Пример #1
0
        // ReSharper disable UnusedMember.Local
        void RunSerializationRoundtripTestWith <TAggregateRoot>() where TAggregateRoot : AggregateRoot, new()
        {
            var instance = new TAggregateRoot {
                Id = "root_id"
            };

            Console.WriteLine(instance.GetHashCode());

            var firstSerialization        = _sturdylizer.SerializeObject(instance);
            var roundtrippedSerialization = _sturdylizer.SerializeObject(_sturdylizer.DeserializeObject(firstSerialization));

            if (firstSerialization != roundtrippedSerialization)
            {
                throw new AssertionException(string.Format(@"Oh noes!!

{0}

{1}", firstSerialization, roundtrippedSerialization));
            }
        }
        // ReSharper disable UnusedMember.Local
        void RunHashCodeTestWith <TAggregateRoot>() where TAggregateRoot : AggregateRoot, new()
        {
            var instance = new TAggregateRoot {
                Id = "root_id", GlobalSequenceNumberCutoff = 0
            };

            var cache = new InMemorySnapshotCache();

            cache.PutCloneToCache(instance);

            var rootInfo = cache.GetCloneFromCache("root_id", 0);

            Assert.That(rootInfo, Is.Not.Null, "Expected to have found a root in the cache!");

            var frozenInstance = rootInfo;

            cache.PutCloneToCache(frozenInstance);

            Assert.That(frozenInstance.GetHashCode(), Is.EqualTo(instance.GetHashCode()));
        }