Exemplo n.º 1
0
 public void ReadCollectionOfComplexTest()
 {
     var context = new SerializationTestContext();
     var stats = context.AssertRead<CollectionOfComplexGraph>(4);
     stats.AssertVisitOrderExact(LevelType.Collection, LevelType.CollectionItem, LevelType.Value, LevelType.Value,
         LevelType.Value, LevelType.Value, LevelType.CollectionItem);
 }
Exemplo n.º 2
0
 public void ReadCollectionOfDictionaryTest()
 {
     var context = new SerializationTestContext();
     var stats = context.AssertRead<CollectionOfDictionaryGraph>(3);
     stats.AssertVisitOrderExact(LevelType.Collection, LevelType.DictionaryInCollection, LevelType.DictionaryKey,
         LevelType.DictionaryValue, LevelType.DictionaryKey, LevelType.DictionaryInCollection);
 }
Exemplo n.º 3
0
 public void WriteCollectionOfComplexTest()
 {
     var context = new SerializationTestContext();
     var stats = context.AssertWrite(4, new CollectionOfComplexGraph {
         Value = new List<Relation> {new Relation {Id = Guid.Empty, Name = "Test", Value = 1}}
     });
     stats.AssertVisitOrderExact(LevelType.Collection, LevelType.CollectionItem, LevelType.Value, LevelType.Value,
         LevelType.Value, LevelType.Value);
 }
        public void WriteBlobTest()
        {
            var graph = new BlobGraph {Value = new byte[] {1, 2, 3}};
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.IsTrue(graph.Value.SequenceEqual(actual.Value));
        }
Exemplo n.º 5
0
 public void WriteCollectionOfCollectionTest()
 {
     var context = new SerializationTestContext();
     var stats = context.AssertWrite(1, new CollectionOfCollectionGraph {
         Value = new List<List<string>> {
             new List<string> {"Test"}
         }
     });
     stats.AssertVisitOrderExact(LevelType.Collection, LevelType.CollectionInCollection, LevelType.CollectionItem);
 }
Exemplo n.º 6
0
 public void WriteCollectionOfDictionaryTest()
 {
     var context = new SerializationTestContext();
     var stats = context.AssertWrite(2, new CollectionOfDictionaryGraph {
         Value = new List<Dictionary<string, int>> {
             new Dictionary<string, int> {{"Test", 42}}
         }
     });
     stats.AssertVisitOrderExact(LevelType.Collection, LevelType.DictionaryInCollection, LevelType.DictionaryKey,
         LevelType.DictionaryValue);
 }
        public void IdentifierTest()
        {
            var graph = new Identifier { Id = 1, Type = ApplicationType.Api };

            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual);
            Assert.AreEqual(graph.Id, actual.Id);
            Assert.AreEqual(graph.Type, actual.Type);
        }
        public void WriteDynamicTravelTest()
        {
            var context = new SerializationTestContext();

            var bytes = context.Pack(DataBlock.Filled());
            Assert.IsNotNull(bytes);
            Assert.IsTrue(bytes.Length > 0);
            var hex = "0x" + string.Join("", bytes.Select(b => b.ToString("X")));
            Assert.IsNotNull(hex);
            var expected = SerializationTestContext.GetFilledDataBlockHexString();
            Assert.AreEqual(expected, hex);
        }
        public void WriteCollectionOfComplexTest()
        {
            var graph = new CollectionOfComplexGraph {
                Value = new List<Relation> { new Relation { Id = Guid.Empty, Name = "Test", Value = 1 } }
            };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(1, actual.Value.Count);

            for (var i = 0; i < graph.Value.Count; i++) {
                var expectedValue = graph.Value[i];
                var actualValue = actual.Value[i];
                Assert.AreEqual(expectedValue, actualValue);
            }
        }
