我一直在尝试使用ASP.NET网站上发布的视频来学习ASP.NET MVC,我遇到了进行单元测试的问题.
我有一个非常简单的控制器,它使用LINQ to SQL来获取一个对象数组:
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
using (TrainingLogDataContext dc = new TrainingLogDataContext())
{
ViewData.Model = dc.Workouts.ToArray();
}
return View();
}
Run Code Online (Sandbox Code Playgroud)
这在NUnit中失败,并出现以下错误:
at TrainingLog.Models.TrainingLogDataContext..ctor() in C:\Webs\TrainingLog\TrainingLog\Models\TrainingLog.designer.cs:line 41
at TrainingLog.Controllers.HomeController.Index() in C:\Webs\TrainingLog\TrainingLog\Controllers\HomeController.cs:line 16
at TrainingLogTests.Controllers.HomeControllerTest.Index() in C:\Webs\TrainingLog\TrainingLog.Tests\Controllers\HomeControllerTest.cs:line 23
Run Code Online (Sandbox Code Playgroud)
我想问题是NUnit无法获取DataContext的连接字符串web.config
.什么是最好的解决方法?
它在我运行页面时工作正常,但单元测试在NUnit中失败.
归档时间: |
|
查看次数: |
4137 次 |
最近记录: |