Example #1
0
        public async Task Handle_WhenHandlingCommand_ResumeApprenticeship_CreatesAddHistoryEvent()
        {
            // Arrange
            var apprenticeship = await SetupApprenticeship();

            var command = new ResumeApprenticeshipCommand
            {
                ApprenticeshipId = apprenticeship.Id,
                UserInfo         = new UserInfo()
            };

            // Act
            await _handler.Handle(command, new CancellationToken());

            // Simulate Unit of Work contex transaction ending in http request.
            await _dbContext.SaveChangesAsync();

            // Assert
            var historyEvent = _unitOfWorkContext.GetEvents().OfType <EntityStateChangedEvent>()
                               .First(e => e.EntityId == apprenticeship.Id);

            historyEvent.EntityType.Should().Be("Apprenticeship");

            var definition   = new { PaymentStatus = PaymentStatus.Paused };
            var historyState = JsonConvert.DeserializeAnonymousType(historyEvent.UpdatedState, definition);

            historyState.PaymentStatus.Should().Be(PaymentStatus.Active);
        }
Example #2
0
        public async Task Handle_WhenHandlingCommand_StoppingApprenticeship_ThenShouldUpdateDatabaseRecord()
        {
            // Arrange
            var apprenticeship = await SetupApprenticeship();

            var stopDate = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1);

            var command = new StopApprenticeshipCommand(apprenticeship.Cohort.EmployerAccountId, apprenticeship.Id, stopDate, false, new UserInfo());

            // Act
            await _handler.Handle(command, new CancellationToken());

            // Simulate Unit of Work contex transaction ending in http request.
            await _dbContext.SaveChangesAsync();

            // Assert
            var apprenticeshipAssertion = await _confirmationDbContext.Apprenticeships.FirstAsync(a => a.Id == apprenticeship.Id);

            apprenticeshipAssertion.StopDate.Should().Be(stopDate);
            apprenticeshipAssertion.MadeRedundant.Should().Be(false);
            apprenticeshipAssertion.PaymentStatus.Should().Be(PaymentStatus.Withdrawn);
        }
        protected override async Task Handle(AddHistoryCommand request, CancellationToken cancellationToken)
        {
            var history = new History
            {
                EntityId          = request.EntityId,
                CommitmentId      = request.EntityType == nameof(Cohort) ? request.EntityId : default(long?),
                ApprenticeshipId  = (request.EntityType == nameof(DraftApprenticeship) || request.EntityType == nameof(Apprenticeship)) ? request.EntityId : default(long?),
                OriginalState     = request.InitialState,
                UpdatedState      = request.UpdatedState,
                ChangeType        = request.StateChangeType.ToString(),
                CreatedOn         = request.UpdatedOn,
                UserId            = request.UpdatingUserId,
                UpdatedByName     = request.UpdatingUserName,
                UpdatedByRole     = request.UpdatingParty.ToString(),
                EmployerAccountId = request.EmployerAccountId,
                ProviderId        = request.ProviderId,
                EntityType        = request.EntityType,
                Diff          = request.Diff,
                CorrelationId = request.CorrelationId
            };

            _dbContext.History.Add(history);
            await _dbContext.SaveChangesAsync(cancellationToken);
        }