开发者

Testing a repository with MSTest and Moq - .Verify not working

I am currently looking at writing unit tests for a basic execution timer with Moq. There is a function called when the timer is stopped which adds all timings into the database and I need to test that the insert has been called. I have used a similar kind of test to test inserts via the homecontroller but this is being done directly.

// Calls AddToLog() which iterates through the list 
// adding all entries to the database

_timer.Stop(); 
_repository.Verify(x => x.Insert(TimerObject));

The error I am receiving is:

Expected invocation on the mock at least once, but was never performed: x => x.Insert(.splitTimer)

Performed invocations:
ITimersRepository.Insert(EF.Domain.Entities.Timer)
ITimersRepository.Insert(开发者_Go百科EF.Domain.Entities.TimerSplit)
ITimersRepository.Save()

the addToLog() method is defiantly being called and is calling the .insert for the repository. I'm not really sure why it comes back as not being called?

Any ideas would be great.

Thanks


_timerRepository.Verify(x => x.Insert(It.IsAny<Timer>()));

This does the trick for what I needed. It checks to see if an insert has been triggered with a type of Timer and is not specific (Since it cant be as the object is created else where)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