public async Task HandleAsync_GivenMessage_ApprovalDateChangeStatusShouldBeValidatedAndReturned()
        {
            var message = fixture.Create <CheckAatfApprovalDateChange>();
            var aatf    = fixture.Create <Aatf>();
            var flags   = new CanApprovalDateBeChangedFlags();

            A.CallTo(() => aatfDataAccess.GetDetails(message.AatfId)).Returns(aatf);
            A.CallTo(() => getAatfApprovalDateChangeStatus.Validate(aatf, message.NewApprovalDate)).Returns(flags);

            var result = await handler.HandleAsync(message);

            result.Should().Be(flags);
        }
Esempio n. 2
0
        public async Task HandleAsync_GivenMessageAndAatfApprovalDateHasNotChanged_AatfDataShouldNotBeRemoved()
        {
            var data          = CreateAatfData(out var competentAuthority);
            var updateRequest = fixture.Build <EditAatfDetails>().With(e => e.Data, data).Create();
            var existingAatf  = GetAatf();
            var flags         = new CanApprovalDateBeChangedFlags();

            A.CallTo(() => genericDataAccess.GetById <Aatf>(updateRequest.Data.Id)).Returns(existingAatf);
            A.CallTo(() => getAatfApprovalDateChangeStatus.Validate(existingAatf, data.ApprovalDate.Value)).Returns(flags);

            var result = await handler.HandleAsync(updateRequest);

            A.CallTo(() => aatfDataAccess.RemoveAatfData(A <Aatf> ._, A <IEnumerable <int> > ._)).MustNotHaveHappened();
        }
Esempio n. 3
0
        public async Task <CanApprovalDateBeChangedFlags> Validate(Aatf aatf, DateTime newApprovalDate)
        {
            var result = new CanApprovalDateBeChangedFlags();

            if (aatf.ApprovalDate.HasValue)
            {
                var currentQuarter = await quarterWindowFactory.GetAnnualQuarterForDate(aatf.ApprovalDate.Value);

                var newQuarter = await quarterWindowFactory.GetAnnualQuarterForDate(newApprovalDate);

                if (aatf.ApprovalDate.Equals(newApprovalDate))
                {
                    return(result);
                }

                if ((int)newQuarter > (int)currentQuarter)
                {
                    result |= CanApprovalDateBeChangedFlags.DateChanged;

                    var returns = await organisationDataAccess.GetReturnsByComplianceYear(aatf.Organisation.Id, aatf.ComplianceYear, aatf.FacilityType);

                    if (returns.Any(r => (int)r.Quarter.Q == (int)currentQuarter && r.ReturnStatus.Value == ReturnStatus.Created.Value))
                    {
                        result |= CanApprovalDateBeChangedFlags.HasStartedReturn;
                    }

                    if (returns.Any(r => (int)r.Quarter.Q == (int)currentQuarter && r.ReturnStatus.Value == ReturnStatus.Submitted.Value))
                    {
                        result |= CanApprovalDateBeChangedFlags.HasSubmittedReturn;
                    }

                    if (returns.Any(r => ((int)r.Quarter.Q == (int)currentQuarter && r.ReturnStatus.Value == ReturnStatus.Submitted.Value && r.ParentId != null) ||
                                    ((int)r.Quarter.Q == (int)currentQuarter && r.ReturnStatus.Value == ReturnStatus.Submitted.Value && r.ParentId != null)))
                    {
                        result |= CanApprovalDateBeChangedFlags.HasResubmission;
                    }

                    if (await aatfDataAccess.HasAatfOrganisationOtherAeOrAatf(aatf))
                    {
                        result |= CanApprovalDateBeChangedFlags.HasMultipleFacility;
                    }
                }
            }

            return(result);
        }
Esempio n. 4
0
        public async Task HandleAsync_GivenMessageAndAatfApprovalDateHasChanged_AatfDataShouldBeRemovedBeforeAatfIsUpdated()
        {
            var data          = CreateAatfData(out var competentAuthority);
            var updateRequest = fixture.Build <EditAatfDetails>().With(e => e.Data, data).Create();
            var existingAatf  = GetAatf();
            var flags         = new CanApprovalDateBeChangedFlags();

            flags |= CanApprovalDateBeChangedFlags.DateChanged;

            A.CallTo(() => genericDataAccess.GetById <Aatf>(A <Guid> ._)).Returns(existingAatf);
            A.CallTo(() => getAatfApprovalDateChangeStatus.Validate(A <Aatf> ._, A <DateTime> ._)).Returns(flags);
            A.CallTo(() => quarterWindowFactory.GetAnnualQuarterForDate(A <DateTime> ._)).ReturnsNextFromSequence(new QuarterType[] { QuarterType.Q1, QuarterType.Q2 });

            var result = await handler.HandleAsync(updateRequest);

            A.CallTo(() => aatfDataAccess.RemoveAatfData(existingAatf, A <IEnumerable <int> > ._))
            .MustHaveHappenedOnceExactly().Then(A.CallTo(() => aatfDataAccess.UpdateDetails(A <Aatf> ._, A <Aatf> ._)).MustHaveHappenedOnceExactly());
        }