Exemplo n.º 1
0
        public void Create_WithListOfEvents_ShouldReturnAggregate()
        {
            var events = GetEventDatas().OrderBy(e => e.Version).Select(x => x.DeserializeEvent());

            var aggregate = _aggregateRootFactory.CreateAsync <Investor>(events);

            aggregate.Should().NotBeNull();
            aggregate.Should().BeAssignableTo <Investor>();
        }
Exemplo n.º 2
0
        public async void GetByIdAsync_WithExistingInvestor_ShouldReturnInvestorAggregate()
        {
            var eventToReturn = GetEvents();

            _eventStore.GetFromAsync <Investor>(_aggregateId).ReturnsForAnyArgs(eventToReturn);

            Snapshot snapshot = null;

            _snapshotService.GetLastAsync(Arg.Any <Guid>()).ReturnsForAnyArgs(snapshot);

            _aggregateRootFactory
            .CreateAsync <Investor>(eventToReturn)
            .Returns(_investor);

            var aggregate = await _eventRepository.GetByIdAsync <Investor>(_aggregateId);

            aggregate.Should().Be(_investor);
            aggregate.Should().NotBeNull();
            _aggregateRootFactory.Received().CreateAsync <Investor>(eventToReturn);
        }
Exemplo n.º 3
0
        public async Task <T> GetByIdAsync <T>(Guid id)
        {
            if (id == Guid.Empty)
            {
                throw new StocqresException("Aggregate Id cannot be empty");
            }

            var snapshot = await _snapshotService.GetLastAsync(id);

            if (snapshot != null)
            {
                return(await RecreateAggregateFromSnapshot <T>(snapshot));
            }

            var events = await _eventStore.GetFromAsync <T>(id);

            if (events == null || !events.Any())
            {
                throw new StocqresException("Aggregate doesn't exist");
            }

            return((T)_factory.CreateAsync <T>(events));
        }