Exemplo n.º 10
0
        protected void CheckInstanceIsSerializable <T> (
            T instance, Action <T, SerializationTestContext <T> > assertions = null, string expectedStringFieldValue = null)
        {
            Assert.That(instance.GetType().IsSerializable, Is.True);

            var context =
                new SerializationTestContext <T>
            {
                SerializedData = Serializer.Serialize(instance),
                Assertions     = assertions,
                ExpectedAssemblyQualifiedName = instance.GetType().AssemblyQualifiedName,
                SerializedTypeFullName        = instance.GetType().FullName,
                ExpectedStringFieldValue      = expectedStringFieldValue
            };

            context.DeserializationCallback = CreateDeserializationCallback(context);

            _appDomainForDeserialization.DoCallBack(context.AppDomainDelegate);
        }
        public void WriteAndReadNullableValuesTest()
        {
            var graph = new NullableValuesEntity {
                Id = 1,
                MayBool = null,
                MayDateTime = null,
                MayInt = 44,
                MayTimeSpan = new TimeSpan(22, 30, 10)
            };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Id);
            Assert.IsNull(actual.MayBool);
            Assert.IsNull(actual.MayDateTime);
            Assert.AreEqual(44, actual.MayInt);
            Assert.AreEqual(new TimeSpan(22, 30, 10), actual.MayTimeSpan);
        }
        public void ValueDictionaryTest()
        {
            var graph = new ValueDictionary {
                Test = new Dictionary<string, int> {
                    {"Test1", 1},
                    {"Test2", 2},
                    {"Test3", 3},
                }
            };

            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Test);
            Assert.AreEqual(3, actual.Test.Count);

            Assert.IsTrue(graph.Test.SequenceEqual(actual.Test, new ValueDictionaryComparer()));
        }
        public void ComplexDictionaryTest()
        {
            var graph = new ComplexDictionary {
                Test = new Dictionary<Identifier, Category> {
                    {new Identifier {Id = 1, Type = ApplicationType.Api}, new Category {Name = "Warning", Description = "Warning of something", Image = new byte[]{1, 2, 3, 4, 5}}},
                    {new Identifier {Id = 2, Type = ApplicationType.Api}, new Category {Name = "Error", Description = "Error of something", Image = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}}},
                    {new Identifier {Id = 3, Type = ApplicationType.Service}, new Category {Name = "Temporary"}}
                }
            };

            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Test);
            Assert.AreEqual(3, actual.Test.Count);

            Assert.IsTrue(graph.Test.Keys.SequenceEqual(actual.Test.Keys));
            Assert.IsTrue(graph.Test.Values.SequenceEqual(actual.Test.Values));
        }
        public void WriteCollectionOfCollectionTest()
        {
            var graph = new CollectionOfCollectionGraph {
                Value = new List<List<string>> {
                    new List<string> {"Test"}
                }
            };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(1, actual.Value.Count);

            for (var i = 0; i < graph.Value.Count; i++) {
                var expectedValue = graph.Value[i];
                var actualValue = actual.Value[i];
                Assert.AreEqual(1, actualValue.Count);

                var firstExpected = expectedValue.First();
                var firstActual = actualValue.First();

                Assert.AreEqual(firstExpected, firstActual);
            }
        }
 public void WriteUInt64Test()
 {
     var context = new SerializationTestContext();
     context.AssertBinarySingleProperty(new UInt64Graph { Value = 42 });
 }
 public void WriteTimeSpanTest()
 {
     var context = new SerializationTestContext();
     context.AssertBinarySingleProperty(new TimeSpanGraph { Value = new TimeSpan(12, 30, 00) });
 }
 public void WriteStringTest()
 {
     var context = new SerializationTestContext();
     context.AssertBinarySingleProperty(new StringGraph { Value = "Hello World" });
 }
        public void WriteDictionaryWithCollectionKeyTest()
        {
            var graph = new DictionaryWithCollectionKeyGraph {
                Value = new Dictionary<List<int>, string> {
                    {new List<int> {42}, "Hello World"}
                }
            };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(1, actual.Value.Count);

            var firstExpected = graph.Value.First();
            var firstActual = actual.Value.First();

            Assert.AreEqual(1, firstActual.Key.Count);
            var firstInnerExpectedKey = firstExpected.Key.First();
            var firstInnerActualKey = firstActual.Key.First();

            Assert.AreEqual(firstInnerExpectedKey, firstInnerActualKey);

            Assert.AreEqual(firstExpected.Value, firstActual.Value);
        }
