Closed iappwebdev closed 9 months ago
This also makes difficult to use Aggregate without CommandService, when u read Aggregate using just AggregateStore then Aggregate ID is not initialised, and there is no simple way to set it as WithId is private.
@solomkae you load the aggregate instance from somewhere, right? If you use aggregateStore.Load<TAggregate, State, TId>(streamNameMap, id, cancellationToken)
, it will assign the id. Same for LoadOrNew
.
@iappwebdev does the testing lib satisfy your need?
@alexeyzimarev Yes, indeed thank you for the testing lib. Only thing that sould be changed is the use of Id
instead of AggregateId
, as it is deprecated.
public static TAggregate CreateTestAggregateInstance<TAggregate, TState, TId>(this AggregateFactoryRegistry registry, TId id)
where TAggregate : Aggregate<TState> where TState : State<TState>, new() where TId : AggregateId // Use Id here
=> registry.CreateInstance<TAggregate>().WithId<TAggregate, TState, TId>(id);
You included the InMemoryEventStore, that's nice!
Hey,
I want to unit test in isolation my Aggregate inheriting from
Aggregate<T>
and havingState
andId
(located inEventuous.Domain
). I wanted to write a simply test of the aggregate separated from theCommandService
but could not instantiate an aggregate withState
andId
because the setter ofId
inState
is internal (what I unterstand). I looked in the source code and found the create method in theCommandService
located inEventuous.Application
project.It is using an
AggregateFactoryRegistry
to create aggregates. TheWithId()
extension is located in Eventuous.Persistence in AggregateStoreExtensions. The internals ofEventuous.Domain
are visible toEventuous.Persistence
. I thought I could use that and I tried to write a test:Unfortunatly,
WithId()
is internal. It works without usingWithId()
but then I get an exception later on when calling aggregate commands likeorder.RemoveArtikel(ArtikelName name)
.So my question is: how to instantiate an Aggregate with
State
andId
without having to mock the CommandService and the EventStore?