Esempio n. 1
0
            public void BinarySerializationComplexGraphWithInheritance()
            {
                var originalObject = ModelBaseTestHelper.CreateHierarchicalGraphWithInheritance();
                var clonedObject   = SerializationTestHelper.SerializeAndDeserialize(originalObject, SerializationFactory.GetBinarySerializer());

                Assert.AreEqual(originalObject, clonedObject);
            }
Esempio n. 2
0
            public void CanSerializeCollection()
            {
                var countrylist = new List <Country>();

                countrylist.Add(new Country {
                    IsoCode = "AF", Description = "Afghanistan"
                });
                countrylist.Add(new Country {
                    IsoCode = "AG", Description = "Agypt"
                });

                TestSerializationOnAllSerializers((serializer, config, description) =>
                {
                    var deserializedObject = SerializationTestHelper.SerializeAndDeserialize(countrylist, serializer, config);

                    Assert.AreEqual(countrylist.Count, deserializedObject.Count, description);

                    for (int i = 0; i < deserializedObject.Count; i++)
                    {
                        var expectedItem = countrylist[i];
                        var actualItem   = deserializedObject[i];

                        Assert.AreEqual(expectedItem.IsoCode, actualItem.IsoCode, description);
                        Assert.AreEqual(expectedItem.Description, actualItem.Description, description);
                    }
                });
            }
Esempio n. 3
0
            public void BinarySerializationLevel3()
            {
                var originalObject = ModelBaseTestHelper.CreateComputerSettingsObject();
                var clonedObject   = SerializationTestHelper.SerializeAndDeserialize(originalObject, SerializationFactory.GetBinarySerializer());

                Assert.AreEqual(originalObject, clonedObject);
            }
Esempio n. 4
0
            public void CanSerializeCustomDataObject()
            {
                var countrylist = new List <Country>();

                countrylist.Add(new Country {
                    IsoCode = "AF", Description = "Afghanistan"
                });
                countrylist.Add(new Country {
                    IsoCode = "AG", Description = "Agypt"
                });

                var dataSourceResult = new DataSourceResult();

                dataSourceResult.Total = 243;
                dataSourceResult.Data  = countrylist;

                TestSerializationOnAllSerializers((serializer, config, description) =>
                {
                    var deserializedObject = SerializationTestHelper.SerializeAndDeserialize(dataSourceResult, serializer, config);

                    Assert.AreEqual(243, deserializedObject.Total, description);

                    int counter = 0;
                    foreach (var country in dataSourceResult.Data)
                    {
                        var existingCountry = countrylist[counter++];

                        Assert.AreEqual(existingCountry.IsoCode, ((Country)country).IsoCode, description);
                        Assert.AreEqual(existingCountry.Description, ((Country)country).Description, description);
                    }
                });
            }
Esempio n. 5
0
            public void CanSerializeArray()
            {
                var countrylist = new[]
                {
                    new Country {
                        IsoCode = "AF", Description = "Afghanistan"
                    },
                    new Country {
                        IsoCode = "AG", Description = "Agypt"
                    },
                };

                TestSerializationOnAllSerializers((serializer, config, description) =>
                {
                    var deserializedObject = SerializationTestHelper.SerializeAndDeserialize(countrylist, serializer, config);

                    Assert.AreEqual(countrylist.GetType(), deserializedObject.GetType(), description);
                    Assert.AreEqual(countrylist.Length, deserializedObject.Length, description);

                    for (var i = 0; i < deserializedObject.Length; i++)
                    {
                        var expectedItem = countrylist[i];
                        var actualItem   = deserializedObject[i];

                        Assert.AreEqual(expectedItem.IsoCode, actualItem.IsoCode, description);
                        Assert.AreEqual(expectedItem.Description, actualItem.Description, description);
                    }
                });
            }
Esempio n. 6
0
            public void CorrectlySerializesCustomizedModels()
            {
                var testModel = new TestModel();

                testModel._excludedField = "excluded";
                testModel._includedField = "included";

                testModel.ExcludedRegularProperty = "excluded";
                testModel.IncludedRegularProperty = "included";

                testModel.ExcludedCatelProperty = "excluded";
                testModel.IncludedCatelProperty = "included";

                testModel.SetValue(TestModel.ExcludedProtectedCatelPropertyProperty, "excluded");

                TestSerializationOnAllSerializers((serializer, description) =>
                {
                    var clonedModel = SerializationTestHelper.SerializeAndDeserialize(testModel, serializer);

                    Assert.AreEqual(null, clonedModel._excludedField, description);
                    Assert.AreEqual("included", clonedModel._includedField, description);

                    Assert.AreEqual(null, clonedModel.ExcludedRegularProperty, description);
                    Assert.AreEqual("included", clonedModel.IncludedRegularProperty, description);

                    Assert.AreEqual(null, clonedModel.ExcludedCatelProperty, description);
                    Assert.AreEqual("included", clonedModel.IncludedCatelProperty, description);

                    Assert.AreEqual(null, clonedModel.GetValue(TestModel.ExcludedProtectedCatelPropertyProperty.Name), description);
                });
            }
