Beispiel #1
0
        public void DeserializeTheSameAsSqlServer(DateTime plaintext, byte precision)
        {
            Database.Insert(new SqlParameter("@parameter", SqlDbType.DateTime2)
            {
                Value = plaintext, Precision = precision
            });
            byte[] ciphertextBytes            = Database.SelectCiphertext(SqlDbType.DateTime2);
            byte[] plaintextBytes             = deterministicEncryptionAlgorithm.Decrypt(ciphertextBytes);
            SqlDatetime2Serializer serializer = new SqlDatetime2Serializer(precision);
            DateTime expectedPlaintext        = serializer.Deserialize(plaintextBytes);
            DateTime actualPlaintext          = (DateTime)Database.SelectPlaintext(SqlDbType.DateTime2);

            Assert.Equal(expectedPlaintext, actualPlaintext);
        }
Beispiel #2
0
        public void SerializeTheSameAsSqlServer(DateTime plaintext, byte precision)
        {
            SqlDatetime2Serializer serializer = new SqlDatetime2Serializer(precision);

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

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

            Assert.Equal(expectedCiphertext, actualCiphertext);
        }
Beispiel #3
0
        public void ThrowWhenPropertySizeOutOfRange(int precision)
        {
            SqlDatetime2Serializer serializer = new SqlDatetime2Serializer();

            Assert.Throws <ArgumentOutOfRangeException>(() => serializer.Precision = precision);
        }
Beispiel #4
0
        public void ShouldThrowIfDeserializingLessThanEightBytes(byte[] data)
        {
            SqlDatetime2Serializer serializer = new SqlDatetime2Serializer();

            Assert.Throws <ArgumentOutOfRangeException>(() => serializer.Deserialize(data));
        }
Beispiel #5
0
        public void ShouldThrowIfDeserializingNull()
        {
            SqlDatetime2Serializer serializer = new SqlDatetime2Serializer();

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