Пример #1
0
        public void DictionaryWithKnownTypes()
        {
            var dictionary = new DictionaryTestClass();

            dictionary.Values.Add("A", new ModelBaseFacts.Person
            {
                FirstName = "John",
                LastName  = "Doe"
            });

            dictionary.Values.Add("B", new ModelBaseFacts.Person
            {
                FirstName = "Jane",
                LastName  = "Doe"
            });

            using (var memoryStream = new MemoryStream())
            {
                dictionary.Save(memoryStream, SerializationMode.Xml);
                memoryStream.Position = 0L;
                var dictionary2 = DictionaryTestClass.Load(memoryStream, SerializationMode.Xml);

                Assert.AreEqual(dictionary, dictionary2);

                var dic1Elem1 = dictionary.Values.ElementAt(0);
                var dic2Elem1 = dictionary2.Values.ElementAt(0);

                Assert.AreEqual(dic1Elem1, dic2Elem1);

                var dic1Elem2 = dictionary.Values.ElementAt(1);
                var dic2Elem2 = dictionary2.Values.ElementAt(1);

                Assert.AreEqual(dic1Elem2, dic2Elem2);
            }
        }
Пример #2
0
        public void DictionaryWithKnownTypes()
        {
            var dictionary = new DictionaryTestClass();

            dictionary.Values.Add("A", new ModelBaseFacts.Person
            {
                FirstName = "John",
                LastName  = "Doe"
            });

            dictionary.Values.Add("B", new ModelBaseFacts.Person
            {
                FirstName = "Jane",
                LastName  = "Doe"
            });

            using (var memoryStream = new MemoryStream())
            {
                var serializer = SerializationFactory.GetXmlSerializer();
                serializer.Serialize(dictionary, memoryStream);

                memoryStream.Position = 0L;

                var dictionary2 = serializer.Deserialize <DictionaryTestClass>(memoryStream);

                Assert.AreEqual(dictionary, dictionary2);

                var dic1Elem1 = dictionary.Values.ElementAt(0);
                var dic2Elem1 = dictionary2.Values.ElementAt(0);

                Assert.AreEqual(dic1Elem1, dic2Elem1);

                var dic1Elem2 = dictionary.Values.ElementAt(1);
                var dic2Elem2 = dictionary2.Values.ElementAt(1);

                Assert.AreEqual(dic1Elem2, dic2Elem2);
            }
        }