public void TestThatStatefulEntityPreservesRestores()
        {
            RaceConditions.Set(0);

            var entityId = $"{_idGenerator.Next(10_000)}";
            var state    = new Entity1State(entityId, "Sally", 23);

            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);

            // check whether race conditions have been reproduced
            Assert.Equal(0, RaceConditions.Get());
        }
Esempio n. 2
0
        public void TestThatMetadataCallbackPreservesRestores()
        {
            var entityId = $"{_idGenerator.Next(10_000)}";
            var state    = new Entity1State(entityId, "Sally", 23);
            var access   = _dispatcher.AfterCompleting(3);

            var entity1 = _world.ActorFor <IEntity1>(() => new Entity1MetadataCallbackActor(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 Entity1MetadataCallbackActor(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);
            });
        }
 public bool Equals(Entity1State other) => Id == other.Id && Name == other.Name && Age == other.Age;