Esempio n. 7
0
            public void RespectsTheXmlAttributeAttributeOnRootElements(XmlSerializerOptimalizationMode mode)
            {
                var family = new XmlFamily();

                family.LastName = "van Horrik";
                family.Persons.Add(new XmlPerson
                {
                    FirstName = "Geert",
                    LastName  = family.LastName,
                    Gender    = Gender.Male
                });

                var newFamily = SerializationTestHelper.SerializeAndDeserialize(family, SerializationTestHelper.GetXmlSerializer(),
                                                                                new XmlSerializationConfiguration
                {
                    OptimalizationMode = mode
                });

                Assert.AreEqual(family.LastName, newFamily.LastName);
                Assert.AreEqual(1, newFamily.Persons.Count);

                var newPerson = newFamily.Persons.First();

                Assert.AreEqual(family.Persons[0].FirstName, newPerson.FirstName);
                Assert.AreEqual(family.Persons[0].LastName, newPerson.LastName);
                Assert.AreEqual(family.Persons[0].Gender, newPerson.Gender);
            }
Esempio n. 8
0
            public void XmlSerializationWithXmlMappings()
            {
                var originalObject = ModelBaseTestHelper.CreateComputerSettingsWithXmlMappingsObject();
                var clonedObject   = SerializationTestHelper.SerializeAndDeserialize(originalObject, SerializationFactory.GetXmlSerializer());

                Assert.AreEqual(originalObject, clonedObject);
            }
Esempio n. 9
0
            public void XmlSerializationLevel2()
            {
                var originalObject = ModelBaseTestHelper.CreateIniFileObject();
                var clonedObject   = SerializationTestHelper.SerializeAndDeserialize(originalObject, SerializationFactory.GetXmlSerializer());

                Assert.AreEqual(originalObject, clonedObject);
            }
Esempio n. 10
0
            public void CorrectlySerializesObjectsImplementingICustomXmlSerializable_Nested()
            {
                var serviceLocator = ServiceLocator.Default;
                var serializer     = serviceLocator.ResolveType <IXmlSerializer>();

                var model = new CustomXmlSerializationModelWithNesting
                {
                    Name        = "Test model with nesting",
                    NestedModel = new CustomXmlSerializationModel
                    {
                        FirstName = "Geert"
                    }
                };

                var clonedModel = SerializationTestHelper.SerializeAndDeserialize(model, serializer, null);

                Assert.IsNotNull(clonedModel.NestedModel);

                // Note: yes, the *model* is serialized, the *clonedModel* is deserialized
                Assert.IsTrue(model.NestedModel.IsCustomSerialized);
                Assert.IsTrue(clonedModel.NestedModel.IsCustomDeserialized);

                Assert.AreEqual(model.Name, clonedModel.Name);
                Assert.AreEqual(model.NestedModel.FirstName, clonedModel.NestedModel.FirstName);
            }
Esempio n. 11
0
            public void CorrectlySerializesCustomizedModels()
            {
                var testModel = new TestModel();

                testModel._excludedField = "excluded";
                testModel._includedField = "included";

                testModel.ExcludedRegularProperty = "excluded";
                testModel.IncludedRegularProperty = "included";

                testModel.ExcludedCatelProperty = "excluded";
                testModel.IncludedCatelProperty = "included";

                testModel.SetValue(TestModel.ExcludedProtectedCatelPropertyProperty, "excluded");

                var clonedModel = SerializationTestHelper.SerializeAndDeserialize(testModel, SerializationFactory.GetXmlSerializer());

                Assert.AreEqual(null, clonedModel._excludedField);
                Assert.AreEqual("included", clonedModel._includedField);

                Assert.AreEqual(null, clonedModel.ExcludedRegularProperty);
                Assert.AreEqual("included", clonedModel.IncludedRegularProperty);

                Assert.AreEqual(null, clonedModel.ExcludedCatelProperty);
                Assert.AreEqual("included", clonedModel.IncludedCatelProperty);

                Assert.AreEqual(null, clonedModel.GetValue(TestModel.ExcludedProtectedCatelPropertyProperty.Name));
            }
