public void can_add_a_parameter_to_a_db_command() { var serializer = new JsonNetSerializer { EnumStorage = EnumStorage.AsString }; var setter = new ContainmentParameterSetter <Target>(serializer, new MemberInfo[] { FindMembers.Member <Target>(x => x.Children) }); setter.AddElement(new[] { "color" }, FindMembers.Member <Target>(x => x.Color)); setter.AddElement(new[] { "name" }, FindMembers.Member <Target>(x => x.String)); setter.AddElement(new[] { "rank" }, FindMembers.Member <Target>(x => x.Number)); var target = new Target { Color = Colors.Blue, String = "Ronald McDonald", Number = 5 }; var command = new NpgsqlCommand(); var builder = new CommandBuilder(command); var parameter = setter.AddParameter(target, builder); parameter.NpgsqlDbType.ShouldBe(NpgsqlDbType.Jsonb); parameter.Value.ShouldBe("{\"Children\":[{\"color\":\"Blue\",\"name\":\"Ronald McDonald\",\"rank\":5}]}"); }
public void can_build_out_the_dictionary() { var serializer = new JsonNetSerializer { EnumStorage = EnumStorage.AsString }; var setter = new ContainmentParameterSetter <Target>(serializer, new MemberInfo[0]); setter.AddElement(new [] { "color" }, FindMembers.Member <Target>(x => x.Color)); setter.AddElement(new [] { "name" }, FindMembers.Member <Target>(x => x.String)); setter.AddElement(new [] { "rank" }, FindMembers.Member <Target>(x => x.Number)); var target = new Target { Color = Colors.Blue, String = "Ronald McDonald", Number = 5 }; var dict = setter.BuildDictionary(target); dict["color"].ShouldBe(Colors.Blue); dict["name"].ShouldBe(target.String); dict["rank"].ShouldBe(5); }
public void add_element_for_property() { var property = FindMembers.Member <Target>(x => x.String); var setter = new ContainmentParameterSetter <Target>(new JsonNetSerializer(), new MemberInfo[0]); setter.AddElement(new[] { "position" }, property); setter.Elements[0].Member.Name.ShouldBe(nameof(Target.String)); }
public void can_set_property_one_deep() { var prop = FindMembers.Member <DictTarget>(x => x.Property); var element = new DictionaryElement <DictTarget, string>(EnumStorage.AsString, new[] { "foo" }, prop); var target = new DictTarget { Property = "baz" }; var dict = new Dictionary <string, object>(); element.Write(target, dict); dict["foo"].ShouldBe("baz"); }
public void can_set_field_one_deep() { var field = FindMembers.Member <DictTarget>(x => x.Field); var element = new DictionaryElement <DictTarget, string>(EnumStorage.AsString, new[] { "foo" }, field); var target = new DictTarget { Field = "bar" }; var dict = new Dictionary <string, object>(); element.Write(target, dict); dict["foo"].ShouldBe("bar"); }
public void can_set_property_three_deep_to_existing_dictionary_structure() { var prop = FindMembers.Member <DictTarget>(x => x.Property); var element = new DictionaryElement <DictTarget, string>(EnumStorage.AsString, new[] { "one", "two", "three" }, prop); var target = new DictTarget { Property = "baz" }; var dict = new Dictionary <string, object>(); dict.Add("one", new Dictionary <string, object>()); element.Write(target, dict); dict["one"].ShouldBeOfType <Dictionary <string, object> >() ["two"].ShouldBeOfType <Dictionary <string, object> >() ["three"].ShouldBe("baz"); }