예제 #1
0
        public void ReturnNullIfDeserializingNull()
        {
            Serializer <string> serializer = new SqlVarcharSerializer();
            string actualDeserializedValue = serializer.Deserialize(null);

            Assert.Null(actualDeserializedValue);
        }
예제 #2
0
        private static void DeserializeAndAddProperty(
            TypeMarker typeMarker,
            byte[] serializedBytes,
            JObject jObject,
            string key)
        {
            SqlSerializerFactory sqlSerializerFactory = new SqlSerializerFactory();

            // UTF-8 encoding.
            SqlVarcharSerializer sqlVarcharSerializer = new SqlVarcharSerializer(size: -1, codePageCharacterEncoding: 65001);

            switch (typeMarker)
            {
            case TypeMarker.Boolean:
                jObject.Add(key, sqlSerializerFactory.GetDefaultSerializer <bool>().Deserialize(serializedBytes));
                break;

            case TypeMarker.Double:
                jObject.Add(key, sqlSerializerFactory.GetDefaultSerializer <double>().Deserialize(serializedBytes));
                break;

            case TypeMarker.Long:
                jObject.Add(key, sqlSerializerFactory.GetDefaultSerializer <long>().Deserialize(serializedBytes));
                break;

            case TypeMarker.String:
                jObject.Add(key, sqlVarcharSerializer.Deserialize(serializedBytes));
                break;

            case TypeMarker.Array:
                jObject.Add(key, JsonConvert.DeserializeObject <JArray>(sqlVarcharSerializer.Deserialize(serializedBytes)));
                break;

            case TypeMarker.Object:
                jObject.Add(key, JsonConvert.DeserializeObject <JObject>(sqlVarcharSerializer.Deserialize(serializedBytes)));
                break;

            default:
                Debug.Fail(string.Format("Unexpected type marker {0}", typeMarker));
                break;
            }
        }
예제 #3
0
        public void DeserializeTheSameAsSqlServer(string plaintext, int size, int codepage)
        {
            Database.Insert(new SqlParameter("@parameter", SqlDbType.VarChar, size)
            {
                Value = plaintext
            });
            byte[] ciphertextBytes          = Database.SelectCiphertext(SqlDbType.VarChar);
            byte[] plaintextBytes           = deterministicEncryptionAlgorithm.Decrypt(ciphertextBytes);
            SqlVarcharSerializer serializer = new SqlVarcharSerializer(size, codepage);
            string expectedPlaintext        = serializer.Deserialize(plaintextBytes);
            string actualPlaintext          = (string)Database.SelectPlaintext(SqlDbType.VarChar);

            Assert.Equal(expectedPlaintext, actualPlaintext);
        }