Example #1
0
        public void ForXmlTheEncryptAttributeDefinedInInterfaceIsUsed()
        {
            IEncryptionMechanism encryptionMechanism = new Base64EncryptionMechanism();

            var serializer = new XmlSerializer <HasEncryptAttribute>(x =>
                                                                     x.ShouldUseAttributeDefinedInInterface()
                                                                     .WithEncryptionMechanism(encryptionMechanism));

            var item = new HasEncryptAttribute
            {
                Foo = "abc"
            };

            var xml = serializer.Serialize(item);

            Assert.That(xml, Is.Not.StringContaining("<Foo>abc</Foo>"));
            var encryptedValue = encryptionMechanism.Encrypt(@"abc", null, new SerializationState());

            Assert.That(xml, Is.StringContaining(string.Format("<Foo>{0}</Foo>", encryptedValue)));
        }
Example #2
0
        public void ForJsonTheEncryptAttributeDefinedInInterfaceIsUsed()
        {
            IEncryptionMechanism encryptionMechanism = new Base64EncryptionMechanism();

            var serializer =
                new JsonSerializer <HasEncryptAttribute>(new JsonSerializerConfiguration
            {
                ShouldUseAttributeDefinedInInterface = true,
                EncryptionMechanism = encryptionMechanism
            });

            var item = new HasEncryptAttribute
            {
                Foo = "abc"
            };

            var json = serializer.Serialize(item);

            Assert.That(json, Is.Not.StringContaining(@"""Foo"":""abc"""));
            var encryptedValue = encryptionMechanism.Encrypt(@"""abc""", null, new SerializationState());

            Assert.That(json, Is.StringContaining(string.Format(@"""Foo"":""{0}""", encryptedValue)));
        }
        public void ForXmlTheEncryptAttributeDefinedInInterfaceIsUsed()
        {
            IEncryptionMechanism encryptionMechanism = new Base64EncryptionMechanism();

            var serializer = new XmlSerializer<HasEncryptAttribute>(x =>
                x.ShouldUseAttributeDefinedInInterface()
                .WithEncryptionMechanism(encryptionMechanism));

            var item = new HasEncryptAttribute
            {
                Foo = "abc"
            };

            var xml = serializer.Serialize(item);

            Assert.That(xml, Is.Not.StringContaining("<Foo>abc</Foo>"));
            var encryptedValue = encryptionMechanism.Encrypt(@"abc", null, new SerializationState());
            Assert.That(xml, Is.StringContaining(string.Format("<Foo>{0}</Foo>", encryptedValue)));
        }
        public void ForJsonTheEncryptAttributeDefinedInInterfaceIsUsed()
        {
            IEncryptionMechanism encryptionMechanism = new Base64EncryptionMechanism();

            var serializer =
                new JsonSerializer<HasEncryptAttribute>(new JsonSerializerConfiguration
                {
                    ShouldUseAttributeDefinedInInterface = true,
                    EncryptionMechanism = encryptionMechanism
                });

            var item = new HasEncryptAttribute
            {
                Foo = "abc"
            };

            var json = serializer.Serialize(item);

            Assert.That(json, Is.Not.StringContaining(@"""Foo"":""abc"""));
            var encryptedValue = encryptionMechanism.Encrypt(@"""abc""", null, new SerializationState());
            Assert.That(json, Is.StringContaining(string.Format(@"""Foo"":""{0}""", encryptedValue)));
        }