NUnit单元测试失败,因为它预期不为null,如何用moq模拟这不能得到这个

时间:2016-07-25 08:03:32

标签: c# unit-testing nunit teamcity moq

我在使用NUnit的Web API控制器测试项目中收到以下错误消息。在Web测试单元测试中,我没有使用Moq,但我想使用它,因为目前正在调用真正的服务。 TeamCity报告此错误

来自TeamCity的NUnit测试错误

(new) Portal.WebAPI.Tests.dll:        
Portal.WebAPI.Tests.Controllers.CalendarEventControllerTest.CalendarEventController_SearchCalendarEvent_Success

Test(s) failed.   Expected: not null
But was:  null

at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression, String message, Object[] args)
at NUnit.Framework.Assert.IsNotNull(Object anObject)
at Portal.WebAPI.Tests.Controllers.CalendarEventControllerTest.   

<CalendarEventController_SearchCalendarEvent_Success>d__1e.MoveNext() in h:\BuildAgent\work\8d99e8b3faa82424\NxtGen\Portal.WebAPI.Tests\Controllers\CalendarEventControllerTest.cs:line 107
at NUnit.Framework.AsyncInvocationRegion.AsyncTaskInvocationRegion.WaitForPendingOperationsToComplete(Object invocationResult)

at NUnit.Core.NUnitAsyncTestMethod.RunTestMethod()

代码

[Test]
public async Task CalendarEventController_SearchCalendarEvent_Success()
{
    CalendarEventController controller = new CalendarEventController();
    CalendarEventSearchRequest request = new CalendarEventSearchRequest();
    request.ClientId = 123;
    CalendarEventSearchResponse response = await controller.SearchCalendarEvents(request);

    Assert.IsNotNull(response.data);
}

我认为问题是Assert.IsNotNull(response.data);,因为它不是空的,因此teamcity运行并且nunit测试失败,对吧?

问题是我不知道什么是有效的“clientid”。真的不应该这只是我的嘲笑/假装吗?在这种情况下如何使用Moq?

0 个答案:

没有答案