I have two interfaces called ITweetReq and ITweetResp.
An outside service sends Requests to send tweets when they come in, which is implemented by the interface ITweetReq and our system in return sends the reply back which is implemented in ITweetResp interface.
Both the incoming and outgoing messages are logged in a file. I have to unit test the log file to make sure it is logging the correct number of message received and replied.
I am wondering if I should mock both the interfaces then do a test on the log file, but not sure how to go about it. Any help or suggestion will be appreciated.
I am using NUnit and Moq Framework.
var TweetReq = new Mock<ITweetReq>();
var TweetRes = new Mock<ITweetRes>();
You seem a little confused as to what mocking/unit testing is.
Mocks are typically created for anything ‘outside’ of the class being tested.
Unit tests are run on your code (typically a method, or part of it).
You should write unit tests for the class which does the logging, by calling the methods which receive/reply to tweets with the mocked objects, and testing for the expected result.
It might be better if you mocked your logging class too, as testing files directly can become complicated and is not recommended.
For example, you might have these methods on your class.
You can then write unit tests like this: