public void TransferFunds() { //arrange the MockObject var logMock = new Moq.Mock <ILogger>(); //arrange SUT var client = new ClientDummy(); var source = new AccountForLogSpy(200, client, logMock.Object); var destination = new AccountForLogSpy(150, client, logMock.Object); //set mocked logger expectations logMock.Setup(d => d.Log("method Log was called with message : Transaction : 100 & 250")); //logMock.ExpectedNumberOfCalls(1); //act source.TransferFunds(destination, 100.00F); //assert Assert.AreEqual(250.00F, destination.Balance); Assert.AreEqual(100.00F, source.Balance); //mock object verify logMock.Verify(_ => _.Log("method Log was called with message : Transaction : 100 & 250"), Times.Once()); }
public void PayInstallment() { //arrange the MockObject var logMock = new Moq.Mock <ILogger>(); //arrange the SUT var client = new ClientDummy(); var credit_card = new AccountForLogSpy(500, client, logMock.Object); credit_card.Grant(1000); credit_card.WithdrawFromCreditCard(200); //act credit_card.PayInstallment(); //assert Assert.AreEqual(826F, credit_card.CreditBalance); //mock object verify logMock.Verify(_ => _.Log("method Log was called with message: Raw Installment = 26"), Times.Exactly(3)); logMock.Verify(_ => _.Log("method Log was called with message: Full Installment = 26.78"), Times.Exactly(2)); logMock.Verify(_ => _.Log("method Log was called with message: credit balance after payment = 826"), Times.Once); }