Last active
September 17, 2015 02:20
-
-
Save melvinlee/5f361180fb531221f8fb to your computer and use it in GitHub Desktop.
Unit test with moq framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void Run_With_InboxMessages_Should_Call_Repo_Save() | |
{ | |
//Arrange | |
var apiConfig = new ApiConfig(); | |
apiConfig.SetCommPort(new CommPort()); | |
var fakeApi = A.Fake<ISmsApi>(); | |
var fakeLogging = A.Fake<ILogging>(); | |
var fakeOutgoingsmsRepo = A.Fake<ISmsOutgoingRepository>(); | |
var fakeIncomingsmsRepo = A.Fake<ISmsIncomingRepository>(); | |
var inbox = new List<InboxMessage> {new InboxMessage()}; | |
//Act | |
A.CallTo(() => fakeApi.GetInboxMessages(A<Action<ICollection<InboxMessage>, SmsServiceException>>.Ignored)) | |
.Invokes(call => | |
{ | |
var action = ((Action<ICollection<InboxMessage>, SmsServiceException>) call.Arguments.First()); | |
action(inbox, null); | |
}); | |
A.CallTo(() => fakeApi.ModemReady).Returns(true); | |
A.CallTo(() => fakeApi.IsModemReady(A<Action<bool, string>>.Ignored)).Invokes(call => | |
{ | |
var action = ((Action<bool, string>) call.Arguments.First()); | |
action(true, ""); | |
}); | |
var smsServer = new SmsServer(fakeApi, apiConfig, fakeOutgoingsmsRepo, fakeIncomingsmsRepo, fakeLogging); | |
smsServer.Run(); | |
//Assert | |
A.CallTo(() => fakeApi.IsModemReady(A<Action<bool, string>>.Ignored)).MustHaveHappened(); | |
A.CallTo(() => fakeIncomingsmsRepo.Add(A<IncomingSms>.Ignored)).MustHaveHappened(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment