I am trying to mock a dbWriteService Method that returns a aggregate exception when i call it, even though everything is not null. I am farely new to mocking and rhino mock, so I do not really get the problem.
This is the part I want to mock in the function i want to test:
public async Task<bool> SaveDataAsync(object data) { ... await _dbWriteService.UpdateAsync(data); ... } I am mocking the writeService like this:
dbWriteService = MockRepository.GenerateStub<IDbWriteService>(); dbWriteService.Expect(service => service.UpdateAsync(null)); var wasSaved = subject.SaveDataAsync(data).Result; dbWriteService.AssertWasCalled(service => service.UpdateAsync(null)); and i am getting an exception like this:
System.AggregateException: One or more errors occurred. ---> System.NullReferenceException: Object reference not set to an instance of an object. at ClearingDataRepository.<SaveDataAsync>d__28.MoveNext() in ....\ClearingDataRepository.cs:line 170 --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task`1.get_Result() at UnitTests.Services.ClearingDataRepositoryTests.SaveDataAsync_Sucess() in ....\ClearingDataRepositoryTests.cs:line 90 I tried a few things with the mocked function but i do not get the reason why this stuff does not work. Could anybody explain this to me?