public async Task <TAggregate> GetAsync <TAggregate>(string id, int version) where TAggregate : class, IAggregate
        {
            if (version <= 0)
            {
                throw new InvalidOperationException("Cannot get version <= 0");
            }

            var  streamName      = id;
            Type aggregateType   = typeof(TAggregate);
            var  instanceOfState = AggregateStateFactory.CreateStateFor(aggregateType);

            long sliceStart = 0;
            StreamEventsSlice currentSlice;

            do
            {
                int sliceCount = (sliceStart + ReadPageSize <= version) ? ReadPageSize : (int)(version - sliceStart + 1);

                currentSlice = await EventStoreConnection.ReadStreamEventsForwardAsync(streamName, sliceStart, sliceCount, false);

                if (currentSlice.Status == SliceReadStatus.StreamNotFound)
                {
                    break;
                }

                if (currentSlice.Status == SliceReadStatus.StreamDeleted)
                {
                    break;
                }

                sliceStart = currentSlice.NextEventNumber;

                foreach (var evnt in currentSlice.Events)
                {
                    instanceOfState.Mutate(DeserializeEvent(evnt.OriginalEvent.Metadata, evnt.OriginalEvent.Data));
                    if (instanceOfState.Version == version)
                    {
                        return(Activator.CreateInstance(aggregateType, instanceOfState) as TAggregate);
                    }
                }
            } while (version >= currentSlice.NextEventNumber && !currentSlice.IsEndOfStream);

            if (instanceOfState.Version == 0)
            {
                return(null);
            }
            return(Activator.CreateInstance(aggregateType, instanceOfState) as TAggregate);
        }
        public void aggregate_state_factory_given_aggregate_creates_state()
        {
            var state = AggregateStateFactory.CreateStateFor(typeof(PersonAggregate));

            Assert.That(state is PersonAggregateState);
        }