Beispiel #1
0
        public void DogMatchDeserializaionTest()
        {
            AnimalCard card       = AnimalCard.Create("🐶");
            var        jsonString = JsonSerializer.Serialize <DogCard>((DogCard)card);

            Assert.Equal("{\"Animal\":\"\\uD83D\\uDC36\",\"IsTurned\":false,\"IsMatched\":false,\"CssClass\":\"\"}", jsonString);

            string toSerialize = "\r\n{ \r\n\"Animal\": \r\n\"\\uD83D\\uDC36\", \r\n\"IsTurned\": false, \r\n\"IsMatched\": false, \r\n\"CssClass\": \"\" \r\n}";
            var    newCard     = JsonSerializer.Deserialize <DogCard>(toSerialize);

            Assert.Equal("🐶", newCard.Animal);
        }
        public void TestSerialization()
        {
            AnimalCard card       = AnimalCard.Create("🐶");
            var        jsonString = JsonSerializer.Serialize <DogCard>((DogCard)card);

            Assert.Equal("{\"Animal\":\"\\uD83D\\uDC36\",\"IsTurned\":false,\"IsMatched\":false,\"CssClass\":\"\"}", jsonString);

            // Convert regular string literal to verbatim string literal
            string toSerialize = "\r\n{ \r\n\"Animal\": \r\n\"\\uD83D\\uDC36\", \r\n\"IsTurned\": false, \r\n\"IsMatched\": false, \r\n\"CssClass\": \"\" \r\n}";
            var    newCard     = JsonSerializer.Deserialize <DogCard>(toSerialize);

            Assert.Equal("🐶", newCard.Animal);
        }
        public void TestSerialization()
        {
            AnimalCard card       = AnimalCard.Create("🐶");
            var        jsonString = JsonSerializer.Serialize <DogCard>((DogCard)card);

            Assert.Equal("{\"Animal\":\"\\uD83D\\uDC36\",\"IsTurned\":false,\"IsMatched\":false,\"CssClass\":\"\"}", jsonString);
            string toSerialize = @"
                                    { 
                                      ""Animal"": 
                                        ""\uD83D\uDC36"", 
                                        ""IsTurned"": false, 
                                        ""IsMatched"": false, 
                                        ""CssClass"": """" 
                                    }";
            var    newCard     = JsonSerializer.Deserialize <DogCard>(toSerialize);

            Assert.Equal("🐶", newCard.Animal);
        }