public async Task Validate_GivenAatfOrganisationHasOtherFacilities_ShouldMultipleFacilityFlag() { var currentApprovalDate = fixture.Create <DateTime>(); var newApprovalDate = fixture.Create <DateTime>(); var aatf = A.Fake <Aatf>(); SetupApprovalDateMovedToNextQuarter(aatf, currentApprovalDate, newApprovalDate); A.CallTo(() => aatfDataAccess.HasAatfOrganisationOtherAeOrAatf(aatf)).Returns(true); var result = await getAatfApprovalDateChangeStatus.Validate(aatf, newApprovalDate); result.Should().HaveFlag(CanApprovalDateBeChangedFlags.HasMultipleFacility); }
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); }
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); } }
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); }