public async Task <TResponse> HandleAsync(TRequest message) { var readOnlyAttribute = typeof(TRequest).GetCustomAttribute <NotificationReadOnlyAuthorizeAttribute>(); if (readOnlyAttribute != null) { // Try and get the notification id var notificationIdProperty = typeof(TRequest).GetProperty("NotificationId") ?? typeof(TRequest).GetProperty("Id"); if (notificationIdProperty == null) { throw new InvalidOperationException(string.Format("No public property NotificationId or Id found on this request object: {0}", typeof(TRequest).FullName)); } var notificationId = (Guid)notificationIdProperty.GetValue(message); var assessment = await repository.GetByNotificationId(notificationId); if (!assessment.CanEditNotification) { throw new NotificationReadOnlyException(notificationId); } } return(await inner.HandleAsync(message)); }
public async Task <RuleResult <MovementRules> > GetResult(Guid notificationId) { var status = (await notificationApplicationRepository.GetByNotificationId(notificationId)).Status; var messageLevel = status == NotificationStatus.ConsentWithdrawn ? MessageLevel.Error : MessageLevel.Success; return(new RuleResult <MovementRules>(MovementRules.ConsentWithdrawn, messageLevel)); }
public async Task <NotificationAssessmentDecisionData> HandleAsync(GetNotificationAssessmentDecisionData message) { var notificationAssessment = await notificationAssessmentRepository.GetByNotificationId(message.NotificationId); return(assessmentDecisionMap.Map(notificationAssessment)); }
public async Task <NotificationDatesSummary> GetById(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); var assessment = await notificationAssessmentRepository.GetByNotificationId(notificationId); var notification = await notificationApplicationRepository.GetById(notificationId); var paymentReceived = await transactionCalculator.PaymentReceivedDate(notificationId) ?? await transactionCalculator.LatestPayment(notificationId); DateTime?paymentReceivedDate = null; if (paymentReceived != null) { paymentReceivedDate = paymentReceived.Date; } return(NotificationDatesSummary.Load( assessment.Status, assessment.Dates.NotificationReceivedDate, notificationId, paymentReceivedDate, await transactionCalculator.IsPaymentComplete(notificationId), assessment.Dates.CommencementDate, assessment.Dates.NameOfOfficer, assessment.Dates.CompleteDate, assessment.Dates.TransmittedDate, assessment.Dates.AcknowledgedDate, await decisionRequiredBy.GetDecisionRequiredByDate(notification, assessment), assessment.Dates.FileClosedDate, assessment.Dates.ArchiveReference)); }
public async Task NotificationStatusConsentedAndFGDecisionNotMade_ReturnsTrue(FinancialGuaranteeStatus status) { var assessment = new NotificationAssessment(NotificationId); ObjectInstantiator <NotificationAssessment> .SetProperty(x => x.Status, NotificationStatus.Consented, assessment); var financialGuaranteeCollection = new FinancialGuaranteeCollection(NotificationId); var financialGuarantee = financialGuaranteeCollection.AddFinancialGuarantee(new DateTime(2015, 1, 1)); ObjectInstantiator <FinancialGuarantee> .SetProperty(x => x.Status, status, financialGuarantee); A.CallTo(() => assessmentRepository.GetByNotificationId(NotificationId)).Returns(assessment); A.CallTo(() => financialGuaranteeRepository.GetByNotificationId(NotificationId)).Returns(financialGuaranteeCollection); var result = await service.Calculate(NotificationId); Assert.True(result); }
public async Task <Unit> HandleAsync(SetArchiveReference message) { var assessment = await repository.GetByNotificationId(message.NotificationId); assessment.SetArchiveReference(message.ArchiveReference); await context.SaveChangesAsync(); return(Unit.Value); }
public async Task <Unit> HandleAsync(SetNotifcationFileClosedDate message) { var assessment = await repository.GetByNotificationId(message.NotificationId); assessment.MarkFileClosed(message.FileClosedDate); await context.SaveChangesAsync(); return(Unit.Value); }
public CapturedMovementFactoryTests() { validator = A.Fake<IMovementNumberValidator>(); assessmentRepository = A.Fake<INotificationAssessmentRepository>(); A.CallTo(() => assessmentRepository.GetByNotificationId(NotificationId)) .Returns(new TestableNotificationAssessment { Status = NotificationStatus.Consented }); factory = new CapturedMovementFactory(validator, assessmentRepository, A.Fake<IUserContext>()); }
public async Task <bool> HandleAsync(AcceptChanges message) { var assessment = await repository.GetByNotificationId(message.NotificationId); assessment.AcceptChanges(); await context.SaveChangesAsync(); return(true); }
public async Task <bool> HandleAsync(ObjectNotificationApplication message) { var assessment = await notificationAssessmentRepository.GetByNotificationId(message.Id); assessment.Object(message.Date, message.Reason); await context.SaveChangesAsync(); return(true); }
public async Task <bool> HandleAsync(UnlockNotification message) { var assessment = await assessmentRepository.GetByNotificationId(message.NotificationId); assessment.Unlock(); await context.SaveChangesAsync(); return(true); }
public async Task <Guid> HandleAsync(SubmitNotification message) { var assessment = await repository.GetByNotificationId(message.NotificationId); assessment.Submit(progressService); await context.SaveChangesAsync(); return(assessment.Id); }
public async Task <bool> HandleAsync(WithdrawConsentForNotificationApplication message) { var assessment = await notificationAssessmentRepository.GetByNotificationId(message.Id); assessment.WithdrawConsent(message.Date, message.ReasonsForConsentWithdrawal); await context.SaveChangesAsync(); return(true); }
public async Task ReturnsMovement() { CreateShipmentInfo(1); A.CallTo(() => movementRepository.GetAllMovements(NotificationId)) .Returns(new Movement[0]); A.CallTo(() => assessmentRepository.GetByNotificationId(NotificationId)) .Returns(new TestableNotificationAssessment { Status = NotificationStatus.Consented }); A.CallTo(() => financialGuaranteeRepository.GetByNotificationId(NotificationId)).Returns(GetFinancialGuarantee(FinancialGuaranteeStatus.Approved)); A.CallTo(() => movementRepository.GetAllActiveMovements(NotificationId)).Returns(GetMovementArray(1)); A.CallTo(() => consentRepository.GetByNotificationId(NotificationId)).Returns(ValidConsent()); var movement = await factory.Create(NotificationId, Today); Assert.NotNull(movement); }
public async Task Consent(Guid notificationId, DateRange dateRange, string conditions, DateTime consentedDate) { var assessment = await assessmentRepository.GetByNotificationId(notificationId); var consent = assessment.Consent(dateRange, conditions, userContext.UserId, consentedDate); consentRepository.Add(consent); }
public async Task <KeyDatesOverrideData> HandleAsync(GetExportKeyDatesOverrideData message) { var assessment = await assessmentRepository.GetByNotificationId(message.NotificationId); var notification = await applicationRepository.GetById(message.NotificationId); var keyDates = await repository.GetKeyDatesForNotification(message.NotificationId); keyDates.DecisionRequiredByDate = await decisionRequiredBy.GetDecisionRequiredByDate(notification, assessment); return(keyDates); }
public async Task NotificationNotConsented_Throws() { A.CallTo(() => validator.Validate(NotificationId, A <int> .Ignored)) .Returns(true); A.CallTo(() => assessmentRepository.GetByNotificationId(NotificationId)) .Returns(new TestableNotificationAssessment { Status = NotificationStatus.FileClosed }); await Assert.ThrowsAsync <InvalidOperationException>(() => factory.Create(NotificationId, 1, null, AnyDate, true)); }
public async Task <InterimStatus> HandleAsync(GetInterimStatus message) { var facilityCollection = await facilityRepository.GetByNotificationId(message.NotificationId); var assessment = await notificationAssessmentRepository.GetByNotificationId(message.NotificationId); return(new InterimStatus { IsInterim = facilityCollection.IsInterim, NotificationId = assessment.NotificationApplicationId, NotificationStatus = assessment.Status }); }
public CapturedMovementFactoryTests() { SystemTime.Freeze(Today); validator = A.Fake <IMovementNumberValidator>(); assessmentRepository = A.Fake <INotificationAssessmentRepository>(); A.CallTo(() => assessmentRepository.GetByNotificationId(NotificationId)) .Returns(new TestableNotificationAssessment { Status = NotificationStatus.Consented }); factory = new CapturedMovementFactory(validator, assessmentRepository, A.Fake <IUserContext>()); }
public CompleteNotificationTests() { notificationAssessmentRepository = A.Fake <INotificationAssessmentRepository>(); facilityRepository = A.Fake <IFacilityRepository>(); notificationTransactionCalculator = A.Fake <INotificationTransactionCalculator>(); completeNotification = new CompleteNotification(notificationAssessmentRepository, facilityRepository, notificationTransactionCalculator); notificationAssessment = new NotificationAssessment(notificationId); A.CallTo(() => notificationAssessmentRepository.GetByNotificationId(notificationId)) .Returns(notificationAssessment); }
public CompleteNotificationTests() { notificationAssessmentRepository = A.Fake<INotificationAssessmentRepository>(); facilityRepository = A.Fake<IFacilityRepository>(); notificationTransactionCalculator = A.Fake<INotificationTransactionCalculator>(); completeNotification = new CompleteNotification(notificationAssessmentRepository, facilityRepository, notificationTransactionCalculator); notificationAssessment = new NotificationAssessment(notificationId); A.CallTo(() => notificationAssessmentRepository.GetByNotificationId(notificationId)) .Returns(notificationAssessment); }
private async Task UpdatePaymentReceivedDate(DateTime?paymentDate, Guid notificationId) { var assessment = await notificationAssessmentRepository.GetByNotificationId(notificationId); if (paymentDate != null) { assessment.Dates.PaymentReceivedDate = paymentDate; } else { if (assessment.Dates.PaymentReceivedDate.HasValue) { assessment.Dates.PaymentReceivedDate = null; } } }
public async Task <Unit> HandleAsync(SetExportKeyDatesOverride message) { var assessment = await assessmentRepository.GetByNotificationId(message.Data.NotificationId); var notification = await applicationRepository.GetById(message.Data.NotificationId); var currentDecisionRequiredByDate = await decisionRequiredBy.GetDecisionRequiredByDate(notification, assessment); if (currentDecisionRequiredByDate != message.Data.DecisionRequiredByDate) { await repository.SetDecisionRequiredByDateForNotification(assessment.Id, message.Data.DecisionRequiredByDate); } await repository.SetKeyDatesForNotification(message.Data); return(Unit.Value); }
public async Task <SubmitSummaryData> HandleAsync(GetSubmitSummaryInformationForNotification message) { var notification = await notificationApplicationRepository.GetById(message.Id); var assessment = await notificationAssessmentRepository.GetByNotificationId(message.Id); var competentAuthority = notification.CompetentAuthority; return(new SubmitSummaryData { CompetentAuthority = competentAuthority, CreatedDate = notification.CreatedDate.Date, NotificationNumber = notification.NotificationNumber, Status = assessment.Status }); }
public async Task <bool> Calculate(Guid notificationId) { var assessment = await assessmentRepository.GetByNotificationId(notificationId); var financialGuaranteeCollection = await financialGuaranteeRepository.GetByNotificationId(notificationId); if (assessment.Status != NotificationStatus.Consented) { return(false); } return (!financialGuaranteeCollection.FinancialGuarantees.Any() || financialGuaranteeCollection.FinancialGuarantees.Any( fg => fg.Status == FinancialGuaranteeStatus.ApplicationComplete || fg.Status == FinancialGuaranteeStatus.ApplicationReceived || fg.Status == FinancialGuaranteeStatus.AwaitingApplication)); }
public async Task Complete(Guid notificationId, DateTime completedDate) { if (!await IsInterimSet(notificationId)) { throw new InvalidOperationException( string.Format("Can't complete notification {0} as IsInterim has not been set.", notificationId)); } if (!await IsPaymentComplete(notificationId)) { throw new InvalidOperationException( string.Format("Can't complete notification {0} as payment is not fully made.", notificationId)); } var assessment = await notificationAssessmentRepository.GetByNotificationId(notificationId); assessment.Complete(completedDate); }
private async Task <NotificationAttentionSummaryTableData> GetTableDataFromSummary(NotificationAttentionSummary summary) { var assessment = await notificationAssessmentRepository.GetByNotificationId(summary.NotificationId); var notification = await notificationApplicationRepository.GetById(summary.NotificationId); var decisionRequiredBy = await decisionRequiredByCalculator.GetDecisionRequiredByDate(notification, assessment); var daysRemaining = daysRemainingCalculator.Calculate(decisionRequiredBy.Value); return(new NotificationAttentionSummaryTableData { NotificationId = summary.NotificationId, NotificationNumber = summary.NotificationNumber, Officer = summary.Officer, AcknowledgedDate = summary.AcknowledgedDate, DecisionRequiredDate = decisionRequiredBy.Value, DaysRemaining = daysRemaining }); }
public async Task <Movement> Create(Guid notificationId, int number, DateTime?prenotificationDate, DateTime actualShipmentDate, bool hasNoPrenotification) { if (hasNoPrenotification && prenotificationDate.HasValue) { throw new ArgumentException("Can't provide prenotification date if there is no prenotification", "prenotificationDate"); } if (!await movementNumberValidator.Validate(notificationId, number)) { throw new MovementNumberException("Cannot create a movement with a conflicting movement number (" + number + ") for notification: " + notificationId); } var notificationStatus = (await assessmentRepository.GetByNotificationId(notificationId)).Status; if (notificationStatus != NotificationStatus.Consented) { throw new InvalidOperationException( string.Format("Cannot create a movement for notification {0} because its status is {1}", notificationId, notificationStatus)); } if (prenotificationDate.HasValue) { if (prenotificationDate > SystemTime.UtcNow.Date) { throw new InvalidOperationException("The prenotification date cannot be in the future."); } if (actualShipmentDate < prenotificationDate) { throw new InvalidOperationException("The actual date of shipment cannot be before the prenotification date."); } if (actualShipmentDate > prenotificationDate.Value.AddDays(60)) { throw new InvalidOperationException("The actual date of shipment should not be more than 30 calendar days after the prenotification date."); } } var movement = Movement.Capture(number, notificationId, actualShipmentDate, prenotificationDate, hasNoPrenotification, userContext.UserId); return(movement); }
public TransactionTests() { notificationAssessmentRepository = A.Fake <INotificationAssessmentRepository>(); notificationTransactionRepository = A.Fake <INotificationTransactionRepository>(); notificationTransactionCalculator = A.Fake <INotificationTransactionCalculator>(); assessment = new TestableNotificationAssessment(); assessment.NotificationApplicationId = notificationId; assessment.Dates = new NotificationDates(); A.CallTo(() => notificationAssessmentRepository.GetByNotificationId(notificationId)) .Returns(assessment); A.CallTo(() => notificationTransactionCalculator.Balance(notificationId)) .Returns(1000); transaction = new Transaction( notificationAssessmentRepository, notificationTransactionRepository, notificationTransactionCalculator); }
public async Task <NotificationInfo> HandleAsync(GetNotificationInfo message) { var id = await notificationApplicationRepository.GetIdOrDefault(message.Number); var importId = await importNotificationRepository.GetIdOrDefault(message.Number); if (!id.HasValue && !importId.HasValue) { return(new NotificationInfo { IsExistingNotification = false }); } if (id.HasValue) { var notificationAssessment = await notificationAssessmentRepository.GetByNotificationId(id.Value); return(new NotificationInfo { IsExistingNotification = true, Id = id.Value, ExportNotificationStatus = notificationAssessment.Status, TradeDirection = TradeDirection.Export }); } else { var notificationAssessment = await importNotificationAssessmentRepository.GetByNotification(importId.Value); return(new NotificationInfo { IsExistingNotification = true, Id = importId.Value, ImportNotificationStatus = notificationAssessment.Status, TradeDirection = TradeDirection.Import }); } }
public async Task <KeyDatesSummaryData> HandleAsync(GetKeyDatesSummaryInformation message) { var notification = await notificationRepository.GetById(message.NotificationId); var assessment = await assessmentRepository.GetByNotificationId(message.NotificationId); var dates = await datesSummaryRepository.GetById(message.NotificationId); var decision = await decisionRepository.GetByNotificationId(message.NotificationId); var facilityCollection = await facilityRepository.GetByNotificationId(message.NotificationId); var consultation = await consultationRepository.GetByNotificationId(message.NotificationId); return(new KeyDatesSummaryData { CompetentAuthority = notification.CompetentAuthority, IsLocalAreaSet = consultation != null && consultation.LocalAreaId.HasValue, Dates = mapper.Map <NotificationDatesData>(dates), DecisionHistory = decision, IsInterim = facilityCollection.IsInterim }); }
public async Task <NotificationStatus> HandleAsync(GetNotificationStatus message) { return((await notificationAssessmentRepository.GetByNotificationId(message.NotificationId)).Status); }