public void Value_Creates_With_Json(object input, string expected) { // Arrange // Act var result = Jsonb.Create(input); // Assert Assert.Equal(expected, result.ToString()); }
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()); }
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()); }
public void Returns_Value() { // Arrange var value = Rnd.Str; var param = new Jsonb(value); // Act var result = param.ToString(); // Assert Assert.Equal(value, result); }
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)); }
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)); } }
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); } }
public static string Localize(this Jsonb jsonb, string lang, string fallbackLang) => jsonb.GetStringValue(lang) ?? jsonb.GetStringValue(fallbackLang);
public static DbParameter MappParameter(DbParameter param, Jsonb value) { param.Value = (string)value; DbTypeProp.SetValue(param, Enum.Parse(DbTypeProp.PropertyType, "Jsonb")); return(param); }