Skip to content

Commit

Permalink
termination outside cover period test added
Browse files Browse the repository at this point in the history
  • Loading branch information
wojteksuwala committed Jan 30, 2019
1 parent 956cd95 commit 39fcb83
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions NoCqrs.Tests/PolicyTerminationUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,14 @@ public void CanTerminatePolicyInTheMiddle()
Equal(new DateTime(2019,1,1), policy.Versions.WithNumber(2).CoverPeriod.ValidFrom);
Equal(Money.Euro(246.58), policy.Versions.WithNumber(2).TotalPremium);
}

[Fact]
public void CannotTerminatePolicyAfterCoverEnds()
{
var policy = PolicyTestData.StandardOneYearPolicy(new DateTime(2019, 1, 1));
var terminationDate = new DateTime(2020, 1, 2);
var ex = Assert.Throws<ApplicationException>(() => policy.TerminatePolicy(terminationDate));
Equal("No active version at given date", ex.Message);
}
}
}
7 changes: 6 additions & 1 deletion NoCqrs/Domain/Policy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ public void TerminatePolicy(DateTime effectiveDateOfChange)
{
throw new ApplicationException("No active version at given date");
}


if (!versionAtEffectiveDate.CoverPeriod.Contains(effectiveDateOfChange))
{
throw new ApplicationException("Cannot terminate policy at given date as it is not withing cover period");
}

var termVer = AddNewVersionBasedOn
(
versionAtEffectiveDate,
Expand Down

0 comments on commit 39fcb83

Please sign in to comment.