public async Task Throw_Bad_Request_With_Missing_Account( CreateDebitCommand command, [Frozen] Mock <IRepository> repo, CreateDebitHandler sut) { repo.Setup(p => p.FindAsync(It.IsAny <IScalar <Account> >())).ReturnsAsync((Account)null); await Assert.ThrowsAsync <BadRequestException>(async() => { await sut.Handle(command, new CancellationToken()); }); }
public async Task Throw_Bad_Request_With_Insufficient_Funds( CreateDebitCommand command, Account account, [Frozen] Mock <IRepository> repo, CreateDebitHandler sut) { account.Debit(new Funds(Currency.USD, account.Balance.Amount)); repo.Setup(p => p.FindAsync(It.IsAny <IScalar <Account> >())).ReturnsAsync(account); await Assert.ThrowsAsync <BadRequestException>(async() => { await sut.Handle(command, new CancellationToken()); }); }
public async Task Returns_Created_With_Valid_Request( CreateDebitCommand command, FundsModel model, [Frozen] Mock <IMediator> mediator, AccountsController sut) { mediator.Setup(p => p.Send(It.IsAny <IRequest <FundsModel> >(), It.IsAny <CancellationToken>())).ReturnsAsync(model); var message = await sut.PostDebit(command) as OkObjectResult; Assert.True(message != null); Assert.True(message.StatusCode == 200); Assert.True((FundsModel)message.Value == model); }
public async Task Fail_With_Invalid_Currency( CreateAccountCommand createAccountCommand, CreateDebitCommand createDebitCommand, TestServer server) { var client = server.CreateClient(); var accountModel = await client.PostAsJsonAsync <CreateAccountCommand, AccountModel>("api/accounts", createAccountCommand); await client.PostAsJsonAsync <FundsModel, FundsModel>($"api/accounts/{accountModel.AccountId}/credits", createDebitCommand.Funds); createDebitCommand.Funds.Currency = "Garbage"; var fundsModel = await client.PostAsJsonAsync <FundsModel, FundsModel>($"api/accounts/{accountModel.AccountId}/debits", createDebitCommand.Funds); Assert.True(fundsModel == null); }
public async Task Succeed_With_Valid_Request( CreateAccountCommand createAccountCommand, CreateDebitCommand createDebitCommand, TestServer server) { var client = server.CreateClient(); var accountModel = await client.PostAsJsonAsync <CreateAccountCommand, AccountModel>("api/accounts", createAccountCommand); await client.PostAsJsonAsync <FundsModel, FundsModel>($"api/accounts/{accountModel.AccountId}/credits", createDebitCommand.Funds); var fundsModel = await client.PostAsJsonAsync <FundsModel, FundsModel>($"api/accounts/{accountModel.AccountId}/debits", createDebitCommand.Funds); var result = await client.GetAsync <AccountModel>($"api/accounts/{accountModel.AccountId}"); Assert.True(result.Balance == fundsModel.Amount); }
public async Task Succeed_With_Valid_Request( CreateDebitCommand command, Account account, [Frozen] Mock <IRepository> repo, CreateDebitHandler sut) { account.Credit(new Funds(Currency.USD, command.Funds.Amount)); var initialBalance = account.Balance.Amount; repo.Setup(p => p.FindAsync(It.IsAny <IScalar <Account> >())).ReturnsAsync(account); var result = await sut.Handle(command, new CancellationToken()); repo.Verify(p => p.FindAsync(It.IsAny <IScalar <Account> >()), Times.Once()); repo.Verify(p => p.UnitOfWork.CommitAsync(), Times.Once()); Assert.True(result.Amount == initialBalance - command.Funds.Amount); }
public ICommandResult DebitPost([FromBody] CreateDebitCommand command) { command.CustomerId = Guid.Parse(User.FindFirst(ClaimTypes.Sid)?.Value); return(_handler.Handle(command)); }
public async Task <IActionResult> PostDebit(CreateDebitCommand command) { return(await Handle <CreateDebitCommand, FundsModel>(command, Ok)); }