Esempio n. 1
0
        public void DuplicatedEncryptAttributesHaveNoEffectOnDeserialization()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var json =
                @"{""Grault"":"
                + @""""
                + encryptionMechanism.Encrypt(@"{""Qux"":""abc"",""Garply"":true}")
                + @""""
                + @",""Waldo"":"
                + @""""
                + encryptionMechanism.Encrypt(@"{""Qux"":""abc"",""Garply"":true}")
                + @""""
                + @"}";

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
            };

            var serializer = new JsonSerializer <Thud>(configuration);

            var result = serializer.Deserialize(json);

            Assert.That(result.Grault.Qux, Is.EqualTo("abc"));
            Assert.That(result.Grault.Garply, Is.EqualTo(true));
            Assert.That(result.Waldo.Qux, Is.EqualTo("abc"));
            Assert.That(result.Waldo.Garply, Is.EqualTo(true));
        }
        public void CanSerializeWithEncryptRootObjectEnabled()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject = true
            };

            var serializer = new JsonSerializer<Bar>(configuration);

            var instance = new Bar
            {
                Baz = new Baz
                {
                    Qux = "abc",
                    Garply = true
                },
                Corge = 123.45
            };

            var json = serializer.Serialize(instance);

            var expected =
                @""""
                + encryptionMechanism.Encrypt(@"{""Baz"":{""Qux"":""abc"",""Garply"":true},""Corge"":123.45}")
                + @"""";

            Assert.That(json, Is.EqualTo(expected));
        }
Esempio n. 3
0
        public void CanSerializeIDictionaryOfStringToCustomTypeEncrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject   = true
            };

            var serializer = new JsonSerializer <IDictionary <string, Corge> >(configuration);

            var json = serializer.Serialize(new Dictionary <string, Corge> {
                { "foo", new Corge {
                      Bar = "abc", Baz = true
                  } }
            });

            var expected =
                @""""
                + encryptionMechanism.Encrypt(@"{""foo"":{""Bar"":""abc"",""Baz"":true}}")
                + @"""";

            Assert.That(json, Is.EqualTo(expected));
        }
