在阅读使用MbUnit作为测试框架的Asp.Net MVC代码示例时,我看到可以通过使用Row属性对多个输入可能性运行单个测试,如下所示:
[Test]
[Row("test@test_test.com")]
[Row("sdfdf dsfsdf")]
[Row("sdfdf@.com")]
public void Invalid_Emails_Should_Return_False(string invalidEmail)
{
...
}
Run Code Online (Sandbox Code Playgroud)
请问我是否想知道NUnit是否等同于MbUnit的Row属性,或者是否是在NUnit中实现此目的的优雅方式.谢谢.
我只是单元测试和ASP.NET MVC的新手.我一直在尝试使用Steve Sanderson的"Pro ASP.NET MVC框架".书中有这段代码:
public class AdminController : Controller
{
...
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Product product, HttpPostedFileBase image)
{
...
productsRepository.SaveProduct(product);
TempData["message"] = product.Name + " has been saved.";
return RedirectToAction("Index");
}
}
Run Code Online (Sandbox Code Playgroud)
他如此测试:
[Test]
public void Edit_Action_Saves_Product_To_Repository_And_Redirects_To_Index()
{
// Arrange
AdminController controller = new AdminController(mockRepos.Object);
Product newProduct = new Product();
// Act
var result = (RedirectToRouteResult)controller.Edit(newProduct, null);
// Assert: Saved product to repository and redirected
mockRepos.Verify(x => x.SaveProduct(newProduct));
Assert.AreEqual("Index", result.RouteValues["action"]);
}
Run Code Online (Sandbox Code Playgroud)
测试通行证.
所以我故意通过添加"productsRepository.DeleteProduct(product);"来破坏代码.在"SaveProduct(product);"之后 如:
...
productsRepository.SaveProduct(product);
productsRepository.DeleteProduct(product);
... …Run Code Online (Sandbox Code Playgroud) 我安装了Asp.net MVC 3 beta,它也安装了NuPack,但是当我在Visual Studio 2010 Express中打开一个项目时,Package Manager Console给出了以下错误消息:
System.TypeLoadException: Could not load type 'System.Management.Automation.Runspaces.InitialSessionState' from assembly 'System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at NuPackConsole.Host.PowerShell.Implementation.PowerShellHostProvider.CreateHost(IConsole console)
at NuPackConsole.Implementation.PowerConsole.HostInfo.get_WpfConsole()
at NuPackConsole.Implementation.PowerConsoleToolWindow.get_WpfConsole()System.InvalidOperationException: Can't start ConsoleDispatcher. Host is null.
at NuPackConsole.Implementation.Console.ConsoleDispatcher.Start()
at NuPackConsole.Implementation.PowerConsoleToolWindow.MoveFocus(FrameworkElement consolePane)
Run Code Online (Sandbox Code Playgroud)
我可以通过"添加包参考"菜单选项下载包,但不能通过包管理器控制台下载包.请问问题是什么?谢谢.
asp.net-mvc ×3
unit-testing ×2
.net ×1
mbunit ×1
mocking ×1
moq ×1
nuget ×1
nunit ×1
tdd ×1
verify ×1