public void Withdraw_ShouldNotWithdraw() { // Arrange var daoMock = new Mock <IJSonDao>(); var emptyDenoms = new List <DenominationModel> { new DenominationModel { Denomination = 100, Count = 0 }, new DenominationModel { Denomination = 50, Count = 0 }, new DenominationModel { Denomination = 20, Count = 0 }, new DenominationModel { Denomination = 10, Count = 0 }, new DenominationModel { Denomination = 5, Count = 0 }, new DenominationModel { Denomination = 1, Count = 0 }, }; daoMock.Setup(d => d.Denominations).Returns(emptyDenoms); var hists = new List <HistoryModel>(); daoMock.Setup(d => d.Histories).Returns(hists); daoMock.Setup(d => d.Add(It.IsAny <HistoryModel>())) .Callback((HistoryModel a) => hists.Add(a)); var denomService = new DenominationService(daoMock.Object); var requestedAmount = 1; // Act var result = denomService.Withdraw(requestedAmount); // Assert Assert.Equal(requestedAmount, result.TotalAmount); Assert.False(result.IsSuccess); var denoms = denomService.GetDenominations(); foreach (var denom in denoms) { Assert.Equal(0, denom.Count); } var histories = denomService.GetHistory(); Assert.Single(histories); var history = histories.First(); Assert.Equal(requestedAmount, history.TotalAmount); }
public void Withdraw_ShouldWithdraw() { // Arrange var daoMock = new Mock <IJSonDao>(); daoMock.Setup(d => d.Denominations).Returns(_standardDenoms); var hists = new List <HistoryModel>(); daoMock.Setup(d => d.Histories).Returns(hists); daoMock.Setup(d => d.Add(It.IsAny <HistoryModel>())) .Callback((HistoryModel a) => hists.Add(a)); var denomService = new DenominationService(daoMock.Object); var requestedAmount = 186; // 1 of each denomination. // Act var result = denomService.Withdraw(requestedAmount); // Assert Assert.Equal(requestedAmount, result.TotalAmount); Assert.True(result.IsSuccess); var denoms = denomService.GetDenominations(); foreach (var denom in denoms) { Assert.Equal(9, denom.Count); } var histories = denomService.GetHistory(); Assert.Single(histories); var history = histories.First(); Assert.Equal(requestedAmount, history.TotalAmount); }