Exemplo n.º 1
0
        public void ReturnNullIfSerializingNull()
        {
            Serializer <string> serializer = new SqlNvarcharSerializer();

            byte[] actualSerializedValue = serializer.Serialize(null);

            Assert.Null(actualSerializedValue);
        }
Exemplo n.º 2
0
        private static (TypeMarker, byte[]) Serialize(JToken propertyValue)
        {
            SqlSerializerFactory  sqlSerializerFactory  = new SqlSerializerFactory();
            SqlNvarcharSerializer sqlNvarcharSerializer = new SqlNvarcharSerializer(-1);

            switch (propertyValue.Type)
            {
            case JTokenType.Undefined:
                Debug.Assert(false, "Undefined value cannot be in the JSON");
                return(default, null);

            case JTokenType.Null:
                Debug.Assert(false, "Null type should have been handled by caller");
                return(TypeMarker.Null, null);

            case JTokenType.Boolean:
                return(TypeMarker.Boolean, sqlSerializerFactory.GetDefaultSerializer <bool>().Serialize(propertyValue.ToObject <bool>()));

            case JTokenType.Float:
                return(TypeMarker.Double, sqlSerializerFactory.GetDefaultSerializer <double>().Serialize(propertyValue.ToObject <double>()));

            case JTokenType.Integer:
                return(TypeMarker.Long, sqlSerializerFactory.GetDefaultSerializer <long>().Serialize(propertyValue.ToObject <long>()));

            case JTokenType.String:
                return(TypeMarker.String, sqlNvarcharSerializer.Serialize(propertyValue.ToObject <string>()));

            case JTokenType.Array:
                return(TypeMarker.Array, sqlNvarcharSerializer.Serialize(propertyValue.ToString()));

            case JTokenType.Object:
                return(TypeMarker.Object, sqlNvarcharSerializer.Serialize(propertyValue.ToString()));

            default:
                throw new InvalidOperationException($" Invalid or Unsupported Data Type Passed : {propertyValue.Type}");
            }
        }
Exemplo n.º 3
0
        public void SerializeTheSameAsSqlServer(string plaintext, int size)
        {
            SqlNvarcharSerializer serializer = new SqlNvarcharSerializer(size);

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

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

            Assert.Equal(expectedCiphertext, actualCiphertext);
        }