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()); }
/// <summary> /// Sets the list of challengers when the lobby is received. /// </summary> /// <param name="sender">The sender of the LobbyReceived event.</param> /// <param name="e">The event arguments.</param> private void Client_LobbyReceived(object sender, LobbyReceivedEventArgs e) { this.BattleList = new ObservableCollection <BattleListEntryViewModel>(); for (int i = 0; i < e.ClientDummies.Count; i++) { ClientDummy client = e.ClientDummies[i]; Application.Current.Dispatcher.Invoke(() => { this.BattleList.Add(new BattleListEntryViewModel(client.UserName, client.IPAddress, client.InGame, client.Id, this.client)); }); } }
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); }