Example #1
0
        public void SerializeAndDeserializeStateWorksDetectsCircularDependencyOnDeserialization()
        {
            var storageEngine       = new InMemoryStorageEngine();
            var roots               = new Roots2();
            var serializerFactories = SerializerFactories.Default;
            var mps = new MapAndSerializers(serializerFactories);

            mps.GetOrCreateSerializerFor(roots);

            var p1 = new Person {
                Name = "Peter"
            };
            var p2 = new Person {
                Name = "Ole"
            };

            p1.Sibling = p2;
            p2.Sibling = p1;

            roots.Entangle(p1);

            var persister = new Persister2(storageEngine, mps);

            persister.DetectAndPersistChanges();

            try
            {
                Deserializer2.Load(storageEngine, new Ephemerals(), serializerFactories);
            }
            catch (CircularDependencyException2 e)
            {
                e.CircularPath.Count().ShouldBe(3);
            }
        }
Example #2
0
        public void SerializeAndDeserializeStateWorksDetectsNonCircularDependencyOnDeserialization()
        {
            var storageEngine       = new InMemoryStorageEngine();
            var roots               = new Roots2();
            var serializerFactories = SerializerFactories.Default;
            var mps = new MapAndSerializers(serializerFactories);

            mps.GetOrCreateSerializerFor(roots);

            var p1 = new Person {
                Name = "Peter"
            };
            var p2 = new Person {
                Name = "Ole"
            };

            p1.Sibling = p2;

            roots.Entangle(p1);

            var persister = new Persister2(storageEngine, mps);

            persister.DetectAndPersistChanges();

            var(r, _) = Deserializer2.Load(storageEngine, new Ephemerals(), serializerFactories);
            var p = r.Find <Person>();

            p.Name.ShouldBe("Peter");
            p.Sibling.Name.ShouldBe("Ole");
        }
        public void SerializeAndDeserializeStateWorksInSimpleCase()
        {
            var storageEngine       = new InMemoryStorageEngine();
            var roots               = new Roots2();
            var serializerFactories = SerializerFactories.Default;
            var mps = new MapAndSerializers(serializerFactories);

            mps.GetOrCreateSerializerFor(roots);

            roots.Entangle(new Person {
                Name = "Peter"
            });

            var persister = new Persister2(storageEngine, mps);

            persister.DetectAndPersistChanges();

            var deserializedState = Deserializer2.Load(storageEngine, new Ephemerals(), serializerFactories);

            var deserializedPerson = deserializedState.Roots.Find <Person>();

            deserializedPerson.Name.ShouldBe("Peter");
            deserializedPerson.Relationship.ShouldBeNull();
        }