Ejemplo n.º 1
0
	public void Value_Creates_With_Json(object input, string expected)
	{
		// Arrange

		// Act
		var result = Jsonb.Create(input);

		// Assert
		Assert.Equal(expected, result.ToString());
	}
Ejemplo n.º 2
0
	public void Null_Object_Creates_With_Empty_Json()
	{
		// Arrange
		int? value = null;

		// Act
		var result = Jsonb.Create(value);

		// Assert
		Assert.Equal(JsonF.Empty, result.ToString());
	}
Ejemplo n.º 3
0
	public void Object_Creates_With_Json()
	{
		// Arrange
		var value = new Test(Rnd.Str, Rnd.Int);
		var json = JsonF.Serialise(value).UnsafeUnwrap();

		// Act
		var result = Jsonb.Create(value);

		// Assert
		Assert.Equal(json, result.ToString());
	}
Ejemplo n.º 4
0
    public void Returns_Value()
    {
        // Arrange
        var value = Rnd.Str;
        var param = new Jsonb(value);

        // Act
        var result = param.ToString();

        // Assert
        Assert.Equal(value, result);
    }
Ejemplo n.º 5
0
    public void Adds_Value()
    {
        // Arrange
        var value = Rnd.Str;
        var name  = Rnd.Str;
        var param = new Jsonb(value);

        var collection = Substitute.For <IDataParameterCollection>();
        var command    = Substitute.For <IDbCommand>();

        command.Parameters.Returns(collection);

        // Act
        param.AddParameter(command, name);

        // Assert
        collection.Received().Add(Arg.Is <NpgsqlParameter>(p => p.Value == (object)value));
    }
Ejemplo n.º 6
0
        object IUserType.NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
        {
            if (names.Length != 1)
            {
                throw new InvalidOperationException("Only expecting one column...");
            }


            object value = rs[names[0]];

            if (value == DBNull.Value)
            {
                return(Jsonb.Null);
            }
            else
            {
                return(Jsonb.Create((string)value));
            }
        }
Ejemplo n.º 7
0
        public static string GetStringValue(this Jsonb jsonb, string key)
        {
            // We can also do: if (jsonb.ToString() != null)
            // But it's better to abstract things out to future-proof things,
            // we might want to use blank instead of null in the future.

            if (jsonb != Jsonb.Null)
            {
                var d = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonb.ToString());
                if (d.ContainsKey(key))
                {
                    return((string)d[key]);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 8
0
 public static string Localize(this Jsonb jsonb, string lang, string fallbackLang) =>
 jsonb.GetStringValue(lang) ?? jsonb.GetStringValue(fallbackLang);
Ejemplo n.º 9
0
 public static DbParameter MappParameter(DbParameter param, Jsonb value)
 {
     param.Value = (string)value;
     DbTypeProp.SetValue(param, Enum.Parse(DbTypeProp.PropertyType, "Jsonb"));
     return(param);
 }