public void BindsTo_ListProperties(BindDelegate @delegate) { var binder = new JsonBinder(); var keyValuePairs = new[] { new KeyValuePair <string, string>("Values:0:value", "123"), new KeyValuePair <string, string>("Values:1:value", "456"), new KeyValuePair <string, string>("Values:2:value", "789") }; var result = (ListProperties)@delegate(binder, typeof(ListProperties), JsonBinder.DefaultSerializer, keyValuePairs); result.Values.Should().BeEquivalentTo(new[] { new AutoProperty { Value = "123" }, new AutoProperty { Value = "456" }, new AutoProperty { Value = "789" } }); binder.From(result) .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) .Should().BeEquivalentTo( keyValuePairs .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) ); }
/// <summary> /// Initializes a new instance of the <see cref="ComplexTableEntity"/> class. /// </summary> /// <param name="partitionKey">The partition key.</param> /// <param name="rowKey">The row key.</param> /// <param name="jsonSerializer">The json serializer.</param> /// <exception cref="ArgumentNullException"> /// partitionKey /// or /// rowKey /// or /// jsonSerializer /// </exception> /// TODO Edit XML Comment Template for #ctor protected ComplexTableEntity(string partitionKey, string rowKey, JsonSerializer jsonSerializer) { _partitionKey = partitionKey ?? throw new ArgumentNullException(nameof(partitionKey)); _rowKey = rowKey ?? throw new ArgumentNullException(nameof(rowKey)); _jsonSerializer = jsonSerializer ?? throw new ArgumentNullException(nameof(jsonSerializer)); _binder = new JsonBinder(_separator, _jsonSerializer); }
public void Populates_Value(PopulateDelegate @delegate) { var binder = new JsonBinder(); var result = (PopulatesFixture)@delegate( binder, new PopulatesFixture() { A = "123", B = 789, }, JsonBinder.DefaultSerializer, new[] { new KeyValuePair <string, string>("B", "123"), new KeyValuePair <string, string>("ComplexProperty:value", "123"), new KeyValuePair <string, string>("ComplexProperty:AutoProperty:value", "456"), new KeyValuePair <string, string>("something", "1123"), new KeyValuePair <string, string>("somethingelse:value", "1456"), new KeyValuePair <string, string>("ComplexProperty:something", "2123"), new KeyValuePair <string, string>("ComplexProperty:somethingelse:value", "2456"), }); result.A.Should().Be("123"); result.B.Should().Be(123); result.ComplexProperty.Value.Should().Be("123"); result.ComplexProperty.CustomFields.Should().NotBeEmpty(); result.CustomFields.Should().NotBeEmpty(); Logger.LogInformation(JsonConvert.SerializeObject(result.CustomFields)); }
public void BindsTo_ExtensionData(BindDelegate @delegate) { var binder = new JsonBinder(); var keyValuePairs = new[] { new KeyValuePair <string, string>("ComplexProperty:value", "123"), new KeyValuePair <string, string>("ComplexProperty:AutoProperty:value", "456"), new KeyValuePair <string, string>("something", "1123"), new KeyValuePair <string, string>("somethingelse:value", "1456"), new KeyValuePair <string, string>("ComplexProperty:something", "2123"), new KeyValuePair <string, string>("ComplexProperty:somethingelse:value", "2456"), }; var result = (ExtraProperties)@delegate(binder, typeof(ExtraProperties), JsonBinder.DefaultSerializer, keyValuePairs); result.ComplexProperty.Value.Should().Be("123"); result.ComplexProperty.AutoProperty.Value.Should().Be("456"); result.ComplexProperty.CustomFields["something"].ToString().Should().Be("2123"); result.ComplexProperty.CustomFields["somethingelse"]["value"].ToString().Should().Be("2456"); result.CustomFields.Should().NotBeEmpty(); result.CustomFields["something"].ToString().Should().Be("1123"); result.CustomFields["somethingelse"]["value"].ToString().Should().Be("1456"); Logger.LogInformation(JsonConvert.SerializeObject(result.CustomFields)); binder.From(result) .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) .Should().BeEquivalentTo( keyValuePairs .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) ); }
private static object PopulateConfiguration(JsonBinder binder, object value, JsonSerializer serializer, IEnumerable <KeyValuePair <string, string> > values) { var config = new ConfigurationBuilder(); config.AddInMemoryCollection(values); return(binder.Populate(value, config.Build())); }
private static object BindConfigurationJsonSerializer(JsonBinder binder, Type objectType, JsonSerializer serializer, IEnumerable <KeyValuePair <string, string> > values) { var config = new ConfigurationBuilder(); config.AddInMemoryCollection(values); return(binder.Bind(objectType, config.Build(), serializer)); }
private void ConfigureIOC() { IUnityContainer container = new UnityContainer(); container.AddCommunicationServices() .AddAudioServices(); var binder = new JsonBinder <ActionDescriptionOption>(); var option = binder.BindFromAssemblyResources(R_173.Properties.Resources.JsonRadioStationAssemblyName); container.RegisterInstance(option, new SingletonLifetimeManager()); container.RegisterType <IRadioManager, RadioManager>(new SingletonLifetimeManager()); container.RegisterType <IAudioReaderAndSender <SendableRadioModel>, AudioReaderAndSender>(new SingletonLifetimeManager()); container.RegisterType <IAudioReceiverAndPlayer <ReceivableRadioModel>, AudioReceiverAndPlayer>(new SingletonLifetimeManager()); container.RegisterType <IMicrophone, Microphone>(new SingletonLifetimeManager()); container.RegisterType <KeyboardHandler>(new SingletonLifetimeManager()); container.RegisterType <MainWindow>(new SingletonLifetimeManager()); container.RegisterType <IMessageBox, MessageBoxViewModel>(new SingletonLifetimeManager()); var handler = new NetworkTaskPipelineHandler(); container.RegisterInstance <INetworkTaskListener>(handler, new SingletonLifetimeManager()); container.RegisterInstance(handler, new SingletonLifetimeManager()); container.RegisterType <INetworkTaskManager, NetworkTaskManager>(new SingletonLifetimeManager()); ServiceCollection = container; }
public void GetKey_CustomSep() { var binder = new JsonBinder("__"); var values = binder.GetValues(new { a = new { b = new { value = "ABC" } } }); values.Should().Contain(x => x.Key == "a__b__value"); }
private static T BindConfigurationGenericJsonSerializer <T>(JsonBinder binder, JsonSerializer serializer, IEnumerable <KeyValuePair <string, string> > values) where T : class, new() { var config = new ConfigurationBuilder(); config.AddInMemoryCollection(values); return(binder.Bind <T>(config.Build(), serializer)); }
public void GetKey_Default() { var binder = new JsonBinder(); var values = binder.GetValues(new { a = new { b = new { value = "ABC" } } }); values.Should().Contain(x => x.Key == "a:b:value"); }
public void NullValue() { var binder = new JsonBinder(new JsonSerializer()); var actual = binder.BindToNet(new Binding <JToken> { }); Assert.Null(actual); }
public void EmptyTargetTypePrimitivePayload() { var binder = new JsonBinder(new JsonSerializer()); var actual = binder.BindToNet(new Binding <JToken> { Value = JToken.Parse("\"data\"") as JToken }); Assert.Equal("data", (string)actual); }
public void FloatConverted() { var binder = new JsonBinder(new JsonSerializer()); var actual = binder.BindToNet(new Binding <JToken> { TargetType = typeof(Single), Value = JToken.Parse("1.23") as JToken }); Assert.True(Math.Abs(1.23f - (float)actual) < 0.0000001); }
public void StringConverted() { var binder = new JsonBinder(new JsonSerializer()); var actual = binder.BindToNet(new Binding <JToken> { TargetType = typeof(string), Value = JToken.Parse("\"text\"") as JToken }); Assert.Equal("text", (string)actual); }
public void EmptyTargetType() { var binder = new JsonBinder(new JsonSerializer()); var actual = binder.BindToNet(new Binding <JToken> { Value = JToken.Parse("{\"id\":9, \"sub\":{\"test\":\"sad\"}}") as JToken }); //TODO: this is not a proper assertion and also the code behind this conversion is bad Assert.IsAssignableFrom <IDictionary <string, object> >(actual); }
public void IntConverted() { var binder = new JsonBinder(new JsonSerializer()); var actual = binder.BindToNet(new Binding <JToken> { TargetType = typeof(Int32), Value = JToken.Parse("1") as JToken }); Assert.Equal(1, (int)actual); }
private static object Bind2ConfigurationJsonSerializer(JsonBinder binder, Type objectType, JsonSerializer serializer, IEnumerable <KeyValuePair <string, string> > values) { var method = typeof(JsonBinderTests).GetTypeInfo() .GetMethod(nameof(BindConfigurationGenericJsonSerializer), BindingFlags.Static | BindingFlags.NonPublic); return(method .MakeGenericMethod(objectType) .Invoke(null, new object[] { binder, serializer, values })); }
public void ComplexTypeConverted() { var binder = new JsonBinder(new JsonSerializer()); var actual = binder.BindToNet(new Binding <JToken> { TargetType = typeof(ComplexType), Value = JToken.Parse("{\"String\":\"text\", \"Int\": 9}") as JToken }); Assert.Equal("text", ((ComplexType)actual).String); Assert.Equal(9, ((ComplexType)actual).Int); }
public void BindsTo_PrivateSetterProperty(BindDelegate @delegate) { var binder = new JsonBinder(); var keyValuePairs = new[] { new KeyValuePair <string, string>("value", "123") }; var result = (PrivateSetterProperty)@delegate(binder, typeof(PrivateSetterProperty), JsonBinder.DefaultSerializer, keyValuePairs); result.Value.Should().Be("123"); binder.From(result) .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) .Should().BeEquivalentTo( keyValuePairs .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) ); }
public void BindsTo_ComplexProperties_Null(BindDelegate @delegate) { var binder = new JsonBinder(); var keyValuePairs = new[] { new KeyValuePair <string, string>("value", "123") }; var result = (ComplexProperty)@delegate(binder, typeof(ComplexProperty), JsonBinder.DefaultSerializer, keyValuePairs); result.Value.Should().Be("123"); result.AutoProperty.Should().BeNull(); binder.From(result) .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) .Should().Contain( keyValuePairs .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) ); }
public void BindsTo_SimpleArrayProperties(BindDelegate @delegate) { var binder = new JsonBinder(); var keyValuePairs = new[] { new KeyValuePair <string, string>("Values:0", "123"), new KeyValuePair <string, string>("Values:1", "456"), new KeyValuePair <string, string>("Values:2", "789") }; var result = (SimpleArrayProperties)@delegate(binder, typeof(SimpleArrayProperties), JsonBinder.DefaultSerializer, keyValuePairs); result.Values.Should().BeEquivalentTo("123", "456", "789"); binder.From(result) .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) .Should().BeEquivalentTo( keyValuePairs .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) ); }
public void BindsTo_ComplexProperties_CustomSep(BindDelegate @delegate) { var binder = new JsonBinder("__"); var keyValuePairs = new[] { new KeyValuePair <string, string>("value", "123"), new KeyValuePair <string, string>("AutoProperty__value", "456") }; var result = (ComplexProperty)@delegate(binder, typeof(ComplexProperty), JsonBinder.DefaultSerializer, keyValuePairs); result.Value.Should().Be("123"); result.AutoProperty.Value.Should().Be("456"); binder.From(result) .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) .Should().BeEquivalentTo( keyValuePairs .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value)) ); }
private static T BindGenericJsonSerializer <T>(JsonBinder binder, JsonSerializer serializer, IEnumerable <KeyValuePair <string, string> > values) where T : class, new() { return(binder.Bind <T>(values, serializer)); }
private static object BindJsonSerializer(JsonBinder binder, Type objectType, JsonSerializer serializer, IEnumerable <KeyValuePair <string, string> > values) { return(binder.Bind(objectType, values, serializer)); }
private static object PopulateJsonSerializer(JsonBinder binder, object value, JsonSerializer serializer, IEnumerable <KeyValuePair <string, string> > values) { return(binder.Populate(value, values, serializer)); }