Пример #1
0
        public async Task Validate_GivenScenario_ExpectedFlagsShouldBePresent(bool hasMultipleOfFacility, bool organisationHasOtherFacilityType, bool organisationHasAssociatedScheme,
                                                                              bool organisationHasOtherEntityOfSameType, bool organisationHasReturns, bool aatfHasReturnData, bool expectedToDeleteAatf, bool expectedToDeleteOrganisation)
        {
            var organisation  = Organisation.CreatePartnership("trading");
            var aatfId        = fixture.Create <Guid>();
            var aatfIdForAatf = fixture.Create <Guid>();
            var aatf          = A.Fake <Aatf>();

            A.CallTo(() => aatf.Organisation).Returns(organisation);
            A.CallTo(() => aatf.FacilityType).Returns(FacilityType.Aatf);
            A.CallTo(() => aatf.Id).Returns(aatfId);
            A.CallTo(() => aatf.AatfId).Returns(aatfIdForAatf);
            var canOrganisationBeDeletedFlags = new CanOrganisationBeDeletedFlags();

            if (hasMultipleOfFacility)
            {
                canOrganisationBeDeletedFlags |= CanOrganisationBeDeletedFlags.HasMultipleOfFacility;
            }

            if (organisationHasAssociatedScheme)
            {
                canOrganisationBeDeletedFlags |= CanOrganisationBeDeletedFlags.HasScheme;
            }

            if (organisationHasReturns)
            {
                canOrganisationBeDeletedFlags |= CanOrganisationBeDeletedFlags.HasReturns;
            }

            if (organisationHasOtherFacilityType)
            {
                canOrganisationBeDeletedFlags |= CanOrganisationBeDeletedFlags.HasAe;
            }

            A.CallTo(() => aatfDataAccess.GetDetails(aatfId)).Returns(aatf);
            A.CallTo(() => aatfDataAccess.HasAatfData(aatfId)).Returns(aatfHasReturnData);
            A.CallTo(() => getOrganisationDeletionStatus.Validate(aatf.Organisation.Id, aatf.ComplianceYear, aatf.FacilityType)).Returns(canOrganisationBeDeletedFlags);
            A.CallTo(() => aatfDataAccess.HasAatfOrganisationOtherAeOrAatf(aatf)).Returns(organisationHasOtherEntityOfSameType);
            A.CallTo(() => aatfDataAccess.IsLatestAatf(aatf.Id, aatfIdForAatf)).Returns(true);

            var result = await getAatfDeletionStatus.Validate(aatfId);

            if (expectedToDeleteAatf)
            {
                result.Should().HaveFlag(CanAatfBeDeletedFlags.CanDelete);
            }
            else
            {
                result.Should().NotHaveFlag(CanAatfBeDeletedFlags.CanDelete);
            }

            if (expectedToDeleteOrganisation)
            {
                result.Should().HaveFlag(CanAatfBeDeletedFlags.CanDeleteOrganisation);
            }
            else
            {
                result.Should().NotHaveFlag(CanAatfBeDeletedFlags.CanDeleteOrganisation);
            }
        }
Пример #2
0
        public async Task <CanAatfBeDeletedFlags> Validate(Guid aatfId)
        {
            var result = new CanAatfBeDeletedFlags();

            var aatf = await aatfDataAccess.GetDetails(aatfId);

            var isLatest = await aatfDataAccess.IsLatestAatf(aatf.Id, aatf.AatfId);

            if (!isLatest)
            {
                result |= CanAatfBeDeletedFlags.IsNotLatest;
                return(result);
            }

            var hasData = await aatfDataAccess.HasAatfData(aatfId);

            if (hasData)
            {
                result |= CanAatfBeDeletedFlags.HasData;
                return(result);
            }

            var organisationDeletionStatus = await getOrganisationDeletionStatus.Validate(aatf.Organisation.Id, aatf.ComplianceYear, aatf.FacilityType);

            if (organisationDeletionStatus.HasFlag(CanOrganisationBeDeletedFlags.HasReturns) &&
                await aatfDataAccess.HasAatfOrganisationOtherAeOrAatf(aatf))
            {
                result |= CanAatfBeDeletedFlags.CanDelete;
            }
            else if (!organisationDeletionStatus.HasFlag(CanOrganisationBeDeletedFlags.HasReturns) &&
                     await aatfDataAccess.HasAatfOrganisationOtherAeOrAatf(aatf))
            {
                result |= CanAatfBeDeletedFlags.CanDelete;
            }
            else if (!organisationDeletionStatus.HasFlag(CanOrganisationBeDeletedFlags.HasReturns) &&
                     !await aatfDataAccess.HasAatfOrganisationOtherAeOrAatf(aatf))
            {
                result |= CanAatfBeDeletedFlags.CanDelete;

                if (!organisationDeletionStatus.HasFlag(CanOrganisationBeDeletedFlags.HasScheme) && !organisationDeletionStatus.HasFlag(CanOrganisationBeDeletedFlags.HasMultipleOfFacility) &&
                    (aatf.FacilityType == FacilityType.Aatf && !organisationDeletionStatus.HasFlag(CanOrganisationBeDeletedFlags.HasAe) ||
                     (aatf.FacilityType == FacilityType.Ae && !organisationDeletionStatus.HasFlag(CanOrganisationBeDeletedFlags.HasAatf))))
                {
                    result |= CanAatfBeDeletedFlags.CanDeleteOrganisation;
                }
            }

            return(result);
        }