lundi 25 juillet 2016

NUnit Unit Test Fails as it expects not null, how can this be mocked with moq to not get this

I am getting the following error message in a Web API controller Testing project which is using NUnit. In the Web Test Unit test, i'm not using Moq, but I would like to use it as currently the real services are getting invoked. TeamCity is what is reporting this error

Error from TeamCity on the NUnit test

(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()

Code

[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);
}

I gather that the issue is Assert.IsNotNull(response.data); as it is not null, thus teamcity runs and the nunit test fails, right?

Problem is that I don't know what valid "clientid" even are. Really shouldn't this just my mocked/faked anyway? How can I use Moq in this situation?

Aucun commentaire:

Enregistrer un commentaire