Example #1
0
        public async Task Process_Apprenticeship_Stopped_Correctly()
        {
            var stoppedEvent = new ApprenticeshipStoppedEvent()
            {
                ApprenticeshipId = 1,
                AppliedOn        = DateTime.Today,
                StopDate         = DateTime.Today
            };

            mocker.Mock <IApprenticeshipStoppedService>()
            .Setup(svc => svc.UpdateApprenticeship(It.IsAny <UpdatedApprenticeshipStoppedModel>()))
            .ReturnsAsync(() => new ApprenticeshipModel
            {
                Id = stoppedEvent.ApprenticeshipId,
            });

            var apprenticeshipProcessor = mocker.Create <ApprenticeshipProcessor>();
            await apprenticeshipProcessor.ProcessStoppedApprenticeship(stoppedEvent);

            mocker.Mock <IEndpointInstance>()
            .Verify(svc => svc.Publish(It.Is <ApprenticeshipUpdated>(ev =>
                                                                     ev.Id == stoppedEvent.ApprenticeshipId),
                                       It.IsAny <PublishOptions>()), Times.Once);

            mocker.Mock <IApprenticeshipStoppedService>()
            .Verify(svc => svc.UpdateApprenticeship(It.IsAny <UpdatedApprenticeshipStoppedModel>()), Times.Once);
        }
        public async Task Handle(ApprenticeshipStoppedEvent message)
        {
            try
            {
                var selectedApprenticeship = _forecastingDbContext.Commitment.FirstOrDefault(x => x.ApprenticeshipId == message.ApprenticeshipId);
                if (selectedApprenticeship == null)
                {
                    selectedApprenticeship = await _getApprenticeshipService.GetApprenticeshipDetails(message.ApprenticeshipId);

                    _forecastingDbContext.Commitment.Add(selectedApprenticeship);
                }

                selectedApprenticeship.UpdatedDateTime = DateTime.UtcNow;
                selectedApprenticeship.ActualEndDate   = message.StopDate;
                selectedApprenticeship.Status          = Status.Stopped;
                await _forecastingDbContext.SaveChangesAsync();
            }
            catch (CommitmentsApiModelException commitmentException)
            {
                _logger.LogError(commitmentException, $"Apprenticeship Stopped function Failure to retrieve  ApprenticeshipId: [{message.ApprenticeshipId}]");
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Apprenticeship Stopped function Failed for ApprenticeshipId: [{message.ApprenticeshipId}] ");
                throw;
            }
        }
        public ApprenticeshipStoppedEventTestsFixture()
        {
            MessageHandlerContext = new Mock <IMessageHandlerContext>();
            MockGetApprenticeship = new Mock <IGetApprenticeshipService>();
            MockLogger            = new Mock <ILogger <ApprenticeshipStoppedEventHandler> >();
            MockApprenticeshipCompletionDateUpdatedEventHandler = new Mock <IApprenticeshipStoppedEventHandler>();
            Fixture = new Fixture();

            Db = new ForecastingDbContext(new DbContextOptionsBuilder <ForecastingDbContext>()
                                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                          .EnableSensitiveDataLogging()
                                          .Options);
            Commitment                  = Fixture.Create <Commitments>();
            Commitment.Id               = CommitmentId = 101;
            Commitment.ActualEndDate    = null;
            Commitment.Status           = Status.LiveOrWaitingToStart;
            Commitment.ApprenticeshipId = 1;
            Db.Commitment.Add(Commitment);

            ApprenticeshipStoppedEvent = Fixture.Create <ApprenticeshipStoppedEvent>();
            ApprenticeshipStoppedEvent.ApprenticeshipId = Commitment.ApprenticeshipId;

            var configuration = new MapperConfiguration(cfg => cfg.AddProfile <AutoMapperProfile>());
            var mapper        = new Mapper(configuration);

            Sut = new ApprenticeshipStoppedEventHandler(Db, MockGetApprenticeship.Object, MockLogger.Object);
            Db.SaveChanges();
        }
        public async Task Run(
            [NServiceBusTrigger(Endpoint = "SFA.DAS.Fcast.ApprenticeshipStopped")] ApprenticeshipStoppedEvent message)
        {
            _logger.LogInformation($"Apprenticeship Stopped function Begin at: [{DateTime.UtcNow}] UTC, event with ApprenticeshipId: [{message.ApprenticeshipId}].");

            await _apprenticeshipStoppedEventHandler.Handle(message);

            _logger.LogInformation($"Apprenticeship Stopped function Finished at: [{DateTime.UtcNow}] UTC, event with ApprenticeshipId: [{message.ApprenticeshipId}].");
        }
Example #5
0
        public async Task ProcessStoppedApprenticeship(ApprenticeshipStoppedEvent apprenticeshipStoppedEvent)
        {
            logger.LogDebug($"Now processing the stopped apprenticeship with  id: {apprenticeshipStoppedEvent.ApprenticeshipId}");
            var model = new UpdatedApprenticeshipStoppedModel
            {
                ApprenticeshipId = apprenticeshipStoppedEvent.ApprenticeshipId,
                StopDate         = apprenticeshipStoppedEvent.StopDate
            };

            await HandleStoppedApprenticeship(model);
        }
 public Task Handle(ApprenticeshipStoppedEvent message, IMessageHandlerContext context)
 {
     return(Log(message, context));
 }