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 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); }