Esempio n. 1
0
        public async Task Given_default_policy()
        {
            var aggregateId      = Guid.NewGuid().ToString();
            var initialParameter = 1;
            var cmd = new InflateNewBallonCommand(initialParameter, aggregateId);
            await Node.Prepare(cmd)
            .Expect <BalloonCreated>()
            .Execute();

            var changedParameter             = 2;
            var changeSampleAggregateCommand = new WriteTitleCommand(changedParameter, aggregateId);

            await Node.Prepare(changeSampleAggregateCommand)
            .Expect <BalloonTitleChanged>()
            .Execute();

            Thread.Sleep(1000);

            var aggregates = await AggregateSnapshotRepository.New(AutoTestNodeDbConfiguration.Default.JournalConnectionString,
                                                                   BalloonAggregateFactory.Default)
                             .Load <Balloon>(aggregateId);

            //Snapshots_should_be_saved_two_times()
            Assert.Equal(2, aggregates.Length);
            //Restored_aggregates_should_have_same_ids()
            Assert.True(aggregates.All(s => s.Payload.Id == aggregateId));
            //First_snapshot_should_have_parameters_from_first_command()
            Assert.Equal(initialParameter.ToString(), aggregates.First().Payload.Title);
            //Second_snapshot_should_have_parameters_from_second_command()
            Assert.Equal(changedParameter.ToString(), aggregates.Skip(1).First().Payload.Title);
        }
        public async Task Given_save_on_each_message_policy_and_keep_2_snapshots()
        {
            var startEvent = new GotTiredEvent(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            var res = await Node.NewDebugWaiter()
                      .Expect <ProcessManagerCreated <SoftwareProgrammingState> >()
                      .Create()
                      .SendToProcessManagers(startEvent);

            var processId = res.Message <ProcessManagerCreated <SoftwareProgrammingState> >()
                            .SourceId;

            var continueEventA = new CoffeMakeFailedEvent(Guid.NewGuid().ToString(),
                                                          startEvent.PersonId,
                                                          BusinessDateTime.UtcNow,
                                                          processId);

            await Node.SendToProcessManagers(continueEventA);

            await Node.KillProcessManager <SoftwareProgrammingProcess, SoftwareProgrammingState>(processId);


            Version <ProcessStateAggregate <SoftwareProgrammingState> >[] snapshots = null;


            //Only_two_Snapshots_should_left()

            AwaitAssert(() =>
            {
                snapshots = AggregateSnapshotRepository.New(AutoTestNodeDbConfiguration.Default.JournalConnectionString)
                            .Load <ProcessStateAggregate <SoftwareProgrammingState> >(processId)
                            .Result;
                Assert.Equal(2, snapshots.Length);

                // Restored_aggregates_should_have_same_ids()
                Assert.True(snapshots.All(s => s.Payload.Id == processId));

                // First_Snapshots_should_have_coding_state_from_first_event()
                Assert.Equal(nameof(SoftwareProgrammingProcess.MakingCoffee),
                             snapshots.First()
                             .Payload.State.CurrentStateName);

                //Last_Snapshots_should_have_coding_state_from_last_event()
                Assert.Equal(nameof(SoftwareProgrammingProcess.Sleeping),
                             snapshots.Last()
                             .Payload.State.CurrentStateName);

                //All_snapshots_should_not_have_uncommited_events()
                Assert.Empty(snapshots.SelectMany(s => s.Payload.GetEvents()));
            },
                        TimeSpan.FromSeconds(10),
                        TimeSpan.FromSeconds(1));
        }
Esempio n. 3
0
        public async Task Given_default_policy()
        {
            var startEvent = new GotTiredEvent(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            var resTask = Node.NewDebugWaiter()
                          .Expect <ProcessReceivedMessage <SoftwareProgrammingState> >()
                          .Create()
                          .SendToProcessManagers(startEvent, MessageMetadata.New(startEvent.Id, null, null));

            var processId = (await resTask).Message <ProcessReceivedMessage <SoftwareProgrammingState> >().SourceId;

            var continueEvent = new CoffeMakeFailedEvent(processId, startEvent.PersonId, BusinessDateTime.UtcNow, processId);

            //to avoid racy state receiving expected message from processing GotTiredEvent
            await Node.NewDebugWaiter()
            .Expect <ProcessReceivedMessage <SoftwareProgrammingState> >(e => e.MessageId == continueEvent.Id)
            .Create()
            .SendToProcessManagers(continueEvent, processId);

            Log.Info("Testcase enforce additional snapshot save & delete, will kill process manager");
            await Node.KillProcessManager <SoftwareProgrammingProcess, SoftwareProgrammingState>(processId);

            var snapshots = await AggregateSnapshotRepository.New(AutoTestNodeDbConfiguration.Default.JournalConnectionString,
                                                                  AggregateFactory.Default)
                            .Load <ProcessStateAggregate <SoftwareProgrammingState> >(processId);

            //Snapshot_should_be_saved_one_time
            Assert.Single(snapshots);
            //Restored_process_state_should_have_correct_ids
            Assert.True(snapshots.All(s => s.Payload.Id == processId));
            //Snapshot_should_have_parameters_from_first_event = created event
            Assert.Equal(nameof(SoftwareProgrammingProcess.Coding),
                         snapshots.First().Payload.State.CurrentStateName);
            //All_snapshots_should_not_have_uncommited_events
            Assert.Empty(snapshots.SelectMany(s => s.Payload.GetEvents()));
        }