Esempio n. 12
0
            public void CanSerializeAndDeserializeComplexHierarchies()
            {
                var complexHierarchy = ComplexSerializationHierarchy.CreateComplexHierarchy();

                var deserializedObject = SerializationTestHelper.SerializeAndDeserialize(complexHierarchy, SerializationFactory.GetXmlSerializer());

                Assert.IsTrue(complexHierarchy == deserializedObject);
            }
Esempio n. 13
0
            public void CanSerializeBasicTypes <T>(T value)
            {
                TestSerializationOnAllSerializers((serializer, config, description) =>
                {
                    var deserializedObject = SerializationTestHelper.SerializeAndDeserialize(value, serializer, config);

                    Assert.AreEqual(value, deserializedObject);
                });
            }
Esempio n. 14
0
            public void CorrectlyHandlesSameInstancesInGraph()
            {
                var graph = SerializationTestHelper.CreateComplexCircularTestModelGraph();

                var clonedGraph = SerializationTestHelper.SerializeAndDeserialize(graph, SerializationFactory.GetBinarySerializer());

                Assert.IsNotNull(clonedGraph);
                Assert.IsTrue(ReferenceEquals(clonedGraph, clonedGraph.CircularModel.CircularModel));
            }
Esempio n. 15
0
            public void XmlSerializationWithPrivateMembers()
            {
                var originalObject = new ObjectWithPrivateMembers("My private member");

                originalObject.PublicMember = "My public member";

                var clonedObject = SerializationTestHelper.SerializeAndDeserialize(originalObject, SerializationFactory.GetXmlSerializer());

                Assert.AreEqual(originalObject, clonedObject);
            }
            public void MembersIgnoredViaModifier()
            {
                var modelC = new TestModels.ModelC();

                modelC.IgnoredMember = "test is a value";

                var clonedModelC = SerializationTestHelper.SerializeAndDeserialize(modelC, SerializationFactory.GetXmlSerializer());

                Assert.AreEqual(null, clonedModelC.IgnoredMember);
            }
Esempio n. 17
0
            public void SerializationLevel3()
            {
                var originalObject = ModelBaseTestHelper.CreateComputerSettingsObject();

                TestSerializationOnAllSerializers((serializer, description) =>
                {
                    var clonedObject = SerializationTestHelper.SerializeAndDeserialize(originalObject, serializer);

                    Assert.AreEqual(originalObject, clonedObject, description);
                });
            }
Esempio n. 18
0
            public void SerializationComplexGraphWithInheritance()
            {
                var originalObject = ModelBaseTestHelper.CreateHierarchicalGraphWithInheritance();

                TestSerializationOnAllSerializers((serializer, description) =>
                {
                    var clonedObject = SerializationTestHelper.SerializeAndDeserialize(originalObject, serializer);

                    Assert.AreEqual(originalObject, clonedObject, description);
                }, false);
            }
            public void SerializationLevel2()
            {
                var originalObject = ModelBaseTestHelper.CreateIniFileObject();

                TestSerializationOnAllSerializers((serializer, config, description) =>
                {
                    var clonedObject = SerializationTestHelper.SerializeAndDeserialize(originalObject, serializer, config);

                    Assert.AreEqual(originalObject, clonedObject, description);
                });
            }
Esempio n. 20
0
            public void CanSerializeAndDeserializeComplexHierarchies()
            {
                var complexHierarchy = ComplexSerializationHierarchy.CreateComplexHierarchy();

                TestSerializationOnAllSerializers((serializer, description) =>
                {
                    var deserializedObject = SerializationTestHelper.SerializeAndDeserialize(complexHierarchy, serializer);

                    Assert.IsTrue(complexHierarchy == deserializedObject, description);
                });
            }
Esempio n. 21
0
            public void SerializesAndDeserializesKeyValuePairs()
            {
                var originalObject = new TestModelWithKeyValuePair();

                TestSerializationOnAllSerializers((serializer, description) =>
                {
                    var clonedObject = SerializationTestHelper.SerializeAndDeserialize(originalObject, serializer);

                    Assert.AreEqual(originalObject.KeyValuePair, clonedObject.KeyValuePair, description);
                    Assert.AreEqual(originalObject.KeyValuePairAsObject, clonedObject.KeyValuePairAsObject, description);
                });
            }
