public void SeralizeAndDeserializeAnonymousClass()
        {
            var anonymousClass = new
            {
                Value = 1,
                Date  = DateTime.MaxValue,
                Name  = "Anuman",
                Lst   = new List <byte> {
                    1, 2, 3
                },
                Lng       = new LanguageKnowledge(Language.Kranich, 3),
                Caste     = new ArelPriest(1),
                Race      = new Orc(),
                Character = new Character("Anuman", new Amund(), new ArelPriest(1))
            };
            var anonymousClassJson             = ObjectSerializer.GetSerializedString(anonymousClass);
            var deserializedAnonymousClassJson = ObjectSerializer.LoadContent <dynamic>(anonymousClassJson);

            Assert.AreEqual(anonymousClass.Value, deserializedAnonymousClassJson.Value);
            Assert.AreEqual(anonymousClass.Date, deserializedAnonymousClassJson.Date);
            Assert.AreEqual(anonymousClass.Name, deserializedAnonymousClassJson.Name);
            Assert.AreEqual(anonymousClass.Lst, deserializedAnonymousClassJson.Lst);
            Assert.AreEqual(anonymousClass.Lng.ToString(), deserializedAnonymousClassJson.Lng.ToString());
            Assert.AreEqual(anonymousClass.Caste.ToString(), deserializedAnonymousClassJson.Caste.ToString());
            Assert.AreEqual(anonymousClass.Race.ToString(), deserializedAnonymousClassJson.Race.ToString());
            Assert.AreEqual(anonymousClass.Character.ToString(), deserializedAnonymousClassJson.Character.ToString());
        }
Exemplo n.º 2
0
        private void TestSerialization(object obj, string serializationResultFileName)
        {
            var expectedSerializationContent = EmbeddedResourceReader.Get(serializationResultFileName);
            var actualSerializationContent   = ObjectSerializer.GetSerializedString(obj);

            Assert.AreEqual(expectedSerializationContent, actualSerializationContent);
        }
        public void SeralizeAndDeserializeCharacter()
        {
            var character             = new Character("Mirena", new Human(), new Witch(5));
            var characterJson         = ObjectSerializer.GetSerializedString(character);
            var deserializedCharacter = ObjectSerializer.LoadContent <Character>(characterJson);

            Assert.AreEqual(character.Race.ToString(), deserializedCharacter.Race.ToString());
        }