Hi All, We have a requirement where we have to use NUnit to write test methods and JustMock for mocking the application.
Our application is exposing WCF services and the unit tests will be written to test the WCF Operations. We are using VS 2013.In our application we are using Dependency injection while calling the Constructor i.e. the parameters to the Constuctor are created using Dependency injection. Please refer below sample
public NetworkService(IDbContextFactory<NetworkDbContext> contextFactory, IEventBus eventBus, HostService hostService, UserManagementService userManagementService)
{
_contextFactory = contextFactory.ThrowIfNull("contextFactory");
_eventBus = eventBus.ThrowIfNull("eventBus");
_hostService = hostService.ThrowIfNull("hostService");
_userManagementService = userManagementService.ThrowIfNull("userManagementService");
}
I tried mocking using Telerik Justmock to create the objects of ContextFactory, EventBus etc. but the object created using mocking was of type Proxy of actual object rather than the object itself i.e. Proxy of IEventBus rather than IEventBus.The _contextFactory object is used to create a context like below
using (var ctx = _contextFactory.Create())
But as the object is of type Proxy(Object) I am unable to create the context ctx in above scenario. Hence the controls goes to the Service but
when it tries to use context object ctx, it throws an "Null Reference exception" and hence the testing fails.
Can anyone please suggest if there is any issue with the above and suggest on alternate solution using NUnit and JustMock.
Any help will be highly appreciated. Thanks in advance.
Our application is exposing WCF services and the unit tests will be written to test the WCF Operations. We are using VS 2013.In our application we are using Dependency injection while calling the Constructor i.e. the parameters to the Constuctor are created using Dependency injection. Please refer below sample
public NetworkService(IDbContextFactory<NetworkDbContext> contextFactory, IEventBus eventBus, HostService hostService, UserManagementService userManagementService)
{
_contextFactory = contextFactory.ThrowIfNull("contextFactory");
_eventBus = eventBus.ThrowIfNull("eventBus");
_hostService = hostService.ThrowIfNull("hostService");
_userManagementService = userManagementService.ThrowIfNull("userManagementService");
}
I tried mocking using Telerik Justmock to create the objects of ContextFactory, EventBus etc. but the object created using mocking was of type Proxy of actual object rather than the object itself i.e. Proxy of IEventBus rather than IEventBus.The _contextFactory object is used to create a context like below
using (var ctx = _contextFactory.Create())
But as the object is of type Proxy(Object) I am unable to create the context ctx in above scenario. Hence the controls goes to the Service but
when it tries to use context object ctx, it throws an "Null Reference exception" and hence the testing fails.
Can anyone please suggest if there is any issue with the above and suggest on alternate solution using NUnit and JustMock.
Any help will be highly appreciated. Thanks in advance.