From 73e2a8c3c1c76ca53442ad248e9db65ba18c1898 Mon Sep 17 00:00:00 2001 From: Jack Nolley Date: Thu, 12 Dec 2024 11:04:15 -0600 Subject: [PATCH 1/3] got initial data need to test --- .../ISiteAccessor.cs | 1 + .../SiteAccessor.cs | 12 ++++++++++++ .../WaterAllocation.cs | 9 +++++++++ .../IWaterAllocationManager.cs | 1 + .../WaterAllocationManager.cs | 6 ++++++ 5 files changed, 29 insertions(+) diff --git a/src/API/WesternStatesWater.WestDaat.Accessors/ISiteAccessor.cs b/src/API/WesternStatesWater.WestDaat.Accessors/ISiteAccessor.cs index 5cd3d8a4..e17452f0 100644 --- a/src/API/WesternStatesWater.WestDaat.Accessors/ISiteAccessor.cs +++ b/src/API/WesternStatesWater.WestDaat.Accessors/ISiteAccessor.cs @@ -23,6 +23,7 @@ public interface ISiteAccessor : IServiceContractBase Task> GetVariableInfoListByUuid(string siteUuid); Task> GetMethodInfoListByUuid(string siteUuid); + Task> GetWaterRightInfoListByReportingUnitUuid(string reportingUnitUuid); IEnumerable GetJSONLDData(); } diff --git a/src/API/WesternStatesWater.WestDaat.Accessors/SiteAccessor.cs b/src/API/WesternStatesWater.WestDaat.Accessors/SiteAccessor.cs index a1c25f78..109b6270 100644 --- a/src/API/WesternStatesWater.WestDaat.Accessors/SiteAccessor.cs +++ b/src/API/WesternStatesWater.WestDaat.Accessors/SiteAccessor.cs @@ -79,6 +79,18 @@ public async Task> GetWaterRightInfoListByUuid(stri .ToListAsync(); } + public async Task> GetWaterRightInfoListByReportingUnitUuid(string reportingUnitUuid) + { + await using var db = _databaseContextFactory.Create(); + return await db.AllocationAmountsFact + .Where(aaf => aaf.AllocationBridgeSitesFact.Any(absf => + absf.Site.RegulatoryOverlayBridgeSitesFact.Any(robsf => + robsf.RegulatoryOverlay.RegulatoryReportingUnitsFact.Any(rruf => + rruf.ReportingUnit.ReportingUnitUuid == reportingUnitUuid)))) + .ProjectTo(DtoMapper.Configuration) + .ToListAsync(); + } + public async Task> GetSiteUsageBySiteUuid(string siteUuid) { await using var db = _databaseContextFactory.Create(); diff --git a/src/API/WesternStatesWater.WestDaat.Client.Functions/WaterAllocation.cs b/src/API/WesternStatesWater.WestDaat.Client.Functions/WaterAllocation.cs index 6ce4fa74..e41ec5b3 100644 --- a/src/API/WesternStatesWater.WestDaat.Client.Functions/WaterAllocation.cs +++ b/src/API/WesternStatesWater.WestDaat.Client.Functions/WaterAllocation.cs @@ -174,6 +174,15 @@ public async Task GetWaterSiteRightsListByUuid([HttpTrigger(Au return await CreateOkResponse(request, result); } + [Function(nameof(GetWaterRightsListByReportingUnitUuid))] + public async Task GetWaterRightsListByReportingUnitUuid( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Overlays/{reportingUnitUuid}/Rights")] HttpRequestData request, + string reportingUnitUuid) + { + var result = await _waterAllocationManager.GetWaterRightsInfoListByReportingUnitUuid(reportingUnitUuid); + return await CreateOkResponse(request, result); + } + [Function(nameof(GetSiteUsageByByUuid))] public async Task GetSiteUsageByByUuid([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Sites/{siteUuid}/SiteUsage")] HttpRequestData request, string siteUuid) { diff --git a/src/API/WesternStatesWater.WestDaat.Contracts.Client/IWaterAllocationManager.cs b/src/API/WesternStatesWater.WestDaat.Contracts.Client/IWaterAllocationManager.cs index 012b227a..8c5579bf 100644 --- a/src/API/WesternStatesWater.WestDaat.Contracts.Client/IWaterAllocationManager.cs +++ b/src/API/WesternStatesWater.WestDaat.Contracts.Client/IWaterAllocationManager.cs @@ -47,5 +47,6 @@ public interface IWaterAllocationManager : IServiceContractBase Task> GetOverlayInfoById(string reportingUnitUuid); Task> GetSiteMethodInfoListByUuid(string siteUuid); + Task> GetWaterRightsInfoListByReportingUnitUuid(string reportingUnitUuid); } } diff --git a/src/API/WesternStatesWater.WestDaat.Managers/WaterAllocationManager.cs b/src/API/WesternStatesWater.WestDaat.Managers/WaterAllocationManager.cs index a57fb3ab..e654eeba 100644 --- a/src/API/WesternStatesWater.WestDaat.Managers/WaterAllocationManager.cs +++ b/src/API/WesternStatesWater.WestDaat.Managers/WaterAllocationManager.cs @@ -227,6 +227,12 @@ public async Task GetWaterSiteLocation(string siteUuid) return (await _siteAccessor.GetWaterRightInfoListByUuid(siteUuid)).Map>(); } + async Task> ClientContracts.IWaterAllocationManager.GetWaterRightsInfoListByReportingUnitUuid(string reportingUnitUuid) + { + return (await _siteAccessor.GetWaterRightInfoListByReportingUnitUuid(reportingUnitUuid)) + .Map>(); + } + async Task ClientContracts.IWaterAllocationManager.GetSiteUsageBySiteUuid(string siteUuid) { var siteUsagePoints = await _siteAccessor.GetSiteUsageBySiteUuid(siteUuid); From fea2f8ddb8e523ca3e6759e45eeb94c75414eae8 Mon Sep 17 00:00:00 2001 From: Jack Nolley Date: Fri, 13 Dec 2024 13:06:41 -0600 Subject: [PATCH 2/3] tested --- .../WaterAllocationManagerTests.cs | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/src/API/WesternStatesWater.WestDaat.Tests.ManagerTests/WaterAllocationManagerTests.cs b/src/API/WesternStatesWater.WestDaat.Tests.ManagerTests/WaterAllocationManagerTests.cs index fe0f6240..7b03cafe 100644 --- a/src/API/WesternStatesWater.WestDaat.Tests.ManagerTests/WaterAllocationManagerTests.cs +++ b/src/API/WesternStatesWater.WestDaat.Tests.ManagerTests/WaterAllocationManagerTests.cs @@ -908,8 +908,122 @@ public async Task GetOverlayInfoById_ReturnsOverlayEntries() result.Select(x => x.WaDEOverlayUuid).Should().BeEquivalentTo(new[] { "overlay_1", "overlay_2" }); _waterAllocationAccessorMock.Verify(); } + + [TestMethod] + public async Task GetWaterRightsInfoListByReportingUnitUuid_Results_Returned() + { + // Arrange + var reportingUnitUuid = "test_uuid"; + _siteAccessorMock.Setup(x => x.GetWaterRightInfoListByReportingUnitUuid(reportingUnitUuid)) + .ReturnsAsync(new List + { + new CommonContracts.WaterRightInfoListItem { WaterRightNativeId = "test_water_right_uuid" } + }) + .Verifiable(); + + var manager = CreateWaterAllocationManager(); + + // Act + var result = await manager.GetWaterRightsInfoListByReportingUnitUuid(reportingUnitUuid); + + // Assert + result.Should().NotBeNull(); + result.Count.Should().Be(1); + result[0].WaterRightNativeId.Should().Be("test_water_right_uuid"); + _siteAccessorMock.Verify(); + } + + [TestMethod] + public async Task GetWaterRightsInfoListByReportingUnitUuid_MultipleResults_Returned() + { + // Arrange + var reportingUnitUuid = "test_uuid"; + _siteAccessorMock.Setup(x => x.GetWaterRightInfoListByReportingUnitUuid(reportingUnitUuid)) + .ReturnsAsync(new List + { + new CommonContracts.WaterRightInfoListItem + { + WaterRightNativeId = "water_right_1", + AllocationUuid = "alloc_1", + Owner = "Owner1", + PriorityDate = DateTime.Parse("2000-01-01"), + ExpirationDate = DateTime.Parse("2025-01-01"), + LegalStatus = "Valid", + Flow = 10.5, + Volume = 20.0, + BeneficialUses = new List { "Irrigation", "Recreation" } + }, + new CommonContracts.WaterRightInfoListItem + { + WaterRightNativeId = "water_right_2", + AllocationUuid = "alloc_2", + Owner = "Owner2", + PriorityDate = DateTime.Parse("2010-05-15"), + ExpirationDate = null, + LegalStatus = "Pending", + Flow = 5.0, + Volume = 10.0, + BeneficialUses = new List { "Municipal" } + } + }) + .Verifiable(); + + var manager = CreateWaterAllocationManager(); + + // Act + var result = await manager.GetWaterRightsInfoListByReportingUnitUuid(reportingUnitUuid); + + // Assert + result.Should().NotBeNull(); + result.Count.Should().Be(2); + + // Validate the first item + result[0].WaterRightNativeId.Should().Be("water_right_1"); + result[0].AllocationUuid.Should().Be("alloc_1"); + result[0].Owner.Should().Be("Owner1"); + result[0].PriorityDate.Should().Be(DateTime.Parse("2000-01-01")); + result[0].ExpirationDate.Should().Be(DateTime.Parse("2025-01-01")); + result[0].LegalStatus.Should().Be("Valid"); + result[0].Flow.Should().Be(10.5); + result[0].Volume.Should().Be(20.0); + result[0].BeneficialUses.Should().BeEquivalentTo(new List { "Irrigation", "Recreation" }); + + // Validate the second item + result[1].WaterRightNativeId.Should().Be("water_right_2"); + result[1].AllocationUuid.Should().Be("alloc_2"); + result[1].Owner.Should().Be("Owner2"); + result[1].PriorityDate.Should().Be(DateTime.Parse("2010-05-15")); + result[1].ExpirationDate.Should().BeNull(); + result[1].LegalStatus.Should().Be("Pending"); + result[1].Flow.Should().Be(5.0); + result[1].Volume.Should().Be(10.0); + result[1].BeneficialUses.Should().BeEquivalentTo(new List { "Municipal" }); + _siteAccessorMock.Verify(); + } + + + [TestMethod] + public async Task GetWaterRightsInfoListByReportingUnitUuid_ThrowsException_WhenUuidIsNullOrEmpty() + { + // Arrange + _siteAccessorMock.Setup(x => x.GetWaterRightInfoListByReportingUnitUuid(null)) + .ThrowsAsync(new ArgumentException("ReportingUnitUuid cannot be null or empty.")); + _siteAccessorMock.Setup(x => x.GetWaterRightInfoListByReportingUnitUuid("")) + .ThrowsAsync(new ArgumentException("ReportingUnitUuid cannot be null or empty.")); + + var manager = CreateWaterAllocationManager(); + + // Act & Assert + await Assert.ThrowsExceptionAsync( + () => manager.GetWaterRightsInfoListByReportingUnitUuid(null), + "ReportingUnitUuid cannot be null or empty."); + + await Assert.ThrowsExceptionAsync( + () => manager.GetWaterRightsInfoListByReportingUnitUuid(""), + "ReportingUnitUuid cannot be null or empty."); + } private async Task CheckRecords(Stream entryStream, string fileEnd, List list) { From f76fdfabf10a2b72594431a4dae8745218c45ec7 Mon Sep 17 00:00:00 2001 From: Jack Nolley Date: Fri, 13 Dec 2024 13:07:18 -0600 Subject: [PATCH 3/3] Remove Extra Spaces --- .../WaterAllocationManagerTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/API/WesternStatesWater.WestDaat.Tests.ManagerTests/WaterAllocationManagerTests.cs b/src/API/WesternStatesWater.WestDaat.Tests.ManagerTests/WaterAllocationManagerTests.cs index 7b03cafe..3a87daa0 100644 --- a/src/API/WesternStatesWater.WestDaat.Tests.ManagerTests/WaterAllocationManagerTests.cs +++ b/src/API/WesternStatesWater.WestDaat.Tests.ManagerTests/WaterAllocationManagerTests.cs @@ -1001,8 +1001,6 @@ public async Task GetWaterRightsInfoListByReportingUnitUuid_MultipleResults_Retu _siteAccessorMock.Verify(); } - - [TestMethod] public async Task GetWaterRightsInfoListByReportingUnitUuid_ThrowsException_WhenUuidIsNullOrEmpty()