diff --git a/test/oed-authz.UnitTests/Services/ProxyManagementServiceTests/UpdateProxyRoleAssignmentsTests.cs b/test/oed-authz.UnitTests/Services/ProxyManagementServiceTests/UpdateProxyRoleAssignmentsTests.cs index e75c618..ca35c49 100644 --- a/test/oed-authz.UnitTests/Services/ProxyManagementServiceTests/UpdateProxyRoleAssignmentsTests.cs +++ b/test/oed-authz.UnitTests/Services/ProxyManagementServiceTests/UpdateProxyRoleAssignmentsTests.cs @@ -74,8 +74,7 @@ public async Task EstateWithThreeHeirs_When_AllHeirsHaveProbateRole_ShouldNot_Ad } [Fact] - public async Task - EstateWithThreeHeirs_When_AllHeirsHaveProbateOrFormuesfullmaktRoles_ShouldNot_AddOrRemoveRoles() + public async Task EstateWithThreeHeirs_When_AllHeirsHaveProbateOrFormuesfullmaktRoles_ShouldNot_AddOrRemoveRoles() { // Arrange A.CallTo(() => _fakeRoleAssignmentRepository.GetRoleAssignmentsForEstate(A._)) @@ -104,8 +103,7 @@ public async Task } [Fact] - public async Task - EstateWithThreeHeirs_When_AllHeirsHaveProbateRole_And_OneHeirHasAppointedAnotherHeirAsIndividualProxy_ShouldNot_AddOrRemoveRoles() + public async Task EstateWithThreeHeirs_When_AllHeirsHaveProbateRole_And_OneHeirHasAppointedAnotherHeirAsIndividualProxy_ShouldNot_AddOrRemoveRoles() { // Arrange A.CallTo(() => _fakeRoleAssignmentRepository.GetRoleAssignmentsForEstate(A._)) @@ -135,8 +133,7 @@ public async Task } [Fact] - public async Task - EstateWithThreeHeirs_When_TwoHeirsHaveProbateRole_And_OneHeirHasAppointedTheOtherHeirAsIndividualProxy_Should_AddCollectiveProxyRole() + public async Task EstateWithThreeHeirs_When_TwoHeirsHaveProbateRole_And_OneHeirHasAppointedTheOtherHeirAsIndividualProxy_Should_AddCollectiveProxyRole() { // Arrange A.CallTo(() => _fakeRoleAssignmentRepository.GetRoleAssignmentsForEstate(A._)) @@ -164,15 +161,14 @@ public async Task A.That.Matches(ra => ra.RecipientSsn == "12345678901" && ra.RoleCode == Constants.CollectiveProxyRoleCode))) - .MustHaveHappened(); + .MustHaveHappened(1, Times.Exactly); A.CallTo(() => _fakeRoleAssignmentRepository.RemoveRoleAssignment(A._)) .MustNotHaveHappened(); } [Fact] - public async Task - EstateWithThreeHeirs_When_AllHeirsHaveProbateRole_And_TwoHeirsHaveBothAppointedTheThirdHeirAsIndividualProxy_Should_AddCollectiveProxyRole() + public async Task EstateWithThreeHeirs_When_AllHeirsHaveProbateRole_And_TwoHeirsHaveBothAppointedTheThirdHeirAsIndividualProxy_Should_AddCollectiveProxyRole() { // Arrange A.CallTo(() => _fakeRoleAssignmentRepository.GetRoleAssignmentsForEstate(A._)) @@ -201,7 +197,7 @@ public async Task A.That.Matches(ra => ra.RecipientSsn == "12345678901" && ra.RoleCode == Constants.CollectiveProxyRoleCode))) - .MustHaveHappened(); + .MustHaveHappened(1, Times.Exactly); A.CallTo(() => _fakeRoleAssignmentRepository.RemoveRoleAssignment(A._)) .MustNotHaveHappened(); @@ -209,8 +205,7 @@ public async Task [Fact] - public async Task - EstateWithThreeHeirs_When_OneHeirWithoutProbateRole_HasAppointedAnotherHeirAsIndividualProxy_Should_RemoveProxyRole() + public async Task EstateWithThreeHeirs_When_OneHeirWithoutProbateRole_HasAppointedAnotherHeirAsIndividualProxy_Should_RemoveProxyRole() { // Arrange A.CallTo(() => _fakeRoleAssignmentRepository.GetRoleAssignmentsForEstate(A._)) @@ -238,11 +233,105 @@ public async Task A.That.Matches(ra => ra.RecipientSsn == "12345678901" && ra.HeirSsn == "12345678903"))) - .MustHaveHappened(); + .MustHaveHappened(1, Times.Exactly); A.CallTo(() => _fakeRoleAssignmentRepository.AddRoleAssignment(A._)).MustNotHaveHappened(); } -} -// TODO: Proxies that are not heirs -// TODO: Proxies that are no logner valid + [Fact] + public async Task EstateWithThreeHeirs_When_AllHeirsHaveProbateRole_And_AllHeirsHaveAppointedTheSameNonHeirAsIndividualProxy_Should_AddCollectiveProxyRole() + { + // Arrange + A.CallTo(() => _fakeRoleAssignmentRepository.GetRoleAssignmentsForEstate(A._)) + .ReturnsLazily((call) => + { + var estateSsn = call.Arguments.Get("estateSsn")!; + var factory = new RoleAssignmentFactory(estateSsn); + + return Task.FromResult(new List + { + factory.ProbateRole("12345678901"), + factory.ProbateRole("12345678902"), + factory.ProbateRole("12345678903"), + factory.IndividualProxyRole(heirSsn: "12345678901", proxySsn: "98765432198"), + factory.IndividualProxyRole(heirSsn: "12345678902", proxySsn: "98765432198"), + factory.IndividualProxyRole(heirSsn: "12345678903", proxySsn: "98765432198") + }); + }); + + var sut = new ProxyManagementService(_fakeRoleAssignmentRepository, _fakeLogger); + + // Act + await sut.UpdateProxyRoleAssigments("11111111111"); + + // Assert + A.CallTo(() => _fakeRoleAssignmentRepository.AddRoleAssignment( + A.That.Matches(ra => + ra.RecipientSsn == "98765432198" + && ra.RoleCode == Constants.CollectiveProxyRoleCode))) + .MustHaveHappened(1, Times.Exactly); + + A.CallTo(() => _fakeRoleAssignmentRepository.RemoveRoleAssignment(A._)).MustNotHaveHappened(); + } + + [Fact] + public async Task EstateWithThreeHeirs_When_AllHeirsHaveProbateRole_And_TwoHeirsHaveAppointedTheSameNonHeirAsIndividualProxy_ShouldNot_AddOrRemoveRoles() + { + // Arrange + A.CallTo(() => _fakeRoleAssignmentRepository.GetRoleAssignmentsForEstate(A._)) + .ReturnsLazily((call) => + { + var estateSsn = call.Arguments.Get("estateSsn")!; + var factory = new RoleAssignmentFactory(estateSsn); + + return Task.FromResult(new List + { + factory.ProbateRole("12345678901"), + factory.ProbateRole("12345678902"), + factory.ProbateRole("12345678903"), + factory.IndividualProxyRole(heirSsn: "12345678902", proxySsn: "98765432198"), + factory.IndividualProxyRole(heirSsn: "12345678903", proxySsn: "98765432198") + }); + }); + + var sut = new ProxyManagementService(_fakeRoleAssignmentRepository, _fakeLogger); + + // Act + await sut.UpdateProxyRoleAssigments("11111111111"); + + // Assert + A.CallTo(() => _fakeRoleAssignmentRepository.AddRoleAssignment(A._)).MustNotHaveHappened(); + A.CallTo(() => _fakeRoleAssignmentRepository.RemoveRoleAssignment(A._)).MustNotHaveHappened(); + } + + [Fact] + public async Task EstateWithThreeHeirs_When_AllHeirsHaveProbateRole_And_AllHeirsHaveAppointedDifferentNonHeirAsIndividualProxy_ShouldNot_AddOrRemoveRoles() + { + // Arrange + A.CallTo(() => _fakeRoleAssignmentRepository.GetRoleAssignmentsForEstate(A._)) + .ReturnsLazily((call) => + { + var estateSsn = call.Arguments.Get("estateSsn")!; + var factory = new RoleAssignmentFactory(estateSsn); + + return Task.FromResult(new List + { + factory.ProbateRole("12345678901"), + factory.ProbateRole("12345678902"), + factory.ProbateRole("12345678903"), + factory.IndividualProxyRole(heirSsn: "12345678901", proxySsn: "98765432101"), + factory.IndividualProxyRole(heirSsn: "12345678902", proxySsn: "98765432102"), + factory.IndividualProxyRole(heirSsn: "12345678903", proxySsn: "98765432103") + }); + }); + + var sut = new ProxyManagementService(_fakeRoleAssignmentRepository, _fakeLogger); + + // Act + await sut.UpdateProxyRoleAssigments("11111111111"); + + // Assert + A.CallTo(() => _fakeRoleAssignmentRepository.AddRoleAssignment(A._)).MustNotHaveHappened(); + A.CallTo(() => _fakeRoleAssignmentRepository.RemoveRoleAssignment(A._)).MustNotHaveHappened(); + } +}