Skip to content

Commit

Permalink
La til flere tester av ProxyManagementService
Browse files Browse the repository at this point in the history
  • Loading branch information
larsolavk committed Nov 21, 2024
1 parent 7b14db2 commit be3cf75
Showing 1 changed file with 105 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>._))
Expand Down Expand Up @@ -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<string>._))
Expand Down Expand Up @@ -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<string>._))
Expand Down Expand Up @@ -164,15 +161,14 @@ public async Task
A<RoleAssignment>.That.Matches(ra =>
ra.RecipientSsn == "12345678901"
&& ra.RoleCode == Constants.CollectiveProxyRoleCode)))
.MustHaveHappened();
.MustHaveHappened(1, Times.Exactly);

A.CallTo(() => _fakeRoleAssignmentRepository.RemoveRoleAssignment(A<RoleAssignment>._))
.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<string>._))
Expand Down Expand Up @@ -201,16 +197,15 @@ public async Task
A<RoleAssignment>.That.Matches(ra =>
ra.RecipientSsn == "12345678901"
&& ra.RoleCode == Constants.CollectiveProxyRoleCode)))
.MustHaveHappened();
.MustHaveHappened(1, Times.Exactly);

A.CallTo(() => _fakeRoleAssignmentRepository.RemoveRoleAssignment(A<RoleAssignment>._))
.MustNotHaveHappened();
}


[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<string>._))
Expand Down Expand Up @@ -238,11 +233,105 @@ public async Task
A<RoleAssignment>.That.Matches(ra =>
ra.RecipientSsn == "12345678901"
&& ra.HeirSsn == "12345678903")))
.MustHaveHappened();
.MustHaveHappened(1, Times.Exactly);

A.CallTo(() => _fakeRoleAssignmentRepository.AddRoleAssignment(A<RoleAssignment>._)).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<string>._))
.ReturnsLazily((call) =>
{
var estateSsn = call.Arguments.Get<string>("estateSsn")!;
var factory = new RoleAssignmentFactory(estateSsn);
return Task.FromResult(new List<RoleAssignment>
{
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<RoleAssignment>.That.Matches(ra =>
ra.RecipientSsn == "98765432198"
&& ra.RoleCode == Constants.CollectiveProxyRoleCode)))
.MustHaveHappened(1, Times.Exactly);

A.CallTo(() => _fakeRoleAssignmentRepository.RemoveRoleAssignment(A<RoleAssignment>._)).MustNotHaveHappened();
}

[Fact]
public async Task EstateWithThreeHeirs_When_AllHeirsHaveProbateRole_And_TwoHeirsHaveAppointedTheSameNonHeirAsIndividualProxy_ShouldNot_AddOrRemoveRoles()
{
// Arrange
A.CallTo(() => _fakeRoleAssignmentRepository.GetRoleAssignmentsForEstate(A<string>._))
.ReturnsLazily((call) =>
{
var estateSsn = call.Arguments.Get<string>("estateSsn")!;
var factory = new RoleAssignmentFactory(estateSsn);
return Task.FromResult(new List<RoleAssignment>
{
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<RoleAssignment>._)).MustNotHaveHappened();
A.CallTo(() => _fakeRoleAssignmentRepository.RemoveRoleAssignment(A<RoleAssignment>._)).MustNotHaveHappened();
}

[Fact]
public async Task EstateWithThreeHeirs_When_AllHeirsHaveProbateRole_And_AllHeirsHaveAppointedDifferentNonHeirAsIndividualProxy_ShouldNot_AddOrRemoveRoles()
{
// Arrange
A.CallTo(() => _fakeRoleAssignmentRepository.GetRoleAssignmentsForEstate(A<string>._))
.ReturnsLazily((call) =>
{
var estateSsn = call.Arguments.Get<string>("estateSsn")!;
var factory = new RoleAssignmentFactory(estateSsn);
return Task.FromResult(new List<RoleAssignment>
{
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<RoleAssignment>._)).MustNotHaveHappened();
A.CallTo(() => _fakeRoleAssignmentRepository.RemoveRoleAssignment(A<RoleAssignment>._)).MustNotHaveHappened();
}
}

0 comments on commit be3cf75

Please sign in to comment.