示例#1
0
        public void EncryptDoesNothingIfNoEncryptionMechanismIsDefined()
        {
            dynamic foo =
                new JsonArray
                {
                    "abc",
                };

            object bar = foo[0];
            foo.Encrypt(0);
            object barEncrypted = foo[0];

            Assert.That(barEncrypted, Is.EqualTo(bar));
        }
示例#2
0
        public void EncryptDoesNothingIfTheItemIsNull()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            dynamic foo =
                new JsonArray(encryptionMechanism:encryptionMechanism)
                {
                    null,
                };

            object bar1 = foo[0];
            Assert.That(bar1, Is.Null);

            foo.Encrypt(0);

            object bar2 = foo[0];
            Assert.That(bar2, Is.Null);
        }
示例#3
0
        public void CanEncryptJsonObjectProperty()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            dynamic foo =
                new JsonArray(encryptionMechanism:encryptionMechanism)
                {
                    new JsonObject(encryptionMechanism:encryptionMechanism)
                    {
                        { "baz", false },
                        { "qux", new JsonNumber("123.45") },
                    },
                };

            object bar = foo[0];
            foo.Encrypt(0);
            string barEncrypted = foo[0];

            Assert.That(barEncrypted, Is.Not.EqualTo(bar));

            Assert.That(barEncrypted, Is.EqualTo(encryptionMechanism.Encrypt(@"{""baz"":false,""qux"":123.45}")));
        }
示例#4
0
        public void CanEncryptJsonArrayProperty()
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            dynamic foo =
                new JsonArray(encryptionMechanism:encryptionMechanism)
                {
                    new JsonArray(encryptionMechanism:encryptionMechanism)
                    {
                        false,
                        new JsonNumber("123.45"),
                    },
                };

            object bar = foo[0];
            foo.Encrypt(0);
            string barEncrypted = foo[0];

            Assert.That(barEncrypted, Is.Not.EqualTo(bar));

            Assert.That(barEncrypted, Is.EqualTo(encryptionMechanism.Encrypt(@"[false,123.45]")));
        }
示例#5
0
        public void CanEncryptPrimitiveItem(object value, string expectedPlaintextValue)
        {
            var encryptionMechanism = new Base64EncryptionMechanism();

            dynamic foo =
                new JsonArray(encryptionMechanism:encryptionMechanism)
                {
                    value,
                };

            object bar = foo[0];
            foo.Encrypt(0);
            string barEncrypted = foo[0];

            Assert.That(barEncrypted, Is.Not.EqualTo(bar));

            Assert.That(barEncrypted, Is.EqualTo(encryptionMechanism.Encrypt(expectedPlaintextValue)));
        }