private async Task <EventStoreStreamActor> CreateActor(IActorStateManager actorStateManager, string id)
        {
            var actorTypeInformation = ActorTypeInformation.Get(typeof(EventStoreStreamActor));

            EventStoreStreamActor actorFactory(ActorService service, ActorId id) =>
            new EventStoreStreamActor(service, id, actorStateManager);

            var actorService                 = new ActorService(actorTypeInformation, actorFactory);
            EventStoreStreamActor actor      = actorFactory(actorService, new ActorId(id));
            MethodInfo            OnActivate = actor.GetType().GetMethod("OnActivateAsync", BindingFlags.NonPublic | BindingFlags.Instance);

            await(Task) OnActivate.Invoke(actor, Array.Empty <object>());
            return(actor);
        }
        public async Task EventStoreStreamActor_Read_ExpectGetStateAsync()
        {
            var stateManager = new Mock <IActorStateManager>();

            FakeEvent[] events = new[] { new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent() };
            var         state  = new EventStoreStreamState();

            state.Append(events);
            stateManager.Setup(manager => manager.GetStateAsync <EventStoreStreamState>(_stateName, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(state))
            .Verifiable();
            EventStoreStreamActor testDemoActor = await CreateActor(stateManager.Object, EventStoreStreamActor.CreateStreamId(events[0].AggregateType, events[0].AggregateId));

            IList <IEvent> result = await testDemoActor.Read();

            CheckValues(state.Read(), result);

            stateManager.VerifyAll();
        }
        public async Task EventStoreStreamActor_ReadAfterFive_ExpectFiveAfterEvents()
        {
            var stateManager = new Mock <IActorStateManager>();

            FakeEvent[] testEvents1 = new[] { new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent() };
            FakeEvent[] testEvents2 = new[] { new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent(), new FakeEvent() };
            var         state       = new EventStoreStreamState();

            state.Append(testEvents1);
            state.Append(testEvents2);
            stateManager.Setup(manager => manager.GetStateAsync <EventStoreStreamState>(_stateName, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(state))
            .Verifiable();

            EventStoreStreamActor testDemoActor = await CreateActor(stateManager.Object, EventStoreStreamActor.CreateStreamId(testEvents1[0].AggregateType, testEvents1[0].AggregateId));

            IList <IEvent> result = await testDemoActor.Read(testEvents1.Last().Id, 5);

            CheckValues(testEvents2.Take(5).ToList <IEvent>(), result);
        }