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 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 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 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 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); }
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); }