Skip to content

Commit

Permalink
Psp 3042 (#1110)
Browse files Browse the repository at this point in the history
* remove lease notes specific repository behaviour. Changing the response navigations was causing failures in some cases.

* test corrections.

* increment patch number

Co-authored-by: Smith <[email protected]>
  • Loading branch information
devinleighsmith and Smith authored Mar 16, 2022
1 parent 13d17c8 commit 4dea2bc
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions backend/api/Pims.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<UserSecretsId>0ef6255f-9ea0-49ec-8c65-c172304b4926</UserSecretsId>
<Version>1.1.3-21.45</Version>
<AssemblyVersion>1.1.3.21</AssemblyVersion>
<Version>1.1.4-21.45</Version>
<AssemblyVersion>1.1.4.21</AssemblyVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProjectGuid>16BC0468-78F6-4C91-87DA-7403C919E646</ProjectGuid>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion backend/dal/Repositories/Interfaces/ILeaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface ILeaseRepository : IRepository<PimsLease>
int Count();
IEnumerable<PimsLease> Get(LeaseFilter filter, bool loadPayments = false);
long GetRowVersion(long id);
PimsLease Get(long id, bool skipNavigations = false);
PimsLease Get(long id);
Paged<PimsLease> GetPage(LeaseFilter filter);
PimsLease Add(PimsLease lease, bool userOverride = false);
PimsLease Update(PimsLease lease, bool commitTransaction = true);
Expand Down
13 changes: 5 additions & 8 deletions backend/dal/Repositories/LeaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ public long GetRowVersion(long id)
this.User.ThrowIfNotAuthorized(Permissions.LeaseView);
return this.Context.PimsLeases.Where(l => l.LeaseId == id)?.Select(l => l.ConcurrencyControlNumber)?.FirstOrDefault() ?? throw new KeyNotFoundException();
}
public PimsLease Get(long id, bool skipNavigations = false)
public PimsLease Get(long id)
{
this.User.ThrowIfNotAuthorized(Permissions.LeaseView);

IQueryable<PimsLease> leaseQuery = this.Context.PimsLeases.Where(l => l.LeaseId == id);
if (!skipNavigations)
{
leaseQuery = leaseQuery.Include(l => l.PimsPropertyLeases)
PimsLease lease = this.Context.PimsLeases
.Include(l => l.PimsPropertyLeases)
.ThenInclude(p => p.Property)
.ThenInclude(p => p.Address)
.ThenInclude(p => p.Country)
Expand Down Expand Up @@ -151,9 +149,8 @@ public PimsLease Get(long id, bool skipNavigations = false)
.ThenInclude(t => t.LeasePaymentMethodTypeCodeNavigation)
.Include(t => t.PimsLeaseTerms)
.ThenInclude(t => t.PimsLeasePayments)
.ThenInclude(t => t.LeasePaymentStatusTypeCodeNavigation);
}
PimsLease lease = leaseQuery.FirstOrDefault() ?? throw new KeyNotFoundException();
.ThenInclude(t => t.LeasePaymentStatusTypeCodeNavigation)
.FirstOrDefault(l=>l.LeaseId == id) ?? throw new KeyNotFoundException();

lease.LeasePurposeTypeCodeNavigation = this.Context.PimsLeasePurposeTypes.Single(type => type.LeasePurposeTypeCode == lease.LeasePurposeTypeCode);
lease.PimsPropertyImprovements = lease.PimsPropertyImprovements.OrderBy(i => i.PropertyImprovementTypeCode).ToArray();
Expand Down
3 changes: 2 additions & 1 deletion backend/dal/Services/SecurityDepositService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ public PimsLease UpdateLeaseDepositNote(long leaseId, long leaseRowVersion, stri
{
_user.ThrowIfNotAuthorized(Permissions.LeaseEdit);
ValidateServiceCall(leaseId, leaseRowVersion);
var lease = _leaseRepository.Get(leaseId, true);
var lease = _leaseRepository.Get(leaseId);
lease.ReturnNotes = note;
_leaseRepository.Update(lease);
_leaseRepository.CommitTransaction();

return _leaseRepository.Get(leaseId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void GetLeases_All_Success()
var service = helper.GetService<Mock<IPimsRepository>>();
var mapper = helper.GetService<IMapper>();

service.Setup(m => m.Lease.Get(It.IsAny<long>(), false)).Returns(lease);
service.Setup(m => m.Lease.Get(It.IsAny<long>())).Returns(lease);

// Act
var result = controller.GetLease(1);
Expand All @@ -46,7 +46,7 @@ public void GetLeases_All_Success()
var actualResult = Assert.IsType<Model.LeaseModel>(actionResult.Value);
var expectedResult = mapper.Map<Model.LeaseModel>(lease);
Assert.Equal(expectedResult, actualResult, new DeepPropertyCompare());
service.Verify(m => m.Lease.Get(It.IsAny<long>(), false), Times.Once());
service.Verify(m => m.Lease.Get(It.IsAny<long>()), Times.Once());
}
#endregion
#region UpdateProperties
Expand Down
10 changes: 5 additions & 5 deletions backend/tests/unit/dal/Services/LeaseTermServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void AddTerm()
var leaseRepository = helper.GetService<Mock<Repositories.ILeaseRepository>>();
var leaseTermRepository = helper.GetService<Mock<Repositories.ILeaseTermRepository>>();
leaseService.Setup(x => x.IsRowVersionEqual(It.IsAny<long>(), It.IsAny<long>())).Returns(true);
leaseRepository.Setup(x => x.Get(It.IsAny<long>(), false)).Returns(lease);
leaseRepository.Setup(x => x.Get(It.IsAny<long>())).Returns(lease);

// Act
var term = new PimsLeaseTerm() { TermStartDate = DateTime.Now, LeaseId = lease.Id, Lease = lease };
Expand All @@ -47,7 +47,7 @@ public void AddTerm()

// Assert
leaseTermRepository.Verify(x => x.Add(term), Times.Once);
leaseRepository.Verify(x => x.Get(lease.Id, false), Times.Once);
leaseRepository.Verify(x => x.Get(lease.Id), Times.Once);
}

[Fact]
Expand Down Expand Up @@ -204,7 +204,7 @@ public void UpdateTerm()
var leaseService = helper.GetService<Mock<ILeaseService>>();
var leaseRepository = helper.GetService<Mock<Repositories.ILeaseRepository>>();
leaseService.Setup(x => x.IsRowVersionEqual(It.IsAny<long>(), It.IsAny<long>())).Returns(true);
leaseRepository.Setup(x => x.Get(It.IsAny<long>(), false)).Returns(lease);
leaseRepository.Setup(x => x.Get(It.IsAny<long>())).Returns(lease);
var leaseTermRepository = helper.GetService<Mock<Repositories.ILeaseTermRepository>>();
leaseTermRepository.Setup(x => x.GetById(It.IsAny<long>(), It.IsAny<bool>())).Returns(originalTerm);

Expand All @@ -215,7 +215,7 @@ public void UpdateTerm()

// Assert
leaseTermRepository.Verify(x => x.Update(term), Times.Once);
leaseRepository.Verify(x => x.Get(lease.Id, false), Times.Once);
leaseRepository.Verify(x => x.Get(lease.Id), Times.Once);
}

[Fact]
Expand Down Expand Up @@ -324,7 +324,7 @@ public void DeleteTerm()
var leaseService = helper.GetService<Mock<ILeaseService>>();
var leaseRepository = helper.GetService<Mock<Repositories.ILeaseRepository>>();
leaseService.Setup(x => x.IsRowVersionEqual(It.IsAny<long>(), It.IsAny<long>())).Returns(true);
leaseRepository.Setup(x => x.Get(It.IsAny<long>(), false)).Returns(lease);
leaseRepository.Setup(x => x.Get(It.IsAny<long>())).Returns(lease);
var leaseTermRepository = helper.GetService<Mock<Repositories.ILeaseTermRepository>>();
leaseTermRepository.Setup(x => x.GetById(It.IsAny<long>(), It.IsAny<bool>())).Returns(originalTerm);

Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "1.1.3-21.45",
"version": "1.1.4-21.45",
"private": true,
"dependencies": {
"@bcgov/bc-sans": "1.0.1",
Expand Down

0 comments on commit 4dea2bc

Please sign in to comment.