Exemplo n.º 19
0
 protected abstract Func <SerializationTestContext <T>, T> CreateDeserializationCallback <T> (SerializationTestContext <T> context);
 public void WriteEnumTest()
 {
     var context = new SerializationTestContext();
     context.AssertBinarySingleProperty(new EnumGraph { Value = ApplicationType.Api });
 }
 public void WriteDecimalTest()
 {
     var context = new SerializationTestContext();
     context.AssertBinarySingleProperty(new DecimalGraph { Value = 42.74343M });
 }
 public void WriteBooleanTest()
 {
     var context = new SerializationTestContext();
     context.AssertBinarySingleProperty(new BooleanGraph { Value = true });
 }
        public void WriteDictionaryWithComplexValueTest()
        {
            var graph = new DictionaryWithComplexValueGraph {
                Value = new Dictionary<string, Category> {
                    {"A", new Category {
                        Name = "Warning",
                        Description = "Warning of something",
                        Image = new byte[] {1, 2, 3, 4, 5}
                    }}, {"B", new Category {
                        Name = "Error",
                        Description = "Error of something",
                        Image = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9}
                    }}, {"C", new Category {Name = "Temporary"}}
                }
            };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(3, actual.Value.Count);

            foreach (var kv in graph.Value) {
                var actualValue = actual.Value[kv.Key];
                Assert.AreEqual(kv.Value, actualValue);
            }
        }
        public void WriteDictionaryWithComplexKeyTest()
        {
            var graph = new DictionaryWithComplexKeyGraph {
                Value = new Dictionary<Identifier, string> {
                    {new Identifier {Id = 1, Type = ApplicationType.Api}, "A"},
                    {new Identifier {Id = 2, Type = ApplicationType.Api}, "B"},
                    {new Identifier {Id = 3, Type = ApplicationType.Service}, "C"}
                }
            };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(3, actual.Value.Count);

            foreach (var kv in graph.Value) {
                var actualValue = actual.Value[kv.Key];
                Assert.AreEqual(kv.Value, actualValue);
            }
        }
        public void WriteDictionaryWithComplexKeyAndValueTest()
        {
            var graph = new DictionaryWithComplexKeyAndValueGraph {
                Value = new Dictionary<Identifier, Category> {
                    {new Identifier {Id = 1, Type = ApplicationType.Api}, new Category {Name = "Warning", Description = "Warning of something", Image = new byte[]{1, 2, 3, 4, 5}}},
                    {new Identifier {Id = 2, Type = ApplicationType.Api}, new Category {Name = "Error", Description = "Error of something", Image = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}}},
                    {new Identifier {Id = 3, Type = ApplicationType.Service}, new Category {Name = "Temporary"}}
                }
            };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(3, actual.Value.Count);

            foreach (var kv in graph.Value) {
                var actualValue = actual.Value[kv.Key];
                Assert.AreEqual(kv.Value, actualValue);
            }
        }
Exemplo n.º 26
0
        protected override Func <SerializationTestContext <T>, T> CreateDeserializationCallback <T> (SerializationTestContext <T> context)
        {
            // Do not flush generated assembly to disk to force complex serialization strategy.

            context.ParticipantProviders = _participantProviders;
            return(ctx =>
            {
                var deserializedInstance = (T)DeserializeInstance(ctx.ParticipantProviders, ctx.SerializedData);

                // The assembly name must be different, i.e. the new app domain should use an in-memory assembly.
                var type = deserializedInstance.GetType();
                Assert.That(type.AssemblyQualifiedName, Is.Not.EqualTo(ctx.ExpectedAssemblyQualifiedName));
                Assert.That(type.Assembly.GetName().Name, Is.StringStarting("TypePipe_GeneratedAssembly_"));
                Assert.That(type.Module.Name, Is.EqualTo("<In Memory Module>"));

                // The generated type is always the single type in the assembly. Its name is therefore the same as the serialized type name, but with
                // "Proxy1" in the end.
                var expectedFullName = Regex.Replace(ctx.SerializedTypeFullName, @"Proxy_\d+$", "Proxy_1");
                Assert.That(type.FullName, Is.EqualTo(expectedFullName));

                return deserializedInstance;
            });
        }
        public void WriteCollectionOfDictionaryTest()
        {
            var graph = new CollectionOfDictionaryGraph {
                Value = new List<Dictionary<string, int>> {
                    new Dictionary<string, int> {{"Test", 42}}
                }
            };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(1, actual.Value.Count);

            for (var i = 0; i < graph.Value.Count; i++) {
                var expectedValue = graph.Value[i];
                var actualValue = actual.Value[i];
                Assert.AreEqual(1, actualValue.Count);

                var firstExpected = expectedValue.First();
                var firstActual = actualValue.First();

                Assert.AreEqual(firstExpected.Key, firstActual.Key);
                Assert.AreEqual(firstExpected.Value, firstActual.Value);
            }
        }
 public void WriteGuidTest()
 {
     var context = new SerializationTestContext();
     context.AssertBinarySingleProperty(new GuidGraph { Value = Guid.NewGuid() });
 }
