public async Task LoadWaterAllocation_ExemptOfPriorityFlow_BadData(bool exemptOfPriorityFlow, DateTime?priorityDate, string allocationFlow_CFS, string allocationVolume_AF)
        {
            OrganizationsDim organization;
            VariablesDim     variable;
            WaterSourcesDim  waterSource;
            MethodsDim       method;
            DateDim          dataPublicationDate;
            WaterAllocation  waterAllocation;
            string           startTestString = "01/01";
            string           endTestString   = "12/01";
            int errorCount = 0;

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                errorCount = db.ImportErrors.Count();

                organization = await OrganizationsDimBuilder.Load(db);

                variable = await VariablesDimBuilder.Load(db);

                waterSource = await WaterSourcesDimBuilder.Load(db);

                method = await MethodsDimBuilder.Load(db);

                dataPublicationDate = await DateDimBuilder.Load(db);

                waterAllocation = WaterAllocationBuilder.Create(new WaterAllocationBuilderOptions {
                    RecordType = WaterAllocationRecordType.None
                });

                //////////////////// Exempt of Volume Flow Priority Columns
                waterAllocation.ExemptOfVolumeFlowPriority = exemptOfPriorityFlow;
                waterAllocation.AllocationPriorityDate     = priorityDate;
                waterAllocation.AllocationFlow_CFS         = allocationFlow_CFS;
                waterAllocation.AllocationVolume_AF        = allocationVolume_AF;
                ////////////////////

                waterAllocation.OrganizationUUID         = organization.OrganizationUuid;
                waterAllocation.VariableSpecificUUID     = variable.VariableSpecificUuid;
                waterAllocation.WaterSourceUUID          = waterSource.WaterSourceUuid;
                waterAllocation.MethodUUID               = method.MethodUuid;
                waterAllocation.DataPublicationDate      = dataPublicationDate.Date;
                waterAllocation.AllocationTimeframeStart = startTestString;
                waterAllocation.AllocationTimeframeEnd   = endTestString;
            }

            var sut    = CreateWaterAllocationAccessor();
            var result = await sut.LoadWaterAllocation((new Faker()).Random.AlphaNumeric(10), new[] { waterAllocation });

            result.Should().BeFalse();

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                db.ImportErrors.Should().HaveCount(errorCount + 1);
                var error = await db.ImportErrors.LastAsync();

                error.Data.Should().Contain("Allocation Not Exempt of Volume Flow Priority");
            }
        }
        public async Task LoadWaterAllocation_BadLoad_CivilianAndPower()
        {
            OrganizationsDim organization;
            VariablesDim     variable;
            WaterSourcesDim  waterSource;
            MethodsDim       method;
            DateDim          dataPublicationDate;
            DateDim          allocationPriorityDate;
            WaterAllocation  waterAllocation;

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                organization = await OrganizationsDimBuilder.Load(db);

                variable = await VariablesDimBuilder.Load(db);

                waterSource = await WaterSourcesDimBuilder.Load(db);

                method = await MethodsDimBuilder.Load(db);

                dataPublicationDate = await DateDimBuilder.Load(db);

                allocationPriorityDate = await DateDimBuilder.Load(db);

                waterAllocation = WaterAllocationBuilder.Create(new WaterAllocationBuilderOptions {
                    RecordType = WaterAllocationRecordType.Civilian
                });

                waterAllocation.OrganizationUUID       = organization.OrganizationUuid;
                waterAllocation.VariableSpecificUUID   = variable.VariableSpecificUuid;
                waterAllocation.WaterSourceUUID        = waterSource.WaterSourceUuid;
                waterAllocation.MethodUUID             = method.MethodUuid;
                waterAllocation.DataPublicationDate    = dataPublicationDate.Date;
                waterAllocation.AllocationPriorityDate = allocationPriorityDate.Date;

                waterAllocation.GeneratedPowerCapacityMW = (new Faker()).Random.Decimal(0, 1000).ToString();
            }

            var sut    = CreateWaterAllocationAccessor();
            var runId  = (new Faker()).Random.AlphaNumeric(10);
            var result = await sut.LoadWaterAllocation(runId, new[] { waterAllocation });

            result.Should().BeFalse();

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                db.AllocationAmountsFact.Should().HaveCount(0);

                var importError = db.ImportErrors.Single();
                importError.RunId.Should().Be(runId);
                importError.Data.Should().Contain("Cross Group Not Valid");
            }
        }
        public async Task LoadRegulatoryReportingUnits_SimpleLoad()
        {
            OrganizationsDim     organization;
            RegulatoryOverlayDim regulatoryOverlay;
            ReportingUnitsDim    reportingUnit;
            DateDim date;

            RegulatoryReportingUnits regulatoryReportingUnit;

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                organization = await OrganizationsDimBuilder.Load(db);

                regulatoryOverlay = await RegulatoryOverlayDimBuilder.Load(db);

                reportingUnit = await ReportingUnitsDimBuilder.Load(db);

                date = await DateDimBuilder.Load(db);

                regulatoryReportingUnit = RegulatoryReportingUnitBuilder.Create(new RegulatoryReportingUnitBuilderOptions
                {
                    Organization      = organization,
                    RegulatoryOverlay = regulatoryOverlay,
                    ReportingUnit     = reportingUnit,
                    DatePublication   = date
                });
            }

            var sut    = CreateWaterAllocationAccessor();
            var result = await sut.LoadRegulatoryReportingUnits((new Faker()).Random.AlphaNumeric(10), new[] { regulatoryReportingUnit });

            result.Should().BeTrue();

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                var dbRegulatoryReportingUnit = await db.RegulatoryReportingUnitsFact.SingleAsync();

                dbRegulatoryReportingUnit.DataPublicationDateId.Should().Be(date.DateId);
                dbRegulatoryReportingUnit.OrganizationId.Should().Be(organization.OrganizationId);
                dbRegulatoryReportingUnit.RegulatoryOverlayId.Should().Be(regulatoryOverlay.RegulatoryOverlayId);
                dbRegulatoryReportingUnit.ReportingUnitId.Should().Be(reportingUnit.ReportingUnitId);

                db.ImportErrors.Should().HaveCount(0);
            }
        }
        public async Task LoadSiteSpecificAmounts_SimpleLoad_Power()
        {
            OrganizationsDim   organization;
            SitesDim           site;
            VariablesDim       variable;
            WaterSourcesDim    waterSource;
            MethodsDim         method;
            SiteSpecificAmount siteSpecificAmount;
            BeneficialUsesCV   beneficialUses;
            BeneficialUsesCV   primaryUseCategory;
            ReportYearCv       reportYear;
            DateDim            publicationDate;
            PowerType          powerType;

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                organization = await OrganizationsDimBuilder.Load(db);

                site = await SitesDimBuilder.Load(db);

                variable = await VariablesDimBuilder.Load(db);

                waterSource = await WaterSourcesDimBuilder.Load(db);

                method = await MethodsDimBuilder.Load(db);

                beneficialUses = await BeneficalUsesBuilder.Load(db);

                primaryUseCategory = await BeneficalUsesBuilder.Load(db);

                reportYear = await ReportYearCvBuilder.Load(db);

                publicationDate = await DateDimBuilder.Load(db);

                powerType = await PowerTypeBuilder.Load(db);

                siteSpecificAmount = SiteSpecificAmountBuilder.Create(new SiteSpecificAmountBuilderOptions
                {
                    RecordType          = SiteSpecificRecordType.Power,
                    Method              = method,
                    Organization        = organization,
                    DataPublicationDate = publicationDate,
                    Site               = site,
                    Variable           = variable,
                    WaterSource        = waterSource,
                    BeneficialUse      = beneficialUses,
                    PrimaryUseCategory = primaryUseCategory,
                    ReportYear         = reportYear,
                    PowerType          = powerType
                });
            }

            siteSpecificAmount.PowerGeneratedGWh.Should().NotBeNullOrEmpty("Required field");
            siteSpecificAmount.PowerType.Should().NotBeNullOrEmpty("Required field");

            var sut    = CreateWaterAllocationAccessor();
            var result = await sut.LoadSiteSpecificAmounts((new Faker()).Random.AlphaNumeric(10), new[] { siteSpecificAmount });

            result.Should().BeTrue();

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                var dbSiteVariableAmount = await db.SiteVariableAmountsFact.SingleAsync();

                dbSiteVariableAmount.OrganizationId.Should().Be(organization.OrganizationId);
                dbSiteVariableAmount.SiteId.Should().Be(site.SiteId);
                dbSiteVariableAmount.VariableSpecificId.Should().Be(variable.VariableSpecificId);
                dbSiteVariableAmount.WaterSourceId.Should().Be(waterSource.WaterSourceId);
                dbSiteVariableAmount.MethodId.Should().Be(method.MethodId);
                dbSiteVariableAmount.PrimaryUseCategoryCV.Should().Be(primaryUseCategory.Name);
                dbSiteVariableAmount.ReportYearCv.Should().Be(reportYear.Name);

                dbSiteVariableAmount.PowerGeneratedGwh.Should().Be(double.Parse(siteSpecificAmount.PowerGeneratedGWh));
                dbSiteVariableAmount.PowerType.Should().Be(powerType.Name);

                db.ImportErrors.Should().HaveCount(0);
            }
        }
        public async Task LoadWaterAllocation_LoadAggBridge_PrimaryUseCategoryCV_Null()
        {
            OrganizationsDim  organization;
            ReportingUnitsDim reportingUnit;
            VariablesDim      variable;
            WaterSourcesDim   waterSource;
            MethodsDim        method;
            DateDim           dataPublicationDate;
            DateDim           allocationPriorityDate;
            AggregatedAmount  aggregateAmount;
            BeneficialUsesCV  beneficialUsesCV;

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                organization = await OrganizationsDimBuilder.Load(db);

                reportingUnit = await ReportingUnitsDimBuilder.Load(db);

                variable = await VariablesDimBuilder.Load(db);

                waterSource = await WaterSourcesDimBuilder.Load(db);

                method = await MethodsDimBuilder.Load(db);

                dataPublicationDate = await DateDimBuilder.Load(db);

                allocationPriorityDate = await DateDimBuilder.Load(db);

                beneficialUsesCV = await BeneficalUsesBuilder.Load(db);

                aggregateAmount = AggregatedAmountBuilder.Create();

                aggregateAmount.PrimaryUseCategory = null;

                aggregateAmount.ReportingUnitUUID     = reportingUnit.ReportingUnitUuid;
                aggregateAmount.BeneficialUseCategory = beneficialUsesCV.Name;
                aggregateAmount.OrganizationUUID      = organization.OrganizationUuid;
                aggregateAmount.VariableSpecificUUID  = variable.VariableSpecificUuid;
                aggregateAmount.WaterSourceUUID       = waterSource.WaterSourceUuid;
                aggregateAmount.MethodUUID            = method.MethodUuid;
                aggregateAmount.DataPublicationDate   = dataPublicationDate.Date;
            }

            var sut = CreateWaterAllocationAccessor();

            var result = await sut.LoadAggregatedAmounts((new Faker()).Random.AlphaNumeric(10), new[] { aggregateAmount });

            result.Should().BeTrue();

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                var dbAggregateAmount = await db.AggregatedAmountsFact.SingleAsync();

                dbAggregateAmount.Should().NotBeNull();
                dbAggregateAmount.PrimaryUseCategoryCV.Should().BeNull();

                var dbAggBridge = await db.AggBridgeBeneficialUsesFact.SingleAsync();

                dbAggBridge.Should().NotBeNull();
                dbAggBridge.AggBridgeId.Should().BeGreaterThan(0);
                dbAggBridge.AggregatedAmountId.Should().Be(dbAggregateAmount.AggregatedAmountId);
                dbAggBridge.BeneficialUseCV.Should().Be(beneficialUsesCV.Name);

                db.ImportErrors.Should().HaveCount(0);
            }
        }
        public async Task LoadWaterAllocation_LoadAllocationBridge_PrimaryUseCategoryCV_Null()
        {
            OrganizationsDim organization;
            VariablesDim     variable;
            WaterSourcesDim  waterSource;
            MethodsDim       method;
            DateDim          dataPublicationDate;
            DateDim          allocationPriorityDate;
            WaterAllocation  waterAllocation;
            BeneficialUsesCV beneficialUsesCV;
            string           startTestString = "01/01";
            string           endTestString   = "12/01";

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                organization = await OrganizationsDimBuilder.Load(db);

                variable = await VariablesDimBuilder.Load(db);

                waterSource = await WaterSourcesDimBuilder.Load(db);

                method = await MethodsDimBuilder.Load(db);

                dataPublicationDate = await DateDimBuilder.Load(db);

                allocationPriorityDate = await DateDimBuilder.Load(db);

                beneficialUsesCV = await BeneficalUsesBuilder.Load(db);

                waterAllocation = WaterAllocationBuilder.Create(new WaterAllocationBuilderOptions {
                    RecordType = WaterAllocationRecordType.None
                });

                waterAllocation.PrimaryUseCategory = null;

                waterAllocation.BeneficialUseCategory    = beneficialUsesCV.Name;
                waterAllocation.OrganizationUUID         = organization.OrganizationUuid;
                waterAllocation.VariableSpecificUUID     = variable.VariableSpecificUuid;
                waterAllocation.WaterSourceUUID          = waterSource.WaterSourceUuid;
                waterAllocation.MethodUUID               = method.MethodUuid;
                waterAllocation.DataPublicationDate      = dataPublicationDate.Date;
                waterAllocation.AllocationPriorityDate   = allocationPriorityDate.Date;
                waterAllocation.AllocationTimeframeStart = startTestString;
                waterAllocation.AllocationTimeframeEnd   = endTestString;
            }

            var sut    = CreateWaterAllocationAccessor();
            var result = await sut.LoadWaterAllocation((new Faker()).Random.AlphaNumeric(10), new[] { waterAllocation });

            result.Should().BeTrue();

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                var dbAllocationAmount = await db.AllocationAmountsFact.SingleAsync();

                dbAllocationAmount.Should().NotBeNull();
                dbAllocationAmount.PrimaryUseCategoryCV.Should().BeNull();

                var dbAllocationBridge = await db.AllocationBridgeBeneficialUsesFact.SingleAsync();

                dbAllocationBridge.Should().NotBeNull();
                dbAllocationBridge.AllocationBridgeId.Should().BeGreaterThan(0);
                dbAllocationBridge.AllocationAmountId.Should().Be(dbAllocationBridge.AllocationAmountId);
                dbAllocationBridge.BeneficialUseCV.Should().Be(beneficialUsesCV.Name);

                db.ImportErrors.Should().HaveCount(0);
            }
        }
        public async Task LoadWaterAllocation_SimpleLoad()
        {
            OrganizationsDim organization;
            VariablesDim     variable;
            WaterSourcesDim  waterSource;
            MethodsDim       method;
            DateDim          dataPublicationDate;
            DateDim          allocationPriorityDate;
            WaterAllocation  waterAllocation;
            string           startTestString = "01/01";
            string           endTestString   = "12/01";

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                organization = await OrganizationsDimBuilder.Load(db);

                variable = await VariablesDimBuilder.Load(db);

                waterSource = await WaterSourcesDimBuilder.Load(db);

                method = await MethodsDimBuilder.Load(db);

                dataPublicationDate = await DateDimBuilder.Load(db);

                allocationPriorityDate = await DateDimBuilder.Load(db);

                waterAllocation = WaterAllocationBuilder.Create(new WaterAllocationBuilderOptions {
                    RecordType = WaterAllocationRecordType.None
                });

                waterAllocation.OrganizationUUID         = organization.OrganizationUuid;
                waterAllocation.VariableSpecificUUID     = variable.VariableSpecificUuid;
                waterAllocation.WaterSourceUUID          = waterSource.WaterSourceUuid;
                waterAllocation.MethodUUID               = method.MethodUuid;
                waterAllocation.DataPublicationDate      = dataPublicationDate.Date;
                waterAllocation.AllocationPriorityDate   = allocationPriorityDate.Date;
                waterAllocation.AllocationTimeframeStart = startTestString;
                waterAllocation.AllocationTimeframeEnd   = endTestString;
            }

            var sut    = CreateWaterAllocationAccessor();
            var result = await sut.LoadWaterAllocation((new Faker()).Random.AlphaNumeric(10), new[] { waterAllocation });

            result.Should().BeTrue();

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                var dbAllocationAmount = await db.AllocationAmountsFact.SingleAsync();

                dbAllocationAmount.AllocationAmountId.Should().NotBe(0);
                dbAllocationAmount.OrganizationId.Should().Be(organization.OrganizationId);
                dbAllocationAmount.VariableSpecificId.Should().Be(variable.VariableSpecificId);
                dbAllocationAmount.WaterSourceId.Should().Be(waterSource.WaterSourceId);
                dbAllocationAmount.MethodId.Should().Be(method.MethodId);
                dbAllocationAmount.DataPublicationDateId.Should().Be(dataPublicationDate.DateId);
                dbAllocationAmount.AllocationPriorityDateID.Should().Be(allocationPriorityDate.DateId);
                dbAllocationAmount.AllocationTimeframeStart.Should().Be(startTestString);
                dbAllocationAmount.AllocationTimeframeEnd.Should().Be(endTestString);
                db.ImportErrors.Should().HaveCount(0);
            }
        }
        public async Task LoadWaterAllocation_ExemptOfPriorityFlow(bool exemptOfPriorityFlow, DateTime?priorityDate, string allocationFlow_CFS, string allocationVolume_AF)
        {
            OrganizationsDim organization;
            VariablesDim     variable;
            WaterSourcesDim  waterSource;
            MethodsDim       method;
            DateDim          dataPublicationDate;
            WaterAllocation  waterAllocation;
            string           startTestString = "01/01";
            string           endTestString   = "12/01";

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                organization = await OrganizationsDimBuilder.Load(db);

                variable = await VariablesDimBuilder.Load(db);

                waterSource = await WaterSourcesDimBuilder.Load(db);

                method = await MethodsDimBuilder.Load(db);

                dataPublicationDate = await DateDimBuilder.Load(db);

                waterAllocation = WaterAllocationBuilder.Create(new WaterAllocationBuilderOptions {
                    RecordType = WaterAllocationRecordType.None
                });

                //////////////////// Exempt of Volume Flow Priority Columns
                // When exempt is TRUE priority date, allocation flow or allocation volume can be NULL.
                waterAllocation.ExemptOfVolumeFlowPriority = exemptOfPriorityFlow;
                waterAllocation.AllocationPriorityDate     = priorityDate;
                waterAllocation.AllocationFlow_CFS         = allocationFlow_CFS;
                waterAllocation.AllocationVolume_AF        = allocationVolume_AF;
                ////////////////////

                waterAllocation.OrganizationUUID         = organization.OrganizationUuid;
                waterAllocation.VariableSpecificUUID     = variable.VariableSpecificUuid;
                waterAllocation.WaterSourceUUID          = waterSource.WaterSourceUuid;
                waterAllocation.MethodUUID               = method.MethodUuid;
                waterAllocation.DataPublicationDate      = dataPublicationDate.Date;
                waterAllocation.AllocationTimeframeStart = startTestString;
                waterAllocation.AllocationTimeframeEnd   = endTestString;
            }

            var sut    = CreateWaterAllocationAccessor();
            var result = await sut.LoadWaterAllocation((new Faker()).Random.AlphaNumeric(10), new[] { waterAllocation });

            result.Should().BeTrue();

            using (var db = new WaDEContext(Configuration.GetConfiguration()))
            {
                var dbAllocationAmount = await db.AllocationAmountsFact.SingleAsync();

                dbAllocationAmount.AllocationAmountId.Should().NotBe(0);
                dbAllocationAmount.ExemptOfVolumeFlowPriority.GetValueOrDefault(false).Should().Be(exemptOfPriorityFlow);
                dbAllocationAmount.AllocationFlow_CFS.ToString().Should().Be(allocationFlow_CFS ?? "");
                dbAllocationAmount.AllocationVolume_AF.ToString().Should().Be(allocationVolume_AF ?? "");

                if (priorityDate.HasValue)
                {
                    dbAllocationAmount.AllocationPriorityDateID.Should().BeGreaterThan(0);
                }
                else
                {
                    dbAllocationAmount.AllocationPriorityDateID.Should().BeNull();
                }

                db.ImportErrors.Should().HaveCount(0);
            }
        }