public async Task Given_issued_policy_When_claiming_in_budget_Then_get_payment() { var policy = new InsurancePolicy(); var id = Guid.NewGuid().ToString(); policy.Apply(new PolicyCreatedEvent(id), new PolicyDurationSetEvent(id, TimeSpan.FromDays(1)), new PolicyAmountSetEvent(id, 10m), new PolicyIssuedEvent(id, DateTimeOffset.Now)); var events = await policy.Execute(new ProcessClaimCommand(policy.Address, new Claim(5m))); events.Should().BeLike(new ClaimFulfilledEvent(id, 5)); }
public async Task Given_policy_with_duration_and_amount_When_issuing_Then_get_issued_event() { var policy = new InsurancePolicy(); IAggregateRoot policyAggregate = policy; policyAggregate.Apply(new PolicyCreatedEvent()); policyAggregate.Apply(new PolicyDurationSetEvent(policy.Address.Id, TimeSpan.FromDays(1))); policyAggregate.Apply(new PolicyAmountSetEvent(policy.Address.Id, 10m)); var issueDate = DateTimeOffset.Now; var events = await policy.Execute(new IssuePolicyCommand(policy.Address, issueDate)); events.Should().BeLike(new PolicyIssuedEvent(policy.Address.Id, issueDate)); }
public async Task Given_issued_policy_When_time_pass_less_then_duration_Then_policy_does_not_expire() { var policy = new InsurancePolicy(); var id = Guid.NewGuid().ToString(); policy.Apply(new PolicyCreatedEvent(id), new PolicyDurationSetEvent(id, TimeSpan.FromDays(10)), new PolicyAmountSetEvent(id, 10m), new PolicyIssuedEvent(id, DateTimeOffset.Now) ); var newTime = DateTimeOffset.Now.AddDays(1); var events = await policy.Execute(new ProcessNewTimeCommand(id, newTime)); events.Should().BeLike(new PolicyTimePassedEvent(id, newTime)); }
public async Task Given_scriptedPolicy_When_execute_cmd_Then_script_is_involved() { // Policy defines the extensions point // Scripting engine provides basic abstractions: // set script command // script-related event // Scripting engine definition // script sanitizers // read model build for pure calculations (without an aggregate state change) var policy = new InsurancePolicy(); var policyCreatedEvent = new PolicyCreatedEvent("test_policy"); policy.Apply(policyCreatedEvent); policy.Apply(new IssuePolicyScriptSetEvent("test_policy", "")); var result = await policy.Execute(new IssuePolicyCommand(policyCreatedEvent.Source)); throw new NotImplementedException(); }