Exemplo n.º 29
0
        protected override Func <SerializationTestContext <T>, T> CreateDeserializationCallback <T> (SerializationTestContext <T> context)
        {
            // Flush generated assembly to disk to enable simple serialization strategy.
            Flush();

            return(ctx =>
            {
                var deserializedInstance = (T)Serializer.Deserialize(ctx.SerializedData);
                Assert.That(deserializedInstance.GetType().AssemblyQualifiedName, Is.EqualTo(ctx.ExpectedAssemblyQualifiedName));

                return deserializedInstance;
            });
        }
        public void WriteJaggedArrayTest()
        {
            var graph = new JaggedArrayGraph {
                Value = new[] { new[] { 5, 2, 3 }, new[] { 1, 2, 3 } }
            };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(graph.Value.Length, actual.Value.Length);

            for (var r0 = 0; r0 < graph.Value.Length; r0++) {
                var expectedInner = graph.Value[r0];
                var actualInner = graph.Value[r0];
                Assert.AreEqual(expectedInner.Length, actualInner.Length);
                for (var r1 = 0; r1 < expectedInner.Length; r1++) {
                    var expectedValue = expectedInner[r1];
                    var actualValue = actualInner[r1];

                    Assert.AreEqual(expectedValue, actualValue);
                }
            }
        }
        public void WriteMultidimensionalArrayTest()
        {
            var graph = new MultidimensionalArrayGraph {
                Value = new[,] { { 5, 2, 3 }, { 1, 2, 3 } }
            };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(6, actual.Value.Length);
            Assert.AreEqual(2, actual.Value.GetLength(0));
            Assert.AreEqual(3, actual.Value.GetLength(1));

            for (var r0 = 0; r0 < graph.Value.GetLength(0); r0++) {
                for (var r1 = 0; r1 < graph.Value.GetLength(1); r1++) {
                    var expectedValue = graph.Value[r0, r1];
                    var actualValue = actual.Value[r0, r1];

                    Assert.AreEqual(expectedValue, actualValue);
                }
            }
        }
 public void WriteSingleTest()
 {
     var context = new SerializationTestContext();
     context.AssertBinarySingleProperty(new SingleGraph { Value = 42.3f });
 }
        public void WriteDictionaryWithDictionaryValueTest()
        {
            var graph = new DictionaryWithDictionaryValueGraph {
                Value = new Dictionary<string, Dictionary<int, string>> {
                    {"X", new Dictionary<int, string> {{42, "No 42"}}}
                }
            };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(1, actual.Value.Count);

            var firstExpected = graph.Value.First();
            var firstActual = actual.Value.First();

            Assert.AreEqual(firstExpected.Key, firstActual.Key);

            Assert.AreEqual(1, firstActual.Value.Count);
            var firstInnerExpected = firstExpected.Value.First();
            var firstInnerActual = firstActual.Value.First();

            Assert.AreEqual(firstInnerExpected.Key, firstInnerActual.Key);
            Assert.AreEqual(firstInnerExpected.Value, firstInnerActual.Value);
        }
        public void WriteDictionaryTest()
        {
            var graph = new DictionaryGraph {Value = new Dictionary<int, string> {{2, "Test"}}};
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(1, actual.Value.Count);

            var firstActual = actual.Value.First();
            Assert.AreEqual(2, firstActual.Key);
            Assert.AreEqual("Test", firstActual.Value);
        }