Esempio n. 4
0
        public void APropertyDecoratedWithTheEncryptAttributeIsEncrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
            };

            var serializer = new JsonSerializer <Waldo>(configuration);

            var instance = new Waldo
            {
                Qux    = "abc",
                Garply = true
            };

            var json = serializer.Serialize(instance);

            var expected =
                @"{""Qux"":"""
                + encryptionMechanism.Encrypt(@"""abc""")
                + @""",""Garply"":"""
                + encryptionMechanism.Encrypt("true")
                + @"""}";

            Assert.That(json, Is.EqualTo(expected));
        }
        public void AClassDecoratedWithTheEncryptAttributeIsEncrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
            };

            var serializer = new JsonSerializer<Grault>(configuration);

            var instance = new Grault
            {
                Qux = "abc",
                Garply = true
            };

            var json = serializer.Serialize(instance);

            var expected =
                @""""
                + encryptionMechanism.Encrypt(@"{""Qux"":""abc"",""Garply"":true}")
                + @"""";

            Assert.That(json, Is.EqualTo(expected));
        }
Esempio n. 6
0
        public void CanSerializeIDictionaryOfStringToCustomTypeWithPropertyDecoratedWithEncryptAttribute()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
            };

            var serializer = new JsonSerializer <IDictionary <string, Qux> >(configuration);

            var json = serializer.Serialize(new Dictionary <string, Qux> {
                { "foo", new Qux {
                      Bar = "abc", Baz = true
                  } }
            });

            var expected =
                @"{""foo"":{""Bar"":"
                + @""""
                + encryptionMechanism.Encrypt(@"""abc""")
                + @""""
                + @",""Baz"":true}}";

            Assert.That(json, Is.EqualTo(expected));
        }
Esempio n. 7
0
        public void CanSerializeWithEncryptRootObjectEnabled()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject   = true
            };

            var serializer = new JsonSerializer <Bar>(configuration);

            var instance = new Bar
            {
                Baz = new Baz
                {
                    Qux    = "abc",
                    Garply = true
                },
                Corge = 123.45
            };

            var json = serializer.Serialize(instance);

            var expected =
                @""""
                + encryptionMechanism.Encrypt(@"{""Baz"":{""Qux"":""abc"",""Garply"":true},""Corge"":123.45}")
                + @"""";

            Assert.That(json, Is.EqualTo(expected));
        }
Esempio n. 8
0
        public void ForIDictionaryOfStringToObjectAValueHasAPropertyDecoratedWithTheEncryptAttributeHasThatPropertyEncrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
            };

            var serializer = new JsonSerializer <IDictionary <string, object> >(configuration);

            var json = serializer.Serialize(new Dictionary <string, object> {
                { "foo", new Qux {
                      Bar = "abc", Baz = true
                  } }
            });

            var expected =
                @"{""foo"":{""Bar"":"
                + @""""
                + encryptionMechanism.Encrypt(@"""abc""")
                + @""""
                + @",""Baz"":true}}";

            Assert.That(json, Is.EqualTo(expected));
        }
        public void CanSerializeGenericIEnumerableOfObjectWhenAnItemTypeIsDecoratedWithEncrypteAttribute()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
            };

            var serializer = new JsonSerializer <List <object> >(configuration);

            var json = serializer.Serialize(new List <object> {
                new Foo {
                    Bar = "abc", Baz = true
                }, new Foo {
                    Bar = "xyz", Baz = false
                }
            });

            var expected =
                "["
                + @""""
                + encryptionMechanism.Encrypt(@"{""Bar"":""abc"",""Baz"":true}")
                + @""""
                + ","
                + @""""
                + encryptionMechanism.Encrypt(@"{""Bar"":""xyz"",""Baz"":false}")
                + @""""
                + "]";

            Assert.That(json, Is.EqualTo(expected));
        }
Esempio n. 10
0
        public void MismatchedConfigurationByPropertyThrowsExceptionOnDeserialization()
        {
            var configuration = new JsonSerializerConfiguration();

            configuration.MappingsByProperty.Add(typeof(Lunch).GetProperty("Menu"), typeof(Spam));
            var serializer = new JsonSerializer <Vomit>(configuration);

            var json = @"{""Menu"":{""Eggs"":123}}";

            Assert.That(() => serializer.Deserialize(json), Throws.TypeOf <InvalidCastException>());
        }
        public void ConstructorPassesValuesCorrectly()
        {
            var name    = "notdefault";
            var options = new JsonSerializerConfiguration {
                Encoding = Encoding.UTF32
            };

            var serializer = new XSerializerJsonSerializer(name, options);

            serializer.Name.Should().Be(name);
            serializer.Options.Should().BeSameAs(options);
        }
Esempio n. 12
0
        public void CanDeserializeInterfacePropertyWhenMappingIsSpecifiedViaConfigurationByProperty()
        {
            var configuration = new JsonSerializerConfiguration();

            configuration.MappingsByProperty.Add(typeof(Breakfast).GetProperty("Menu"), typeof(Spam));
            var serializer = new JsonSerializer <Breakfast>(configuration);

            var json = @"{""Menu"":{""Eggs"":123}}";

            var food = serializer.Deserialize(json);

            Assert.That(food.Menu, Is.InstanceOf <Spam>());
            Assert.That(food.Menu.Eggs, Is.EqualTo(123));
        }
Esempio n. 13
0
        public void GivenMultipleMappingsConfigurationByInterfaceHasSecondHighestPriority()
        {
            var configuration = new JsonSerializerConfiguration();

            configuration.MappingsByType.Add(typeof(IHam), typeof(Prosciutto));
            var serializer = new JsonSerializer <FourthMeal>(configuration);

            var json = @"{""Menu"":{""Eggs"":123}}";

            var food = serializer.Deserialize(json);

            Assert.That(food.Menu, Is.InstanceOf <Prosciutto>());
            Assert.That(food.Menu.Eggs, Is.EqualTo(123));
        }
Esempio n. 14
0
        public void CanDeserializeInterfaceWhenMappingIsSpecifiedByBothAttributeAndConfiguration()
        {
            var json = @"{""Eggs"":123}";

            var configuration = new JsonSerializerConfiguration();

            configuration.MappingsByType.Add(typeof(IHam), typeof(Bacon));
            var serializer = new JsonSerializer <IHam>(configuration);

            var ham = serializer.Deserialize(json);

            Assert.That(ham, Is.InstanceOf <Bacon>()); // Choose the configured mapping, not the attribute mapping
            Assert.That(ham.Eggs, Is.EqualTo(123));
        }
Esempio n. 15
0
        public void CanOverrideConcreteClass()
        {
            var configuration = new JsonSerializerConfiguration();

            configuration.MappingsByType.Add(typeof(Widget), typeof(WidgetDerived));
            var serializer = new JsonSerializer <Widget>(configuration);

            var json = @"{""Gadget"":123}";

            var widget = serializer.Deserialize(json);

            Assert.That(widget, Is.InstanceOf <WidgetDerived>());
            Assert.That(widget.Gadget, Is.EqualTo(123));
        }
Esempio n. 16
0
        public void CanDeserializeInterfaceWhenMappingIsSpecifiedViaConfiguration()
        {
            var json = @"{""Eggs"":123}";

            var configuration = new JsonSerializerConfiguration();

            configuration.MappingsByType.Add(typeof(ISpam), typeof(Spam));
            var serializer = new JsonSerializer <ISpam>(configuration);

            var spam = serializer.Deserialize(json);

            Assert.That(spam, Is.InstanceOf <Spam>());
            Assert.That(spam.Eggs, Is.EqualTo(123));
        }
        public void CanDeserializeEncrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject   = true
            };

            var serializer = new JsonSerializer <string>(configuration);

            var json = @""""
                       + encryptionMechanism.Encrypt(@"""abc""")
                       + @"""";

            var value = serializer.Deserialize(json);

            Assert.That(value, Is.EqualTo("abc"));
        }
Esempio n. 18
0
        public void CanSerializeEncrypted(bool value, string expectedPlainText)
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject   = true
            };

            var serializer = new JsonSerializer <bool>(configuration);

            var json = serializer.Serialize(value);

            var expected =
                @""""
                + encryptionMechanism.Encrypt(expectedPlainText)
                + @"""";

            Assert.That(json, Is.EqualTo(expected));
        }
Esempio n. 19
0
        public void CanDeserializeEncrypted(string json, bool expected)
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject   = true
            };

            var serializer = new JsonSerializer <bool>(configuration);

            json =
                @""""
                + encryptionMechanism.Encrypt(json)
                + @"""";

            var value = serializer.Deserialize(json);

            Assert.That(value, Is.EqualTo(expected));
        }
Esempio n. 20
0
        public void CanSerializeEncrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject   = true
            };

            var serializer = new JsonSerializer <double>(configuration);

            var json = serializer.Serialize(123.45);

            var expected =
                @""""
                + encryptionMechanism.Encrypt(@"123.45")
                + @"""";

            Assert.That(json, Is.EqualTo(expected));
        }
        public void CanSerializeEncrypted(bool value, string expectedPlainText)
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject = true
            };

            var serializer = new JsonSerializer<bool>(configuration);

            var json = serializer.Serialize(value);

            var expected =
                @""""
                + encryptionMechanism.Encrypt(expectedPlainText)
                + @"""";

            Assert.That(json, Is.EqualTo(expected));
        }
Esempio n. 22
0
        public void AClassDecoratedWithTheEncryptAttributeIsDecrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var json =
                @""""
                + encryptionMechanism.Encrypt(@"{""Qux"":""abc"",""Garply"":true}")
                + @"""";

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
            };

            var serializer = new JsonSerializer <Grault>(configuration);

            var result = serializer.Deserialize(json);

            Assert.That(result.Garply, Is.EqualTo(true));
            Assert.That(result.Qux, Is.EqualTo("abc"));
        }
Esempio n. 23
0
        public void DuplicatedEncryptAttributesHaveNoEffectOnSerialization()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
            };

            var serializer = new JsonSerializer <Thud>(configuration);

            var instance = new Thud
            {
                Grault = new Grault
                {
                    Qux    = "abc",
                    Garply = true
                },
                Waldo = new Waldo
                {
                    Qux    = "abc",
                    Garply = true
                }
            };

            var json = serializer.Serialize(instance);

            var expected =
                @"{""Grault"":"
                + @""""
                + encryptionMechanism.Encrypt(@"{""Qux"":""abc"",""Garply"":true}")
                + @""""
                + @",""Waldo"":"
                + @""""
                + encryptionMechanism.Encrypt(@"{""Qux"":""abc"",""Garply"":true}")
                + @""""
                + @"}";

            Assert.That(json, Is.EqualTo(expected));
        }
Esempio n. 24
0
        public void CanSerializeIDictionaryOfStringToObjectEncrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject   = true
            };

            var serializer = new JsonSerializer <IDictionary <string, object> >(configuration);

            var json = serializer.Serialize(new Dictionary <string, object> {
                { "foo", "abc" }, { "bar", 123.45 }
            });

            var expected =
                @""""
                + encryptionMechanism.Encrypt(@"{""foo"":""abc"",""bar"":123.45}")
                + @"""";

            Assert.That(json, Is.EqualTo(expected));
        }
        public void CanSerializeSerializeNonGenericIEnumerableEncrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject   = true
            };

            var serializer = new JsonSerializer <ArrayList>(configuration);

            var json = serializer.Serialize(new ArrayList {
                "abc", "xyz"
            });

            var expected =
                @""""
                + encryptionMechanism.Encrypt(@"[""abc"",""xyz""]")
                + @"""";

            Assert.That(json, Is.EqualTo(expected));
        }
Esempio n. 26
0
        public void CanDeserializeWithEncryptRootObjectEnabled()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var json =
                @""""
                + encryptionMechanism.Encrypt(@"{""Baz"":{""Qux"":""abc"",""Garply"":true},""Corge"":123.45}")
                + @"""";

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject   = true
            };

            var serializer = new JsonSerializer <Bar>(configuration);

            var result = serializer.Deserialize(json);

            Assert.That(result.Baz.Garply, Is.EqualTo(true));
            Assert.That(result.Baz.Qux, Is.EqualTo("abc"));
            Assert.That(result.Corge, Is.EqualTo(123.45));
        }
        public void CanDeserializeEncrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject = true
            };

            var serializer = new JsonSerializer<string>(configuration);

            var json = @""""
                + encryptionMechanism.Encrypt(@"""abc""")
                + @"""";

            var value = serializer.Deserialize(json);

            Assert.That(value, Is.EqualTo("abc"));
        }
        public void DuplicatedEncryptAttributesHaveNoEffectOnSerialization()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
            };

            var serializer = new JsonSerializer<Thud>(configuration);

            var instance = new Thud
            {
                Grault = new Grault
                {
                    Qux = "abc",
                    Garply = true
                },
                Waldo = new Waldo
                {
                    Qux = "abc",
                    Garply = true
                }
            };

            var json = serializer.Serialize(instance);

            var expected =
                @"{""Grault"":"
                    + @""""
                    + encryptionMechanism.Encrypt(@"{""Qux"":""abc"",""Garply"":true}")
                    + @""""
                + @",""Waldo"":"
                    + @""""
                    + encryptionMechanism.Encrypt(@"{""Qux"":""abc"",""Garply"":true}")
                    + @""""
                + @"}";

            Assert.That(json, Is.EqualTo(expected));
        }
        public void CanDeserializeWithEncryptRootObjectEnabled()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var json =
                @""""
                + encryptionMechanism.Encrypt(@"{""Baz"":{""Qux"":""abc"",""Garply"":true},""Corge"":123.45}")
                + @"""";

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject = true
            };

            var serializer = new JsonSerializer<Bar>(configuration);

            var result = serializer.Deserialize(json);

            Assert.That(result.Baz.Garply, Is.EqualTo(true));
            Assert.That(result.Baz.Qux, Is.EqualTo("abc"));
            Assert.That(result.Corge, Is.EqualTo(123.45));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="XSerializerJsonSerializer"/> class.
 /// </summary>
 /// <param name="name">The name of the serializer, used to when selecting which serializer to use.</param>
 /// <param name="options">Options for customizing the JsonSerializer.</param>
 public XSerializerJsonSerializer(string name = "default", JsonSerializerConfiguration options = null)
 {
     Name    = name ?? "default";
     Options = options;
 }
        public void CanDeserializeInterfaceWhenMappingIsSpecifiedViaConfiguration()
        {
            var json = @"{""Eggs"":123}";

            var configuration = new JsonSerializerConfiguration();
            configuration.MappingsByType.Add(typeof(ISpam), typeof(Spam));
            var serializer = new JsonSerializer<ISpam>(configuration);

            var spam = serializer.Deserialize(json);

            Assert.That(spam, Is.InstanceOf<Spam>());
            Assert.That(spam.Eggs, Is.EqualTo(123));
        }
        public void CanDeserializeInterfaceWhenMappingIsSpecifiedByBothAttributeAndConfiguration()
        {
            var json = @"{""Eggs"":123}";

            var configuration = new JsonSerializerConfiguration();
            configuration.MappingsByType.Add(typeof(IHam), typeof(Bacon));
            var serializer = new JsonSerializer<IHam>(configuration);

            var ham = serializer.Deserialize(json);

            Assert.That(ham, Is.InstanceOf<Bacon>()); // Choose the configured mapping, not the attribute mapping
            Assert.That(ham.Eggs, Is.EqualTo(123));
        }
        public void CanDeserializeInterfacePropertyWhenMappingIsSpecifiedViaConfigurationByProperty()
        {
            var configuration = new JsonSerializerConfiguration();
            configuration.MappingsByProperty.Add(typeof(Breakfast).GetProperty("Menu"), typeof(Spam));
            var serializer = new JsonSerializer<Breakfast>(configuration);

            var json = @"{""Menu"":{""Eggs"":123}}";

            var food = serializer.Deserialize(json);

            Assert.That(food.Menu, Is.InstanceOf<Spam>());
            Assert.That(food.Menu.Eggs, Is.EqualTo(123));
        }
        public void GivenMultipleMappingsConfigurationByInterfaceHasSecondHighestPriority()
        {
            var configuration = new JsonSerializerConfiguration();
            configuration.MappingsByType.Add(typeof(IHam), typeof(Prosciutto));
            var serializer = new JsonSerializer<FourthMeal>(configuration);

            var json = @"{""Menu"":{""Eggs"":123}}";

            var food = serializer.Deserialize(json);

            Assert.That(food.Menu, Is.InstanceOf<Prosciutto>());
            Assert.That(food.Menu.Eggs, Is.EqualTo(123));
        }
        public void MismatchedConfigurationByPropertyThrowsExceptionOnDeserialization()
        {
            var configuration = new JsonSerializerConfiguration();
            configuration.MappingsByProperty.Add(typeof(Lunch).GetProperty("Menu"), typeof(Spam));
            var serializer = new JsonSerializer<Vomit>(configuration);

            var json = @"{""Menu"":{""Eggs"":123}}";

            Assert.That(() => serializer.Deserialize(json), Throws.TypeOf<InvalidCastException>());
        }
        public void CanOverrideConcreteClass()
        {
            var configuration = new JsonSerializerConfiguration();
            configuration.MappingsByType.Add(typeof(Widget), typeof(WidgetDerived));
            var serializer = new JsonSerializer<Widget>(configuration);

            var json = @"{""Gadget"":123}";

            var widget = serializer.Deserialize(json);

            Assert.That(widget, Is.InstanceOf<WidgetDerived>());
            Assert.That(widget.Gadget, Is.EqualTo(123));
        }
        public void CanDeserializeEncrypted(string json, bool expected)
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject = true
            };

            var serializer = new JsonSerializer<bool>(configuration);

            json =
                @""""
                + encryptionMechanism.Encrypt(json)
                + @"""";

            var value = serializer.Deserialize(json);

            Assert.That(value, Is.EqualTo(expected));
        }
        public void DuplicatedEncryptAttributesHaveNoEffectOnDeserialization()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var json =
                @"{""Grault"":"
                    + @""""
                    + encryptionMechanism.Encrypt(@"{""Qux"":""abc"",""Garply"":true}")
                    + @""""
                + @",""Waldo"":"
                    + @""""
                    + encryptionMechanism.Encrypt(@"{""Qux"":""abc"",""Garply"":true}")
                    + @""""
                + @"}";

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
            };

            var serializer = new JsonSerializer<Thud>(configuration);

            var result = serializer.Deserialize(json);

            Assert.That(result.Grault.Qux, Is.EqualTo("abc"));
            Assert.That(result.Grault.Garply, Is.EqualTo(true));
            Assert.That(result.Waldo.Qux, Is.EqualTo("abc"));
            Assert.That(result.Waldo.Garply, Is.EqualTo(true));
        }
        public void APropertyDecoratedWithTheEncryptAttributeIsDecrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var json =
                @"{""Qux"":"""
                + encryptionMechanism.Encrypt(@"""abc""")
                + @""",""Garply"":"""
                + encryptionMechanism.Encrypt("true")
                + @"""}";

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
            };

            var serializer = new JsonSerializer<Waldo>(configuration);

            var result = serializer.Deserialize(json);

            Assert.That(result.Garply, Is.EqualTo(true));
            Assert.That(result.Qux, Is.EqualTo("abc"));
        }
        public void CanSerializeEncrypted()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            var configuration = new JsonSerializerConfiguration
            {
                EncryptionMechanism = encryptionMechanism,
                EncryptRootObject = true
            };

            var serializer = new JsonSerializer<double>(configuration);

            var json = serializer.Serialize(123.45);

            var expected =
                @""""
                + encryptionMechanism.Encrypt(@"123.45")
                + @"""";

            Assert.That(json, Is.EqualTo(expected));
        }