Exemplo n.º 1
0
 public void Arrange()
 {
     _mockCommandService = new Mock <ICommandService>();
     _fixture            = new Fixture();
     _command            = _fixture.Create <CalculateEarningsCommand>();
     _sut = new HandleApprenticeshipIncentivesCalculateEarningsCommand(_mockCommandService.Object);
 }
Exemplo n.º 2
0
        public async Task Then_the_earnings_calculated_is_persisted()
        {
            //Arrange
            var incentive = _fixture.Create <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>();

            var command = new CalculateEarningsCommand(incentive.Id);

            _mockIncentiveDomainRespository.Setup(x => x
                                                  .Find(command.ApprenticeshipIncentiveId))
            .ReturnsAsync(incentive);

            int itemsPersisted = 0;

            _mockIncentiveDomainRespository.Setup(m => m.Save(It.Is <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>(a => a.Id == command.ApprenticeshipIncentiveId)))
            .Callback(() =>
            {
                itemsPersisted++;
            });


            // Act
            await _sut.Handle(command);

            // Assert
            itemsPersisted.Should().Be(1);
        }
        public async Task WhenAnEarningsCalculationIsRequested()
        {
            var calcEarningsCommand = new CalculateEarningsCommand(_apprenticeshipIncentive.Id);

            await _testContext.WaitFor <ICommand>(async (cancellationToken) =>
                                                  await _testContext.MessageBus.Send(calcEarningsCommand), numberOfOnProcessedEventsExpected : 1);
        }
        public async Task WhenTheApprenticeshipIncentiveEarningsAreCalculated()
        {
            var calcEarningsCommand = new CalculateEarningsCommand(_apprenticeshipIncentive.Id);

            await _testContext.WaitFor(
                async (cancellationToken) =>
            {
                await _testContext.MessageBus.Send(calcEarningsCommand);
            },
                (context) => HasExpectedCompleteEarningsCalculationEvents(context)
                );
        }
        public async Task Then_the_calculation_is_delayed_if_the_active_period_is_in_progress()
        {
            // Arrange
            _collectionPeriods.First().SetPeriodEndInProgress(true);

            var incentive = _fixture.Create <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>();
            var command   = new CalculateEarningsCommand(incentive.Id);

            // Act
            await _sut.Handle(command);

            // Assert
            _mockCommandPublisher.Verify(x => x.Send(It.Is <CalculateEarningsCommand>(y => y.ApprenticeshipIncentiveId == incentive.Id), It.Is <TimeSpan>(y => y.TotalHours == 1), It.IsAny <CancellationToken>()));
            _mockIncentiveDomainRespository.Verify(x => x.Find(It.IsAny <Guid>()), Times.Never);
        }
Exemplo n.º 6
0
        public async Task Then_a_earnings_calculated_event_is_raised()
        {
            //Arrange
            var incentive = _fixture.Create <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>();

            var command = new CalculateEarningsCommand(incentive.Id);

            _mockIncentiveDomainRespository.Setup(x => x
                                                  .Find(command.ApprenticeshipIncentiveId))
            .ReturnsAsync(incentive);

            // Act
            await _sut.Handle(command);

            // Assert
            incentive.FlushEvents().OfType <EarningsCalculated>().ToList().Count.Should().Be(1);
        }
Exemplo n.º 7
0
        public async Task Then_a_pending_payment_is_created_for_each_payment_profile()
        {
            //Arrange
            var incentive = _fixture.Create <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>();

            var command = new CalculateEarningsCommand(incentive.Id);

            _mockIncentiveDomainRespository.Setup(x => x
                                                  .Find(command.ApprenticeshipIncentiveId))
            .ReturnsAsync(incentive);

            // Act
            await _sut.Handle(command);

            // Assert
            incentive.PendingPayments.Count.Should().Be(2);
        }
Exemplo n.º 8
0
        public async Task Handle(PaymentsCalculationRequired @event, CancellationToken cancellationToken = default)
        {
            var command = new CalculateEarningsCommand(@event.Model.Id);

            await _commandPublisher.Publish(command);
        }
Exemplo n.º 9
0
 public async Task HandleCommand([NServiceBusTrigger(Endpoint = QueueNames.ApprenticeshipIncentivesCalculateEarnings)] CalculateEarningsCommand command)
 {
     await _commandService.Dispatch(command);
 }
Exemplo n.º 10
0
        public Task Handle(Created @event, CancellationToken cancellationToken = default)
        {
            var command = new CalculateEarningsCommand(@event.ApprenticeshipIncentiveId);

            return(_commandPublisher.Publish(command));
        }