コード例 #1
0
        public async Task Handle(ApprenticeshipCompletionDateUpdatedEvent 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.Completed;
                selectedApprenticeship.ActualEndDate   = message.CompletionDate;
                await _forecastingDbContext.SaveChangesAsync();
            }
            catch (CommitmentsApiModelException commitmentException)
            {
                _logger.LogError(commitmentException, $"Apprenticeship Completion Date updated function Failure to retrieve  ApprenticeshipId: [{message.ApprenticeshipId}]");
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Apprenticeship Completion Date updated function Failed for ApprenticeshipId: [{message.ApprenticeshipId}] ");
                throw;
            }
        }
コード例 #2
0
        public ApprenticeshipCompletionDateUpdatedEventFixture(bool SetState)
        {
            MessageHandlerContext = new Mock <IMessageHandlerContext>();
            MockGetApprenticeship = new Mock <IGetApprenticeshipService>();
            MockLogger            = new Mock <ILogger <ApprenticeshipCompletionDateUpdatedEventHandler> >();
            MockApprenticeshipCompletionDateUpdatedEventHandler = new Mock <IApprenticeshipCompletionDateUpdatedEventHandler>();
            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);
            if (SetState)
            {
                Db.Entry(Commitment).State = EntityState.Detached;
            }

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

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

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

            await _apprenticeshipCompletionDateUpdatedEventHandler.Handle(message);

            _logger.LogInformation($"Apprenticeship Completion date updated function Finished at: [{DateTime.UtcNow}] UTC, event with ApprenticeshipId: [{message.ApprenticeshipId}].");
        }
        public ApprenticeshipCompletionDateUpdatedEventReceivedFixture()
        {
            MockLogger = new Mock <ILogger <ApprenticeshipCompletionDateUpdatedFunction> >();
            MockpprenticeshipCompletedEventHandler = new Mock <IApprenticeshipCompletionDateUpdatedEventHandler>();
            Fixture = new Fixture();

            ApprenticeshipCompletionDateUpdatedEvent = Fixture.Create <ApprenticeshipCompletionDateUpdatedEvent>();

            Sut = new ApprenticeshipCompletionDateUpdatedFunction(MockpprenticeshipCompletedEventHandler.Object, MockLogger.Object);
        }