Beispiel #1
0
        public async Task Handle_UpdateStatementAmountCommand_Return_True()
        {
            //arrange
            Guid STATEMENT_ID = Guid.NewGuid();
            double oldAmount = 123;
            var oldIsPaid = false;
            var command = new UpdateStatementAmountCommand()
            {
                Id = STATEMENT_ID,
                Amount = 123.45,
                IsPaid = true
            };

            _mocker.GetMock<IStatementRepository>()
                .Setup(m => m.GetById(It.Is<Guid>(id => id == STATEMENT_ID)))
                .Returns(value: new Statement()
                {
                    Amount = oldAmount,
                    IsPaid = oldIsPaid
                })
                .Verifiable("IStatementRepository.GetById should have been called");

            _mocker.GetMock<IStatementRepository>()
                .Setup(m => m.UpdateAsync(It.IsAny<Statement>()))
                .Verifiable("IStatementRepository.Update should have been called");

            StatementUpdatedEvent statementEvent = null;
            _mocker.GetMock<IMediatorHandler>()
                .Setup(m => m.RaiseEvent(It.IsAny<StatementUpdatedEvent>()))
                .Callback<StatementUpdatedEvent>(e => statementEvent = e);

            //act
            var result = await _statementCommandHandler.Handle(command, CancellationToken.None);

            //assert
            _mocker.GetMock<IStatementRepository>().Verify();
            _mocker.GetMock<IInvoiceRepository>().Verify();
            _mocker.GetMock<IMediatorHandler>().Verify();
            Assert.True(result);
            Assert.NotNull(statementEvent);
            Assert.Equal(command.IsPaid, statementEvent.New.IsPaid);
            Assert.Equal(oldIsPaid, statementEvent.Old.IsPaid);
            Assert.Equal(command.Amount, statementEvent.New.Amount);
            Assert.Equal(oldAmount, statementEvent.Old.Amount);
        }
Beispiel #2
0
        public async Task Handle(StatementUpdatedEvent notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation("StatementUpdatedEvent: {statement}", notification);

            return;
        }