我对 Umbraco 7.6.3 的测试有一个严重的问题,因为我的测试总是得到同样的错误:
System.NullReferenceException : Object reference not set to an instance of an object.
at DirectUmbraco.Models.ContactModel..ctor() in E:\Projects\Umbraco\DirectUmbraco\DirectUmbraco\Models\ContactModel.cs:line 13
at DirectUmbraco.Tests.FormsControllerTests.TestContactMethod() in E:\Projects\Umbraco\DirectUmbraco\DirectUmbraco.Tests\ControllersTests.cs:line 43
第 43 行指的是我的 ContactModel 构造函数(继承自 Umbraco.Web.Models.RenderModel),而我的控制器继承自 SurfaceController。
public ContactModel()
:base(UmbracoContext.Current.PublishedContentRequest.PublishedContent){
}
这是我的测试方法:
[Test]
public void TestContactMethod()
{
var controller= new FormController(); //until this the test pass OK
var contactModel = new ContactModel(); //Here the Exception is thrown
var response = controller.Contact(contactModel);
Assert.IsNotNull(response);
}
我在这里和这里也检查了一些相关 内容 ,但没有一个幸运的。我能做些什么来解决这个问题?
谢谢你。