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); }
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); }
public void ThrowWhenPropertySizeOutOfRange(int precision) { SqlDatetime2Serializer serializer = new SqlDatetime2Serializer(); Assert.Throws <ArgumentOutOfRangeException>(() => serializer.Precision = precision); }
public void ShouldThrowIfDeserializingLessThanEightBytes(byte[] data) { SqlDatetime2Serializer serializer = new SqlDatetime2Serializer(); Assert.Throws <ArgumentOutOfRangeException>(() => serializer.Deserialize(data)); }
public void ShouldThrowIfDeserializingNull() { SqlDatetime2Serializer serializer = new SqlDatetime2Serializer(); Assert.Throws <ArgumentNullException>(() => serializer.Deserialize(null)); }