Пример #1
0
        public void DeserializeTheSameAsSqlServer(int plaintext)
        {
            Database.Insert(new SqlParameter("@parameter", SqlDbType.Int)
            {
                Value = plaintext
            });
            byte[]           ciphertextBytes = Database.SelectCiphertext(SqlDbType.Int);
            byte[]           plaintextBytes  = deterministicEncryptionAlgorithm.Decrypt(ciphertextBytes);
            SqlIntSerializer serializer      = new SqlIntSerializer();
            int expectedPlaintext            = serializer.Deserialize(plaintextBytes);
            int actualPlaintext = (int)Database.SelectPlaintext(SqlDbType.Int);

            Assert.Equal(expectedPlaintext, actualPlaintext);
        }
Пример #2
0
        public void SerializeTheSameAsSqlServer(int plaintext)
        {
            SqlIntSerializer serializer = new SqlIntSerializer();

            byte[] serializedPlaintext = serializer.Serialize(plaintext);
            byte[] expectedCiphertext  = deterministicEncryptionAlgorithm.Encrypt(serializedPlaintext);

            Database.Insert(new SqlParameter("@parameter", SqlDbType.Int)
            {
                Value = plaintext
            });
            byte[] actualCiphertext = Database.SelectCiphertext(SqlDbType.Int);

            Assert.Equal(expectedCiphertext, actualCiphertext);
        }
Пример #3
0
        public void ShouldThrowIfDeserializingLessThanEightBytes(byte[] data)
        {
            SqlIntSerializer serializer = new SqlIntSerializer();

            Assert.Throws <ArgumentOutOfRangeException>(() => serializer.Deserialize(data));
        }
Пример #4
0
        public void ShouldThrowIfDeserializingNull()
        {
            SqlIntSerializer serializer = new SqlIntSerializer();

            Assert.Throws <ArgumentNullException>(() => serializer.Deserialize(null));
        }