Esempio n. 22
0
            public void CorrectlyHandlesSameInstancesInGraph()
            {
                var graph = SerializationTestHelper.CreateComplexCircularTestModelGraph();

                TestSerializationOnAllSerializers((serializer, description) =>
                {
                    var clonedGraph = SerializationTestHelper.SerializeAndDeserialize(graph, serializer);

                    Assert.IsNotNull(clonedGraph, description);
                    Assert.IsTrue(ReferenceEquals(clonedGraph, clonedGraph.CircularModel.CircularModel), description);
                }, false);
            }
Esempio n. 23
0
            public void CorrectlyHandlesSerializationOfCollectionsWithAbstractClasses()
            {
                var collection = new ContainerClass();

                collection.Items.Add(new DerivedClass {
                    Name = "item 1"
                });

                var clonedGraph = SerializationTestHelper.SerializeAndDeserialize(collection, SerializationFactory.GetXmlSerializer());

                Assert.AreEqual(collection, clonedGraph);
            }
Esempio n. 24
0
            public void XmlSerializationWithCustomTypes()
            {
                // Create object
                var originalObject = new ObjectWithCustomType();

                originalObject.FirstName = "Test";
                originalObject.Gender    = Gender.Female;

                // Serialize and deserialize
                var clonedObject = SerializationTestHelper.SerializeAndDeserialize(originalObject, SerializationFactory.GetXmlSerializer());

                Assert.AreEqual(originalObject, clonedObject);
            }
            public void TestGenericSerialization()
            {
                var a = new A(3);
                var b = new B <A>(a);

                TestSerializationOnAllSerializers((serializer, config, description) =>
                {
                    var clonedObject = SerializationTestHelper.SerializeAndDeserialize(b, serializer, config);

                    Assert.IsNotNull(clonedObject?.Item);
                    Assert.That(clonedObject.Item.Count, Is.EqualTo(a.Count));
                });
            }
Esempio n. 26
0
            public void CorrectlyIncludesNonSerializablePropertiesIncludedWithAttributes()
            {
                var model = new CTL550Model();

                model.Color = Colors.Red;

                TestSerializationOnAllSerializers((serializer, description) =>
                {
                    var clonedModel = SerializationTestHelper.SerializeAndDeserialize(model, serializer);

                    Assert.AreEqual(Colors.Red, clonedModel.Color, description);
                });
            }
Esempio n. 27
0
            public void SerializationWithPrivateMembers()
            {
                var originalObject = new ObjectWithPrivateMembers("My private member");

                originalObject.PublicMember = "My public member";

                TestSerializationOnAllSerializers((serializer, description) =>
                {
                    var clonedObject = SerializationTestHelper.SerializeAndDeserialize(originalObject, serializer);

                    Assert.AreEqual(originalObject, clonedObject, description);
                });
            }
            public void ComplexInheritanceWorksWithBinary()
            {
                var modelC = new TestModels.ModelC();

                Assert.IsNull(modelC.ModelAProperty);
                Assert.IsNull(modelC.ModelBProperty);
                Assert.IsNull(modelC.ModelCProperty);

                var clonedModelC = SerializationTestHelper.SerializeAndDeserialize(modelC, SerializationFactory.GetBinarySerializer());

                Assert.AreEqual("ModifiedA", clonedModelC.ModelAProperty);
                Assert.AreEqual("ModifiedB", clonedModelC.ModelBProperty);
                Assert.AreEqual("ModifiedC", clonedModelC.ModelCProperty);
            }
Esempio n. 29
0
            public void SerializationWithCustomTypes()
            {
                var originalObject = new ObjectWithCustomType();

                originalObject.FirstName = "Test";
                originalObject.Gender    = Gender.Female;

                TestSerializationOnAllSerializers((serializer, description) =>
                {
                    var clonedObject = SerializationTestHelper.SerializeAndDeserialize(originalObject, serializer);

                    Assert.AreEqual(originalObject, clonedObject, description);
                });
            }
Esempio n. 30
0
            public void SerializeSimpleModels()
            {
                var originalObject = new NonCatelTestModel();

                originalObject.FirstName = "Test";
                originalObject.LastName  = "Subject";

                TestSerializationOnAllSerializers((serializer, description) =>
                {
                    var clonedObject = SerializationTestHelper.SerializeAndDeserialize(originalObject, serializer);

                    Assert.AreEqual(originalObject.FirstName, clonedObject.FirstName, description);
                    Assert.AreEqual(originalObject.LastName, clonedObject.LastName, description);
                });
            }