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));
        }
        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 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);
            }
        }
        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 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 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 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 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 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 WriteComplexTest()
        {
            var graph = new ComplexGraph {Value = new Relation {Id = Guid.NewGuid(), Name = "Test", Description = "Binary", Value = 1}};
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(graph.Value.Id, actual.Value.Id);
            Assert.AreEqual(graph.Value.Name, actual.Value.Name);
            Assert.AreEqual(graph.Value.Description, actual.Value.Description);
            Assert.AreEqual(graph.Value.Value, actual.Value.Value);
        }
        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);
            }
        }
        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);
        }
        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);
        }
        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 WriteCollectionTest()
        {
            var graph = new CollectionGraph { Value = new List<string> { "Test" } };
            var context = new SerializationTestContext();
            var actual = context.SerializeAndDeserialize(graph);

            Assert.IsNotNull(actual.Value);
            Assert.AreEqual(1, actual.Value.Count);
            Assert.AreEqual("Test", actual.Value.First());
        }