diff --git a/source/backend/dal/Repositories/LeasePaymentRepository.cs b/source/backend/dal/Repositories/LeasePaymentRepository.cs index aff970bf6f..a2b763c53f 100644 --- a/source/backend/dal/Repositories/LeasePaymentRepository.cs +++ b/source/backend/dal/Repositories/LeasePaymentRepository.cs @@ -70,7 +70,8 @@ public IEnumerable GetAllTracking(DateTime startDate, DateTime .ThenInclude(t => t.LeaseProgramTypeCodeNavigation) .Include(p => p.LeasePeriod) .ThenInclude(t => t.Lease) - //.ThenInclude(t => t.LeasePurposeTypeCodeNavigation) TODO: fix mappings + .ThenInclude(p => p.PimsLeaseLeasePurposes) + .ThenInclude(c => c.LeasePurposeTypeCodeNavigation) .Include(p => p.LeasePeriod) .ThenInclude(t => t.LeasePeriodStatusTypeCodeNavigation) .Include(p => p.LeasePeriod) diff --git a/source/backend/tests/core/Entities/LeaseHelper.cs b/source/backend/tests/core/Entities/LeaseHelper.cs index 130b3bbe75..f4f2c6ab66 100644 --- a/source/backend/tests/core/Entities/LeaseHelper.cs +++ b/source/backend/tests/core/Entities/LeaseHelper.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Linq; +using DocumentFormat.OpenXml.Office2010.Excel; using Pims.Dal; using Pims.Dal.Entities; using Entity = Pims.Dal.Entities; @@ -16,7 +18,7 @@ public static partial class EntityHelper /// /// public static Entity.PimsLease CreateLease(int pid, string lFileNo = null, string stakeholderFirstName = null, string stakeholderLastName = null, string motiFirstName = null, string motiLastName = null, PimsAddress address = null, bool addStakeholder = false, bool addProperty = true, - PimsLeaseProgramType pimsLeaseProgramType = null, PimsLeasePurposeType pimsLeasePurposeType = null, PimsLeaseStatusType pimsLeaseStatusType = null, PimsLeasePayRvblType pimsLeasePayRvblType = null, PimsLeaseInitiatorType pimsLeaseInitiatorType = null, PimsLeaseResponsibilityType pimsLeaseResponsibilityType = null, PimsLeaseLicenseType pimsLeaseLicenseType = null, PimsRegion region = null) + PimsLeaseProgramType pimsLeaseProgramType = null, PimsLeaseStatusType pimsLeaseStatusType = null, PimsLeasePayRvblType pimsLeasePayRvblType = null, PimsLeaseInitiatorType pimsLeaseInitiatorType = null, PimsLeaseResponsibilityType pimsLeaseResponsibilityType = null, PimsLeaseLicenseType pimsLeaseLicenseType = null, PimsRegion region = null) { var lease = new Entity.PimsLease() { @@ -38,13 +40,10 @@ public static Entity.PimsLease CreateLease(int pid, string lFileNo = null, strin } lease.MotiContact = $"{motiFirstName} {motiLastName}"; lease.LeaseProgramTypeCodeNavigation = pimsLeaseProgramType ?? new Entity.PimsLeaseProgramType() { Id = "testProgramType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" }; - //lease.LeaseProgramTypeCode = "testProgramType"; TODO: Fix Mappings - //lease.LeasePurposeTypeCodeNavigation = pimsLeasePurposeType ?? new Entity.PimsLeasePurposeType() { Id = "testPurposeType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" }; - //lease.LeasePurposeTypeCode = "testPurposeType"; + lease.LeaseProgramTypeCode = "testProgramType"; lease.LeaseStatusTypeCode = "testStatusType"; lease.LeaseStatusTypeCodeNavigation = pimsLeaseStatusType ?? new Entity.PimsLeaseStatusType() { Id = "testStatusType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" }; lease.LeasePayRvblTypeCodeNavigation = pimsLeasePayRvblType ?? new Entity.PimsLeasePayRvblType() { Id = "testRvblType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" }; - //lease.LeaseCategoryTypeCodeNavigation = pimsLeaseCategoryType ?? new Entity.PimsLeaseCategoryType() { Id = "testCategoryType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" }; lease.LeaseInitiatorTypeCodeNavigation = pimsLeaseInitiatorType ?? new Entity.PimsLeaseInitiatorType() { Id = "testInitiatorType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" }; lease.LeaseResponsibilityTypeCodeNavigation = pimsLeaseResponsibilityType ?? new Entity.PimsLeaseResponsibilityType() { Id = "testResponsibilityType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" }; lease.LeaseLicenseTypeCodeNavigation = pimsLeaseLicenseType ?? new Entity.PimsLeaseLicenseType() { Id = "testType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" }; @@ -69,13 +68,11 @@ public static Entity.PimsLease CreateLease(this PimsContext context, int pid, st var leasePurposeType = context.PimsLeasePurposeTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find lease purpose type."); var leaseStatusType = context.PimsLeaseStatusTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find lease status type."); var leasePayRvblType = context.PimsLeasePayRvblTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find lease rvbl type."); - //var leaseCategoryType = context.PimsLeaseCategoryTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find lease category type."); - // TODO: Fix Mappings var leaseInitiatorType = context.PimsLeaseInitiatorTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find lease initiator type."); var leaseResponsibilityType = context.PimsLeaseResponsibilityTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find lease reponsibility type."); var leaseLicenseType = context.PimsLeaseLicenseTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find lease license type."); - var lease = EntityHelper.CreateLease(pid, lFileNo, stakeholderFirstName, stakeholderLastName, motiFirstName, motiLastName, address, addStakeholder, addProperty, programType, leasePurposeType, leaseStatusType, leasePayRvblType, leaseInitiatorType, leaseResponsibilityType, leaseLicenseType); + var lease = CreateLease(pid, lFileNo, stakeholderFirstName, stakeholderLastName, motiFirstName, motiLastName, address, addStakeholder, addProperty, programType, leaseStatusType, leasePayRvblType, leaseInitiatorType, leaseResponsibilityType, leaseLicenseType); context.PimsLeases.Add(lease); return lease; } diff --git a/source/backend/tests/unit/dal/Repositories/PropertyRepositoryTest.cs b/source/backend/tests/unit/dal/Repositories/PropertyRepositoryTest.cs index b407b338b2..e0b795518b 100644 --- a/source/backend/tests/unit/dal/Repositories/PropertyRepositoryTest.cs +++ b/source/backend/tests/unit/dal/Repositories/PropertyRepositoryTest.cs @@ -389,7 +389,15 @@ public void GetMatchingIds_LeasePurpose_Success() // Arrange var repository = CreateRepositoryWithPermissions(Permissions.PropertyView); var property = EntityHelper.CreateProperty(100, isCoreInventory: true); - var lease = EntityHelper.CreateLease(1, pimsLeasePurposeType: new PimsLeasePurposeType() { Id = "test", Description = "Active", DbCreateUserid = "test", DbLastUpdateUserid = "test" }, addProperty: false); + var lease = EntityHelper.CreateLease(1, addProperty: false); + + lease.PimsLeaseLeasePurposes.Add(new PimsLeaseLeasePurpose() + { + LeaseLeasePurposeId = 100, + LeaseId = lease.LeaseId, + LeasePurposeTypeCode = "test", + }); + property.PimsPropertyLeases.Add(new PimsPropertyLease() { PropertyId = property.Internal_Id, LeaseId = lease.Internal_Id, Lease = lease }); _helper.AddAndSaveChanges(property);