/// <inheritdoc />
        public QueryMultiResults QueryAll(QueryExpression expression)
        {
            // NOTE: No query constraints accepted; selects all stored objects

            var all   = new List <StateObject>();
            var store = _stores.ComputeIfAbsent(expression.Type, type => new Dictionary <long, TState>());

            foreach (var entry in store.Values)
            {
                var stateObject = _stateAdapterProvider.FromRaw <StateObject, TState>(entry);
                all.Add(stateObject);
            }

            return(new QueryMultiResults(all));
        }
Esempio n. 2
0
        public void TestThatStatefulEntityPreservesRestores()
        {
            var entityId = $"{_idGenerator.Next(10_000)}";
            var state    = new Entity1State(entityId, "Sally", 23);
            var access   = _dispatcher.AfterCompleting(3);

            var entity1 = _world.ActorFor <IEntity1>(() => new Entity1Actor(RaceConditions, entityId));

            Assert.Equal(state, entity1.DefineWith(state.Name, state.Age).Await());
            Assert.Equal(state, entity1.Current().Await());

            entity1.ChangeName("Sally Jane");
            var newState = entity1.Current().Await();

            Assert.Equal("Sally Jane", newState.Name);

            entity1.IncreaseAge();
            newState = entity1.Current().Await();
            Assert.Equal(24, newState.Age);

            var restoredEntity1      = _world.ActorFor <IEntity1>(() => new Entity1Actor(RaceConditions, entityId));
            var restoredEntity1State = restoredEntity1.Current().Await();

            Assert.NotNull(restoredEntity1State);

            Assert.Equal(1, access.ReadFrom <int>("dispatchedStateCount"));
            var ids = access.ReadFrom <IEnumerable <string> >("dispatchedIds").ToList();

            Assert.Single(ids);

            var flatState = access.ReadFrom <string, TextState>("dispatchedState", ids[0]);

            Assert.Equal(new Entity1State(entityId, "Sally Jane", 24), _stateAdapterProvider.FromRaw <Entity1State, TextState>(flatState));

            restoredEntity1.Current().AndThenConsume(current => {
                Assert.Equal(new Entity1State(entityId, "Sally Jane", 24), current);
            });
        }