public async Task <TAggregate> Read <TAggregate>(Guid id) where TAggregate : IAggregate, new() { var aggregate = new TAggregate(); var stream = $"{aggregate.StreamName}.{id}"; var events = await streamLoader.LoadEvents(stream, selector.For(typeof(TAggregate))); aggregate.LoadHistory(events); return(aggregate); }
public async void ItReturnsAnAggregate(Guid id, string stream) { var map = new EmployeeTypeMap(); A.CallTo(() => selector.For(typeof(Employee))) .Returns(map); var events = A.CollectionOfDummy <EmployeeHired>(1); A.CallTo(() => loader.LoadEvents( stream, map)) .Returns(events); var employee = await sut.Read <Employee>(id); employee.Should().NotBeNull(); employee.Version.Should().Be(1); }
public async void ItLoadsEventsFromTheStream() { var loaded = new List <EventFromStream>(); loaded.AddRange(A.CollectionOfDummy <LoadedEvent>(5)); loaded.Add(A.Dummy <NoEventFound>()); const string stream = "stream"; var typeMap = new TypeMap(); A.CallTo(() => proxy.ReadEventAsync(connection, stream, A <long> ._)) .ReturnsNextFromSequence(loaded.ToArray()); await sut.LoadEvents(stream, typeMap); A.CallTo(() => connection.ConnectAsync()).MustHaveHappened() .Then(A.CallTo(() => connection.Close()).MustHaveHappened()); A.CallTo(() => converter.ConvertReadToDomain(typeMap, A <LoadedEvent> ._)) .MustHaveHappened(); }