public void SetUp() { _mockLogger = new Mock <ILogger <UpdateAccountCommandHandler> >(); _mockAccountService = new Mock <IAccountService>(); _updateAccountCommandHandler = new UpdateAccountCommandHandler(_mockAccountService.Object, _mockLogger.Object); _fixture = new Fixture(); }
public async Task ThrowNotFoundExceptionForNonExistingAccountId() { // Arrange UpdateAccountCommand updateCommand = new UpdateAccountCommand() { Id = 2, AccountId = "0000", AccountName = "Account Payable Update", Active = 1, ParentAccount = 1, }; UpdateAccountCommandHandler handler = new UpdateAccountCommandHandler(_Database); await Assert.ThrowsAsync <NotFoundException> (() => handler.Handle(updateCommand, CancellationToken.None)); }
public async Task UpdateAccountSuccessfuly() { // Arrange UpdateAccountCommand updateCommand = new UpdateAccountCommand() { Id = 10, AccountId = "0000", AccountName = "Account Payable Update", Active = 1, ParentAccount = 1, }; UpdateAccountCommandHandler handler = new UpdateAccountCommandHandler(_Database); // Act var result = await handler.Handle(updateCommand, CancellationToken.None); // Assert Assert.Equal(Unit.Value, result); }
public async void Handler_ShouldApplyCorrectCommission(double commission) { var uow = Substitute.For <IUow>(); var comissionMapper = Substitute.For <ICommissionMapper>(); var comissionApplier = Substitute.For <ICommissionApplier>(); comissionMapper.GetCommissionApplier(Arg.Any <string>()).Returns(comissionApplier); comissionApplier.Apply(Arg.Any <decimal>()).Returns(commission); var updateAccountCommandHandler = new UpdateAccountCommandHandler(uow, comissionMapper); var account = new Account { Id = 2, AccountId = 9834, Balance = 456.45 }; var accounts = new List <Account>() { account }; var command = new UpdateAccountCommand() { AccountId = 100, Amount = 600, MessageType = "PAYMENT", Origin = "MASTER", TransactionId = Guid.NewGuid() }; uow.AccountRepository .Get(Arg.Any <Expression <Func <Account, bool> > >(), Arg.Any <Func <IQueryable <Account>, IOrderedQueryable <Account> > >(), StringValues.Empty) .Returns(accounts); var actualAccounts = await updateAccountCommandHandler.Handle(command, new CancellationToken()); await uow.AccountTransactionRepository.Received().Insert(Arg.Is <AccountTransaction>(at => at.Commission == commission)); }