Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save simpleprogrammer-shared/77aaef90308a64d431672e2272c7057e to your computer and use it in GitHub Desktop.
Save simpleprogrammer-shared/77aaef90308a64d431672e2272c7057e to your computer and use it in GitHub Desktop.
Back to Basics: Why Unit Testing is Hard 6
[Test]
public void When3AddsThenGetHistory_ShouldReturnOnlyThose3Results()
{
// Arrange
IStorageService storageServiceMock = Mocker.Mock <IStorageService>();
storageServiceMock.Stub(service => service.IsServiceOnline())
.Return(true);
storageServiceMock.Stub(service => service.GetHistorySession(1))
.Return(new List <int>{4, 7, 9});
var calculator = new Calculator(storageServiceMock);
calculator.Add(1, 3);
calculator.Add(2, 5);
calculator.Add(3, 6);
// Act
var result = calculator.GetHistory();
// Assert
storageServiceMock.AssertWasCalled(service =>
service.GetHistorySession(1);
Assert.Equal(4, result[0]);
Assert.Equal(7, resut[1]);
Assert.Equal(9, result[2]);
Assert.Equal(3, result.Count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment