public void CreateAggregate_Always_Throws() { var context = new AggregateExecutionContext(Fixtures.Pipelines.FakeCreateCommand()); scope.Invoking(s => s.CreateAggregate <FakeAggregateRoot, FakeAggregateState>(Unified.NewCode(), context)) .Should().Throw <InvalidOperationException>(); }
public async Task SaveAsync_NoEvents_Throws() { var id = Unified.NewCode(); var executionContext = new AggregateExecutionContext(Fixtures.Pipelines.FakeCreateCommand()); var aggregateRoot = new FakeAggregateRoot(id, executionContext); await store.Awaiting(s => s.SaveAsync(aggregateRoot)).Should().ThrowAsync <InvalidOperationException>(); }
/// <summary> /// Creates <see cref="IntegrationEventExecutionResult"/>. /// </summary> /// <param name="context">Execution context.</param> /// <param name="setup">Configures integration event.</param> /// <typeparam name="TIntegrationEvent">Type of integration event.</typeparam> /// <returns>Execution result.</returns> protected IExecutionResult IntegrationEvent <TIntegrationEvent>(AggregateExecutionContext context, Action <TIntegrationEvent> setup) where TIntegrationEvent : IntegrationEvent, new() { var @event = context.CreateIntegrationEvent <TIntegrationEvent>(); setup(@event); return(new IntegrationEventExecutionResult(@event)); }
public static TIntegrationEvent IntegrationEvent <TIntegrationEvent>(Command command, Action <TIntegrationEvent> setup) where TIntegrationEvent : IntegrationEvent, new() { var context = new AggregateExecutionContext(command); var @event = context.CreateIntegrationEvent <TIntegrationEvent>(); setup(@event); return(@event); }
private FakeAggregateRoot SetupAggregateRootWithEvents() { var id = Unified.NewCode(); var executionContext = new AggregateExecutionContext(Fixtures.Pipelines.FakeCreateCommand()); var aggregateRoot = new FakeAggregateRoot(id, executionContext); aggregateRoot.Create(FixtureUtils.String()); aggregateRoot.Update(FixtureUtils.String()); return(aggregateRoot); }
public async Task SaveAsync_HasEvents_Stores() { var id = Unified.NewCode(); var executionContext = new AggregateExecutionContext(Fixtures.Pipelines.FakeCreateCommand()); var aggregateRoot = new FakeAggregateRoot(id, executionContext); aggregateRoot.Create(FixtureUtils.String()); aggregateRoot.Update(FixtureUtils.String()); await store.SaveAsync(aggregateRoot); var events = await store.GetAsync(aggregateRoot.Id, 0); events.Should().BeEquivalentTo(aggregateRoot.Events, options => options.ForMessage()); }
/// <summary> /// Deconstructs request. /// </summary> /// <param name="command">Value of <see cref="Command"/>.</param> /// <param name="context">Value of <see cref="Context"/>.</param> /// <param name="transactionScope">Value of <see cref="TransactionScope"/>.</param> public void Deconstruct(out TCommand command, out AggregateExecutionContext context, out ITransactionScope transactionScope) { command = Command; context = Context; transactionScope = TransactionScope; }
/// <summary> /// Initializes a new instance of the <see cref="CommandRequest{TCommand}"/> class. /// </summary> /// <param name="command">Value for <see cref="Command"/>.</param> public CommandRequest(TCommand command) { Command = command; Context = new AggregateExecutionContext(command); TransactionScope = new NullTransactionScope(); }
/// <inheritdoc /> public TAggregateRoot CreateAggregate <TAggregateRoot, TAggregateState>(string id, AggregateExecutionContext context) where TAggregateRoot : BaseAggregateRoot <TAggregateState> where TAggregateState : AggregateState, new() { throw new InvalidOperationException($"'{typeof(NullTransactionScope)}' can't be created and attached."); }
/// <inheritdoc /> public Task <TAggregateRoot> FindAggregateAsync <TAggregateRoot, TAggregateState>(string aggregateId, AggregateExecutionContext context) where TAggregateRoot : AggregateRoot <TAggregateState> where TAggregateState : AggregateState, new() { throw new InvalidOperationException($"No Aggregate could be retrieved from '{typeof(NullTransactionScope)}'."); }
/// <inheritdoc /> public TAggregateRoot CreateAggregate <TAggregateRoot, TAggregateState>(string id, AggregateExecutionContext context) where TAggregateRoot : BaseAggregateRoot <TAggregateState> where TAggregateState : AggregateState, new() { var aggregate = aggregateStore.Create <TAggregateRoot, TAggregateState>(id, context); aggregates[aggregate.Id] = aggregate; return(aggregate); }
/// <inheritdoc /> public async Task <TAggregateRoot> FindAggregateAsync <TAggregateRoot, TAggregateState>(string aggregateId, AggregateExecutionContext context) where TAggregateRoot : AggregateRoot <TAggregateState> where TAggregateState : AggregateState, new() { try { if (aggregates.TryGetValue(aggregateId, out var abstractAggregate)) { return((TAggregateRoot)abstractAggregate); } var aggregate = await aggregateStore.GetAsync <TAggregateRoot, TAggregateState>(aggregateId, context); aggregates[aggregateId] = aggregate; return(aggregate); } catch (KeyNotFoundException) { return(null); } }
public FakeAggregateRoot(string id, AggregateExecutionContext context) : base(id, context) { }