public void Balance_ShouldAskAccountOperationServiceForBalance_UsingProperAccountNumber() { // arrange var accountOperationsService = Substitute.For<IAccountOperationsService>(); var controller = new OperationsController(accountOperationsService); MockUserIdentityForController(controller); // act controller.Balance(); // assert accountOperationsService.Received().GetBalanceForAccount(AccountNumber); }
public void OperationReport_ShouldReturnTempDataOperationResultAsModel() { // arrange // we should not have default constructor anyway, and we cannot use it since we really want to isolate our tests from infrastructure (database, in this case) // using mocking library to provide test doubles IAccountOperationsService accountOperationsService = Substitute.For<IAccountOperationsService>(); var controller = new OperationsController(accountOperationsService); var operationResult = new OperationResult { AmountWithdrawed = 100, BalanceLeftAmount = 200, CardNumber = AccountNumber, Timestamp = DateTime.MinValue, }; controller.TempData["OperationResult"] = operationResult; // act var actionResult = controller.OperationReport(); // assert ((ViewResultBase)(actionResult)).Model.ShouldBeEquivalentTo(operationResult); }
public void Balance_ShouldReturnProperBalanceStampAsModel_FromAccountOperationService() { // arrange var accountOperationsService = Substitute.For<IAccountOperationsService>(); AccountBalanceStamp balanceStamp = new AccountBalanceStamp { CardNumber = AccountNumber, MoneyAmount = 300, Timestamp = DateTime.MaxValue, }; accountOperationsService.GetBalanceForAccount(Arg.Any<string>()).Returns(balanceStamp); var controller = new OperationsController(accountOperationsService); MockUserIdentityForController(controller); // act var actionResult = controller.Balance(); // assert accountOperationsService.Received().GetBalanceForAccount(AccountNumber); ((ViewResultBase)(actionResult)).Model.ShouldBeEquivalentTo(balanceStamp); }