コード例 #1
0
        public void Given_a_policy_When_executing_command_for_another_instance_Then_getting_error()
        {
            var policy = new InsurancePolicy();
            var id     = Guid.NewGuid().ToString();

            policy.Apply(new PolicyCreatedEvent(id));

            policy.Invoking(async p =>
                            await p.Execute(new ProcessNewTimeCommand(Guid.NewGuid().ToString(), DateTimeOffset.Now)))
            .Should().Throw <AggregateIdMismatchException>();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        public void Given_not_issued_policy_When_claiming_over_budget_Then_get_error()
        {
            var policy = new InsurancePolicy();
            var id     = Guid.NewGuid().ToString();

            policy.Apply(new PolicyCreatedEvent(id),
                         new PolicyDurationSetEvent(id, TimeSpan.FromDays(1)),
                         new PolicyAmountSetEvent(id, 10m));

            policy.Invoking(async p => await p.Execute(new ProcessClaimCommand(policy.Address, new Claim(1m))))
            .Should().Throw <PolicyNotIssuedException>();
        }
コード例 #4
0
        public void Given_a_policy_When_executing_unknown_command_Then_getting_error()
        {
            var policy = new InsurancePolicy();
            var id     = Guid.NewGuid().ToString();

            policy.Apply(new PolicyCreatedEvent(id));

            policy.Invoking(
                async p => await p.Execute(new SomeCommand {
                Destination = Address.New <InsurancePolicy>(id)
            }))
            .Should().Throw <UnsupportedCommandException>();
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        public void Given_expired_policy_When_claiming_within_budget_Then_getting_error()
        {
            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),
                         new PolicyTimePassedEvent(id, DateTimeOffset.Now.AddDays(1)),
                         new PolicyExpiredEvent(id)
                         );

            policy.Invoking(async p => await p.Execute(new ProcessClaimCommand(policy.Address, new Claim(1m))))
            .Should().Throw <PolicyExpiredException>();
        }
コード例 #7
0
        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));
        }