コード例 #1
0
        public async Task Handle(ApprenticeshipStopDateChangedEvent 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.Status          = Status.Stopped;
                selectedApprenticeship.ActualEndDate   = message.StopDate;
                await _forecastingDbContext.SaveChangesAsync();
            }
            catch (CommitmentsApiModelException commitmentException)
            {
                _logger.LogError(commitmentException, $"Apprenticeship Completed function Failure to retrieve  ApprenticeshipId: [{message.ApprenticeshipId}]");
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Apprenticeship Completed function Failed for ApprenticeshipId: [{message.ApprenticeshipId}] ");
                throw;
            }
        }
コード例 #2
0
        public async Task Process_Apprenticeship_Stop_Date_Changed_Correctly()
        {
            var stopDateChangedEvent = new ApprenticeshipStopDateChangedEvent()
            {
                ApprenticeshipId = 1,
                ChangedOn        = DateTime.Today,
                StopDate         = DateTime.Today
            };

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

            var apprenticeshipProcessor = mocker.Create <ApprenticeshipProcessor>();
            await apprenticeshipProcessor.ProcessStopDateChange(stopDateChangedEvent);

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

            mocker.Mock <IApprenticeshipStoppedService>()
            .Verify(svc => svc.UpdateApprenticeship(It.IsAny <UpdatedApprenticeshipStoppedModel>()), Times.Once);
        }
        public ApprenticeshipStopDateChangedEventFixture()
        {
            MessageHandlerContext = new Mock <IMessageHandlerContext>();
            MockGetApprenticeship = new Mock <IGetApprenticeshipService>();
            MockLogger            = new Mock <ILogger <ApprenticeshipStopDateChangedEventHandler> >();
            MockApprenticeshipCompletionDateUpdatedEventHandler = new Mock <IApprenticeshipStopDateChangedEventHandler>();
            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);

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

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

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

            await _apprenticeshipStopDateChangedEventHandler.Handle(message);

            _logger.LogInformation($"Apprenticeshipupdate update approved  function Finished at: [{DateTime.UtcNow}] UTC, event with ApprenticeshipId: [{message.ApprenticeshipId}].");
        }
コード例 #5
0
        public ApprenticeshipStopDateChangedEventReceivedFixture()
        {
            MockLogger = new Mock <ILogger <ApprenticeshipStopDateChangedFunction> >();
            MockapprenticeshipUpdatedApprovedEventHandler = new Mock <IApprenticeshipStopDateChangedEventHandler>();
            Fixture = new Fixture();

            ApprenticeshipStopDateChangedEvent = Fixture.Create <ApprenticeshipStopDateChangedEvent>();

            Sut = new ApprenticeshipStopDateChangedFunction(MockapprenticeshipUpdatedApprovedEventHandler.Object, MockLogger.Object);
        }
コード例 #6
0
        public async Task ProcessStopDateChange(ApprenticeshipStopDateChangedEvent stopDateChangedEvent)
        {
            logger.LogDebug($"Now processing the stop date change event for  apprenticeship with  id: {stopDateChangedEvent.ApprenticeshipId}");

            var model = new UpdatedApprenticeshipStoppedModel
            {
                ApprenticeshipId = stopDateChangedEvent.ApprenticeshipId,
                StopDate         = stopDateChangedEvent.StopDate
            };

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