Esempio n. 1
0
        public async Task Then_SyncExecute_until_aggregate_event_wait_by_Node()
        {
            var syncCommand = new LongOperationCommand(1000, Guid.NewGuid());
            await GridNode.Execute(CommandPlan.New(syncCommand, TimeSpan.FromDays(1), Expect.Message <SampleAggregateChangedEvent>(nameof(SampleAggregateChangedEvent.SourceId), syncCommand.AggregateId)));

            var aggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId);

            Assert.AreEqual(syncCommand.Parameter.ToString(), aggregate.Value);
        }
Esempio n. 2
0
        public void Given_SyncExecute_until_projection_build_event_wait_by_caller()
        {
            _syncCommand = new LongOperationCommand(1000, Guid.NewGuid());
            var expectedMessage = Expect.Message <AggregateChangedEventNotification>(e => e.AggregateId, _syncCommand.AggregateId);

            _changedEvent = GridNode.Execute(CommandPlan.New(_syncCommand, Timeout, expectedMessage)).Result;

            _aggregate = LoadAggregate <SampleAggregate>(_syncCommand.AggregateId);
        }
        public void Aggregate_will_apply_events_later_than_command_execution_finish()
        {
            var syncCommand = new LongOperationCommand(42, Guid.NewGuid());

            GridNode.Execute(syncCommand);
            var aggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId);

            Assert.AreNotEqual(syncCommand.Parameter, aggregate.Value);
        }
        public async Task CommandWaiter_will_wait_for_all_of_expected_message()
        {
            var cmd = new LongOperationCommand(1000, Guid.NewGuid());

            await GridNode.NewCommandWaiter(Timeout)
            .Expect <SampleAggregateChangedEvent>(e => e.SourceId == cmd.AggregateId)
            .And <SampleAggregateCreatedEvent>(e => e.SourceId == cmd.AggregateId)
            .Create()
            .Execute(cmd)
            .ShouldThrow <TimeoutException>();
        }
        public async Task Wait_for_timeout_command_throws_excpetion()
        {
            var cmd = new LongOperationCommand(1000, Guid.NewGuid());

            var res = GridNode.NewCommandWaiter(TimeSpan.FromMilliseconds(100))
                      .Expect <SampleAggregateChangedEvent>(e => e.SourceId == cmd.AggregateId)
                      .Create()
                      .Execute(cmd);

            await res.ShouldThrow <TimeoutException>();
        }
Esempio n. 6
0
        public async Task Default_wait_for_event_matches_by_correlation_id_when_projection_builder_cares_about_metadata()
        {
            var commandA = new LongOperationCommand(10, Guid.NewGuid());
            var commandB = new LongOperationCommand(10, Guid.NewGuid());

            GridNode.Execute(commandB);
            var res = await GridNode.PrepareCommand(commandA)
                      .Expect <AggregateChangedEventNotification>()
                      .Execute(TimeSpan.FromSeconds(500), false);

            //will pick right command by correlation Id
            Assert.AreEqual(commandA.AggregateId, res.Message <AggregateChangedEventNotification>().AggregateId);
        }
        public void After_wait_ends_aggregate_should_be_changed()
        {
            var cmd = new LongOperationCommand(100, Guid.NewGuid());

            var msg = GridNode.NewCommandWaiter(Timeout)
                      .Expect <SampleAggregateChangedEvent>(e => e.SourceId == cmd.AggregateId)
                      .Create()
                      .Execute(cmd)
                      .Result
                      .Message <SampleAggregateChangedEvent>();

            Assert.AreEqual(cmd.Parameter.ToString(), msg.Value);
        }
        public async Task MessageWaiter_after_cmd_execute_should_waits_until_aggregate_event()
        {
            var cmd = new LongOperationCommand(100, Guid.NewGuid());

            var waiter = GridNode.NewWaiter(Timeout)
                         .Expect <SampleAggregateChangedEvent>(e => e.SourceId == cmd.AggregateId)
                         .Create();

            GridNode.Execute(cmd);
            var res = await waiter;

            Assert.AreEqual(cmd.Parameter.ToString(), res.Message <SampleAggregateChangedEvent>().Value);
        }
Esempio n. 9
0
        public async Task SyncExecute_will_wait_for_all_of_expected_message_by_Node_with_message_base_class()
        {
            var syncCommand = new LongOperationCommand(1000, Guid.NewGuid());

            var changeExpect = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId);
            var createExpect = Expect.Message <SampleAggregateCreatedEvent>(e => e.SourceId, syncCommand.AggregateId);

            var commandPlan = new CommandPlan <object>(syncCommand,
                                                       TimeSpan.FromSeconds(1),
                                                       changeExpect,
                                                       createExpect);

            await GridNode.Execute(commandPlan)
            .ShouldThrow <TimeoutException>();
        }
Esempio n. 10
0
        public void Then_SyncExecute_until_aggregate_event_wait_by_caller()
        {
            var syncCommand     = new LongOperationCommand(1000, Guid.NewGuid());
            var expectedMessage = Expect.Message <SampleAggregateChangedEvent>(nameof(SampleAggregateChangedEvent.SourceId),
                                                                               syncCommand.AggregateId);
            var task = GridNode.Execute(syncCommand, expectedMessage);

            if (!task.Wait(Timeout))
            {
                throw new TimeoutException();
            }

            //to finish persistence
            var aggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId);

            Assert.AreEqual(syncCommand.Parameter.ToString(), aggregate.Value);
        }