public async Task Then_execute_throws_exception_from_aggregate_with_stack_trace() { var syncCommand = new AlwaysFaultAsyncCommand(Guid.NewGuid()); var expectedMessage = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId); await GridNode.Execute(CommandPlan.New(syncCommand, Timeout, expectedMessage)) .ShouldThrow <SampleAggregateException>(e => e.StackTrace.Contains(typeof(SampleAggregate).Name)); }
public void PlanExecute_doesnt_throw_exception_after_wait_with_timeout() { var syncCommand = new LongOperationCommand(1000, Guid.NewGuid()); var expectedMessage = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId); var plan = CommandPlan.New(syncCommand, expectedMessage); Assert.False(GridNode.Execute(plan).Wait(100)); }
public async Task SyncExecute_throws_exception_from_aggregate_on_fault_wait_by_Node() { var syncCommand = new AlwaysFaultCommand(Guid.NewGuid()); var expectedMessage = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId); await GridNode.Execute(CommandPlan.New(syncCommand, Timeout, expectedMessage)) .ShouldThrow <SampleAggregateException>(); }
public async Task PlanExecute_by_result_throws_exception_after_default_timeout() { var syncCommand = new LongOperationCommand(1000, Guid.NewGuid()); var expectedMessage = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId); var plan = CommandPlan.New(syncCommand, TimeSpan.FromMilliseconds(500), expectedMessage); await GridNode.Execute(plan) .ShouldThrow <TimeoutException>(); }
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); }
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 async Task FutureDomainEvent_envelops_has_unique_id() { _aggregateId = Guid.NewGuid(); var testCommandA = new ScheduleEventInFutureCommand(DateTime.Now.AddSeconds(1), _aggregateId, "test value A"); var testCommandB = new ScheduleEventInFutureCommand(DateTime.Now.AddSeconds(2), _aggregateId, "test value B"); _eventA = await GridNode.Execute(CommandPlan.New(testCommandA, Timeout, Expect.Message <FutureEventOccuredEvent>(e => e.SourceId, testCommandA.AggregateId))); _eventB = await GridNode.Execute(CommandPlan.New(testCommandB, Timeout, Expect.Message <FutureEventOccuredEvent>(e => e.SourceId, testCommandB.AggregateId))); }
public async Task When_async_method_finished_produced_events_has_sagaId_from_command() { var externalCallCommand = new AsyncMethodCommand(43, Guid.NewGuid(), Guid.NewGuid()); var domainEvent = await GridNode.Execute(CommandPlan.New(externalCallCommand, TimeSpan.FromDays(1), Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, externalCallCommand.AggregateId))); Assert.AreEqual(externalCallCommand.SagaId, domainEvent.SagaId); }
public async Task After_wait_end_aggregate_event_is_applied() { var syncCommand = new AsyncMethodCommand(42, Guid.NewGuid()); await GridNode.Execute(CommandPlan.New(syncCommand, Timeout, Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId))); var aggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId); Assert.AreEqual(syncCommand.Parameter.ToString(), aggregate.Value); }
public async Task After_wait_aggregate_should_be_changed() { var syncCommand = new AsyncMethodCommand(42, Guid.NewGuid()); var expectedMessage = Expect.Message <AggregateChangedEventNotification>(e => e.AggregateId, syncCommand.AggregateId); await GridNode.Execute(CommandPlan.New(syncCommand, Timeout, expectedMessage)); var aggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId); Assert.AreEqual(syncCommand.Parameter.ToString(), aggregate.Value); }
public async Task SyncExecute_will_finish() { 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); await GridNode.Execute(CommandPlan.New(syncCommand, Timeout, changeExpect)); var aggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId); Assert.AreEqual(syncCommand.Parameter.ToString(), aggregate.Value); }
public void Raising_several_future_events_for_different_aggregates() { _commandA = new ScheduleEventInFutureCommand(DateTime.Now.AddSeconds(0.5), Guid.NewGuid(), "test value A"); var expectedMessageA = Expect.Message <FutureEventOccuredEvent>(e => e.SourceId, _commandA.AggregateId); var planA = CommandPlan.New(_commandA, expectedMessageA); _commandB = new ScheduleEventInFutureCommand(DateTime.Now.AddSeconds(0.5), Guid.NewGuid(), "test value B"); var expectedMessageB = Expect.Message <FutureEventOccuredEvent>(e => e.SourceId, _commandB.AggregateId); var planB = CommandPlan.New(_commandB, expectedMessageB); var taskA = GridNode.Execute <FutureEventOccuredEvent>(planA).ContinueWith(r => _eventA = r.Result); var taskB = GridNode.Execute <FutureEventOccuredEvent>(planB).ContinueWith(r => _eventB = r.Result); Task.WaitAll(taskA, taskB); }
public void Then_events_are_applied_to_aggregate_after_wait_finish() { var syncCommand = new AsyncMethodCommand(42, Guid.NewGuid()); var expectedMessage = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId); var task = GridNode.Execute(CommandPlan.New(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); }
public async Task When_async_method_is_called_other_commands_can_be_executed_before_async_results() { var aggregateId = Guid.NewGuid(); var asyncCommand = new AsyncMethodCommand(43, Guid.NewGuid(), Guid.NewGuid(), TimeSpan.FromSeconds(3)); var syncCommand = new ChangeSampleAggregateCommand(42, aggregateId); var asyncCommandTask = GridNode.PrepareCommand(asyncCommand) .Expect <SampleAggregateChangedEvent>() .Execute(); await GridNode.Execute(CommandPlan.New(syncCommand, TimeSpan.FromSeconds(1), Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId))); var sampleAggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId); Assert.AreEqual(syncCommand.Parameter.ToString(), sampleAggregate.Value); var waitResults = await asyncCommandTask; Assert.AreEqual(asyncCommand.Parameter.ToString(), waitResults.Message <SampleAggregateChangedEvent>().Value); }