Esempio n. 1
0
        public void TestEventSourcing_AfterManyTests_TestStateSignalled()
        {
            var probe = CreateTestActor("probe");

            Sys.EventStream.Subscribe(probe, typeof(DomainEvent <TestAggregate, TestAggregateId, TestStateSignalEvent>));
            var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager");
            var aggregateId      = TestAggregateId.New;


            var command = new CreateTestCommand(aggregateId);

            aggregateManager.Tell(command);

            for (var i = 0; i < 5; i++)
            {
                var test        = new Test(TestId.New);
                var testCommand = new AddTestCommand(aggregateId, test);
                aggregateManager.Tell(testCommand);
            }

            var poisonCommand = new PoisonTestAggregateCommand(aggregateId);

            aggregateManager.Tell(poisonCommand);

            var reviveCommand = new PublishTestStateCommand(aggregateId);

            aggregateManager.Tell(reviveCommand);



            ExpectMsg <DomainEvent <TestAggregate, TestAggregateId, TestStateSignalEvent> >(
                x => x.AggregateEvent.LastSequenceNr == 6 &&
                x.AggregateEvent.Version == 6 &&
                x.AggregateEvent.AggregateState.TestCollection.Count == 5);
        }
        public void TestEventMultipleEmitSourcing_AfterManyMultiCommand_TestStateSignalled()
        {
            var eventProbe = CreateTestProbe("event-probe");

            Sys.EventStream.Subscribe(eventProbe, typeof(DomainEvent <TestAggregate, TestAggregateId, TestStateSignalEvent>));
            var aggregateManager = Sys.ActorOf(Props.Create(() => new TestAggregateManager()), "test-aggregatemanager");
            var aggregateId      = TestAggregateId.New;
            var commandId        = CommandId.New;


            var command = new CreateTestCommand(aggregateId, commandId);

            aggregateManager.Tell(command);

            var test         = new Test(TestId.New);
            var testSourceId = CommandId.New;
            var testCommand  = new AddFourTestsCommand(aggregateId, testSourceId, test);

            aggregateManager.Tell(testCommand);

            var poisonCommand = new PoisonTestAggregateCommand(aggregateId);

            aggregateManager.Tell(poisonCommand);

            var reviveCommand = new PublishTestStateCommand(aggregateId);

            aggregateManager.Tell(reviveCommand);


            eventProbe
            .ExpectMsg <DomainEvent <TestAggregate, TestAggregateId, TestStateSignalEvent> >(
                x => x.AggregateEvent.LastSequenceNr == 5 &&
                x.AggregateEvent.Version == 5 &&
                x.AggregateEvent.AggregateState.TestCollection.Count == 4);
        }
Esempio n. 3
0
        public void TestEventSourcing_AfterManyTests_TestStateSignalled()
        {
            var eventProbe = CreateTestProbe("event-probe");

            Sys.EventStream.Subscribe(eventProbe, typeof(IDomainEvent <TestAggregateId, TestStateSignalEvent>));
            var aggregateId = TestAggregateId.New;
            var commandId   = CommandId.New;
            var bus         = Sys.GetExtension <ServiceProviderHolder>().ServiceProvider.GetRequiredService <ICommandBus>();

            var command = new CreateTestCommand(aggregateId, commandId);

            bus.Publish(command).GetAwaiter().GetResult();

            for (var i = 0; i < 5; i++)
            {
                var test          = new Test(TestId.New);
                var testCommandId = CommandId.New;
                var testCommand   = new AddTestCommand(aggregateId, testCommandId, test);
                bus.Publish(testCommand).GetAwaiter().GetResult();
            }

            var poisonCommand = new PoisonTestAggregateCommand(aggregateId);

            bus.Publish(poisonCommand).GetAwaiter().GetResult();

            var reviveCommand = new PublishTestStateCommand(aggregateId);

            bus.Publish(reviveCommand).GetAwaiter().GetResult();

            eventProbe.ExpectMsg <IDomainEvent <TestAggregateId, TestStateSignalEvent> >(
                x => x.AggregateEvent.LastSequenceNr == 6 &&
                x.AggregateEvent.Version == 6 &&
                x.AggregateEvent.AggregateState.TestCollection.Count == 5);
        }
