我只想了解标签"容器"的来源.谁知道?
似乎很多东西都可以称为"容器".
dependency-injection conventions naming-conventions inversion-of-control
"MagicFunction"的实现会如何使以下(nunit)测试通过?
public MagicFunction_Should_Prepend_Given_String_To_Each_Line()
{
var str = @"line1
line2
line3";
var result = MagicFunction(str, "-- ");
var expected = @"-- line1
-- line2
-- line3";
Assert.AreEqual(expected, result);
}
Run Code Online (Sandbox Code Playgroud) 我想清除我的 SqlServer 实例上的数据库架构。我应该使用什么 tsql?
我所说的架构是指表、约束等。我希望结果与创建新数据库时的结果类似,但是我不想实际删除和创建数据库。
为什么:
对于那些好奇的人,由于为单元测试隔离数据库的方式,我需要清空模式而不删除。在运行我的测试之前,保存了数据库的快照。每次测试运行后,都会恢复此快照。如果我将数据库操作保持在数据库范围内,我只能确保跨单元测试的状态一致。删除/创建数据库不在 db 的范围内(在 master 的范围内)。
在这种情况下,我需要断言当架构为空时会发生预期的事情。通过 sql 清空架构使测试方法保持一致:基本上对数据库做任何你想做的事情,练习它,恢复它。
Raj More 的回答让我开始了。我希望有人可以缩短流程。
我有以下课程:
public class Script
{
IPrinter _printer;
public Script(IPrinter printer)
{
_printer = printer;
}
public void Print(TextWriter writer)
{
_printer.PrintComment(writer, "lolz");
writer.WriteLine("omg this complicates things";
_printer.PrintSpecial(writer);
if (signoff)
_printer.PrintComment(writer, "kthxbye");
}
}
Run Code Online (Sandbox Code Playgroud)
如何设置测试以声明使用正确的参数以正确的顺序调用打印机方法?
我可以手动创建一个'假'打印机并对编写器进行状态测试,但由于上下文很大(特别是因为脚本也在与编写器一起使用),我想避免它.
我正在使用nunit和rhino模拟器.任何关于体系结构更改的想法或模拟程序,以使这更容易测试,这是值得赞赏的.不幸的是,我正在使用的真实代码更复杂 - 但这是要点.
我有一个带有nvarchar参数的存储过程.我希望调用者在使用此SP时为sql命令提供文本.
如何从SP内执行提供的sql命令?
这有可能吗? -
我认为可以使用EXEC,但以下内容:
EXEC @script
Run Code Online (Sandbox Code Playgroud)
错误表明它无法按给定名称查找存储过程.由于它是一个脚本,这显然是准确的,但让我觉得它没有按预期工作.
我想在我的scss文件中按字母顺序排列css选择器(和属性).我确信vim可以做到这一点(即使我需要使用一些外部工具).你会如何排序以下内容?
h2 {
color:red;
background-color:green;
}
h1 {
font-size:12px;
}
Run Code Online (Sandbox Code Playgroud)
对此:
h1 {
font-size:12px;
}
h2 {
background-color:green;
color:red;
}
Run Code Online (Sandbox Code Playgroud) 我试图孤立地测试我的控制器的动作链.具体来说,我想确保我所需的行为适用于我所有控制器的操作.例如,测试我的所有操作都需要身份验证:
context "when not authenticated" do
# single case
describe "GET index" do
it "responds with 401" do
get :index
response.code.should be(401)
end
end
# all of them...
described_class.action_methods.each do |action|
['get', 'put', 'post', 'delete', 'patch'].each do |verb|
describe "#{verb.upcase} #{action}" do
it "responds with 401" do
send verb, action
response.code.should == "401"
end
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
我希望这可行,但事实并非如此.我得到一些ActionController::RoutingErrors.这是因为我的一些路线需要参数,在某些情况下我不提供它们(就像我打电话时post :create).我明白了.但我不明白的是:为什么要重要!?
对于这些测试,路由是一个单独的问题.我关心我的行动链,而不是我的要求(这就是我拥有的routing specs和我request specs的).我不应该关心自己在这个级别的路线限制.
所以我的问题是:有没有办法在不模拟请求的情况下测试动作链?
编辑:一些研究
看起来在TestCase#进程中正在运行路由.这有必要吗?
所以,如果我有一个实例
System.Reflection.Assembly
Run Code Online (Sandbox Code Playgroud)
我有以下型号:
class Person {}
class Student : Person {}
class Freshman : Student {}
class Employee : Person {}
class PersonList : ArrayList {}
class StudentList : PersonList {}
Run Code Online (Sandbox Code Playgroud)
如何枚举程序集的类型以仅获取对Person和PersonList类型的引用?
要明确:我不希望在此查找期间显式指定Person或PersonList类型.Person和PersonList只是本例中有问题的程序集中定义的根类型.我正在寻找一种枚举给定程序集的所有根类型的通用方法.
谢谢你的时间:)
任何人都可以告诉我如何让我的模型在自己的中心旋转去重力而不是默认(0,0,0)轴吗?
而我的轮换似乎只是左右不是360度..
如果我有一个参数是接口的方法,那么查看接口引用是否属于特定泛型类型的快速方法是什么?
更具体地说,如果我有:
interface IVehicle{}
class Car<T> : IVehicle {}
CheckType(IVehicle param)
{
// How do I check that param is Car<int>?
}
Run Code Online (Sandbox Code Playgroud)
检查结束后我还要投.所以,如果有一种方法可以一石二鸟,让我知道.
这是对这个问题的姐妹问题
如果我有一个实例
System.Reflection.Assembly
Run Code Online (Sandbox Code Playgroud)
我有以下型号:
class Person {}
class Student : Person {}
class Freshman : Student {}
class Employee : Person {}
class PersonList : ArrayList {}
class StudentList : PersonList {}
Run Code Online (Sandbox Code Playgroud)
如何枚举程序集的类型以获取对Employee,Freshman和StudentList的引用?
我希望能够枚举任何给定程序集的所有底部类型,如上例所示.
谢谢你的时间 :)
我可以看到以下代码初始化FOO为localhostif BAR为空,但是究竟发生了:-什么?它是什么?
c# ×5
reflection ×3
.net ×2
sql ×2
sql-server ×2
t-sql ×2
axis ×1
bash ×1
controllers ×1
conventions ×1
css ×1
dynamic-sql ×1
mocking ×1
opengl ×1
rhino-mocks ×1
rotation ×1
rspec ×1
sorting ×1
string ×1
syntax ×1
testing ×1
translation ×1
unit-testing ×1
vim ×1