public async Task OpenAccount_PositiveInitialCredit_TransactionCreated() { //Arrange const decimal balance = 123; int customerId = Math.Abs(Guid.NewGuid().GetHashCode()); int customerAccountId = Math.Abs(Guid.NewGuid().GetHashCode()); var target = CreateTarget(); _customerAccountRepositoryMock .Setup(c => c.GetCustomer(customerId)) .Returns(new DbCustomer { CustomerId = customerId }); var newCustomerAccount = new DbCustomerAccount { CustomerId = customerId, CustomerAccountId = customerAccountId }; _customerAccountRepositoryMock .Setup(c => c.CreateCustomerAccount(customerId, balance)) .Returns(newCustomerAccount); _mapperMock .Setup(c => c.Map <CustomerAccount>(newCustomerAccount)) .Returns(new CustomerAccount()); AccountTransaction createdTransaction = null; _transactionProxyServiceMock .Setup(c => c.CreateTransaction(It.IsAny <AccountTransaction>())) .Returns(Task.CompletedTask) .Callback((AccountTransaction tran) => { createdTransaction = tran; }); //Act var result = await target.OpenAccount(new CustomerAccountCreateRequest { InitialCredit = balance, CustomerId = customerId }); //Assert Assert.Multiple(() => { Assert.IsInstanceOf <OkObjectResult>(result.Result); _customerAccountRepositoryMock.VerifyAll(); _transactionProxyServiceMock.VerifyAll(); Assert.IsInstanceOf <OkObjectResult>(result.Result); Assert.AreEqual(customerId, createdTransaction.CustomerId); Assert.AreEqual(customerAccountId, createdTransaction.AccountId); Assert.AreEqual(balance, createdTransaction.Amount); }); }
public async Task OpenAccount_EmptyInitialCredit_NotTransactionCreated() { //Arrange int customerId = Math.Abs(Guid.NewGuid().GetHashCode()); var target = CreateTarget(); _customerAccountRepositoryMock .Setup(c => c.GetCustomer(customerId)) .Returns(new DbCustomer { CustomerId = customerId }); var newCustomerAccount = new DbCustomerAccount { CustomerId = customerId }; _customerAccountRepositoryMock .Setup(c => c.CreateCustomerAccount(customerId, 0)) .Returns(newCustomerAccount); _mapperMock .Setup(c => c.Map <CustomerAccount>(newCustomerAccount)) .Returns(new CustomerAccount()); //Act var result = await target.OpenAccount(new CustomerAccountCreateRequest { InitialCredit = 0, CustomerId = customerId }); //Assert Assert.Multiple(() => { Assert.IsInstanceOf <OkObjectResult>(result.Result); _customerAccountRepositoryMock.VerifyAll(); _transactionProxyServiceMock .Verify(c => c.CreateTransaction(It.IsAny <AccountTransaction>()), Times.Never); Assert.IsInstanceOf <OkObjectResult>(result.Result); }); }