Esempio n. 4
0
        public void TestEventMultipleEmitSourcing_AfterManyMultiCommand_TestStateSignalled()
        {
            var aggregateId = TestAggregateId.New;
            var commandId   = SourceId.New;

            var command = new CreateTestCommand(aggregateId).WithSourceId(commandId);

            var test         = new TestEntity(TestId.New);
            var testSourceId = SourceId.New;
            var testCommand  = new AddFourTestsCommand(aggregateId, test).WithSourceId(testSourceId);

            var poisonCommand = new PoisonTestAggregateCommand(aggregateId);

            var fixture = new AggregateFixture <TestAggregateId, TestAggregate,
                                                ITestAggregateState, TestAggregateState>(this);

            fixture.For(aggregateId)
            .GivenNothing()
            .When(command, testCommand, poisonCommand)
            .ThenExpectDomainEvent <TestCreatedEvent>()
            .ThenExpectDomainEvent <TestAddedEvent>()
            .ThenExpectDomainEvent <TestAddedEvent>()
            .ThenExpectDomainEvent <TestAddedEvent>()
            .ThenExpectDomainEvent <TestAddedEvent>()
            .ThenExpectState(
                x => x.TestCollection.Count == 4);
        }
Esempio n. 5
0
        private bool Execute(PoisonTestAggregateCommand command)
        {
            if (!IsNew)
            {
                Context.Stop(Self);
            }
            else
            {
                TestErrors++;
                Throw(new TestedErrorEvent(TestErrors));
            }

            return(true);
        }
Esempio n. 6
0
        private bool Execute(PoisonTestAggregateCommand command)
        {
            if (!IsNew)
            {
                Context.Stop(Self);
            }
            else
            {
                TestErrors++;
                Throw(new TestedErrorEvent(TestErrors));
                Reply(TestExecutionResult.FailedWith(command.SourceId));
            }

            return(true);
        }
Esempio n. 7
0
        public Task <IExecutionResult> Execute(PoisonTestAggregateCommand command)
        {
            if (!IsNew)
            {
                Context.Stop(Self);
            }
            else
            {
                TestErrors++;
                Throw(new TestedErrorEvent(TestErrors));
                ReplyFailure(TestExecutionResult.FailedWith(command.Metadata.SourceId));
            }

            return(Task.FromResult(ExecutionResult.Success()));
        }
Esempio n. 8
0
        public async Task <Result> Do(PoisonTestAggregateCommand command)
        {
            if (!IsNew)
            {
                DeactivateOnIdle();
            }
            else
            {
                TestErrors++;
                await Emit(new TestedErrorEvent(Id, TestErrors));

                return(Result.Fail("TestedErrorEvent"));
            }

            return(Result.Success);
        }
Esempio n. 9
0
        public void TestEventSourcing_AfterManyTests_TestStateSignalled()
        {
            IEnumerable <ICommand> GetCommands(TestAggregateId testAggregateId, ISourceId commandId1)
            {
                var command = new CreateTestCommand(testAggregateId).WithSourceId(commandId1);

                yield return(command);

                for (var i = 0; i < 5; i++)
                {
                    var test          = new TestEntity(TestId.New);
                    var testCommandId = SourceId.New;
                    var testCommand   = new AddTestCommand(testAggregateId, test).WithSourceId(testCommandId);
                    yield return(testCommand);
                }

                var poisonCommand = new PoisonTestAggregateCommand(testAggregateId);

                yield return(poisonCommand);
            }

            var aggregateId = TestAggregateId.New;
            var commandId   = SourceId.New;

            var fixture = new AggregateFixture <TestAggregateId, TestAggregate,
                                                ITestAggregateState, TestAggregateState>(this);

            fixture.For(aggregateId)
            .GivenNothing()
            .When(GetCommands(aggregateId, commandId).ToArray())
            .ThenExpectDomainEvent <TestCreatedEvent>()
            .ThenExpectDomainEvent <TestAddedEvent>()
            .ThenExpectDomainEvent <TestAddedEvent>()
            .ThenExpectDomainEvent <TestAddedEvent>()
            .ThenExpectDomainEvent <TestAddedEvent>()
            .ThenExpectDomainEvent <TestAddedEvent>()
            .ThenExpectState(
                x => x.TestCollection.Count == 5);
        }