Ejemplo n.º 1
0
        public void InvokeTest()
        {
            var first   = ConverterMiddleware.Link(new NullValueConverter());
            var context = new ConvertContext("name", null, 0, null);
            var kvs     = first.Invoke(context)
                          .ToDictionary(item => item.Key, item => item.Value);

            Assert.True(kvs["name"] == null);
        }
Ejemplo n.º 2
0
        public void InvokeTest()
        {
            var first   = ConverterMiddleware.Link(new SimpleTypeConverter(), new EnumerableConverter());
            var model   = new object[] { "30", 30, 30m, 30d, 30f };
            var context = new ConvertContext("v", model, 0, null);
            var kvs     = first.Invoke(context).ToArray();

            Assert.True(kvs.Length == model.Length);
            Assert.True(kvs.All(kv => kv.Key == "v" && kv.Value == "30"));
        }
        public void InvokeTest()
        {
            var first   = ConverterMiddleware.Link(new KeyValuePairConverter());
            var model   = new KeyValuePair <string, object>("name", "laojiu");
            var context = new ConvertContext("model", model, 0, new WebApiClient.FormatOptions {
                UseCamelCase = true
            });
            var kvs = first.Invoke(context)
                      .ToDictionary(item => item.Key, item => item.Value);

            Assert.True(kvs["name"] == "laojiu");
        }
Ejemplo n.º 4
0
        public void InvokeTest()
        {
            var     first = ConverterMiddleware.Link(new DynamicObjectConverter());
            dynamic model = new dyObject();

            model.name = "laojiu";
            model.age  = "18";
            var context = new ConvertContext("name", model, 0, null);
            var kvs     = first.Invoke(context)
                          .ToDictionary(item => item.Key, item => item.Value);

            Assert.True(kvs["name"] == "laojiu");
            Assert.True(kvs["age"] == "18");
        }
Ejemplo n.º 5
0
        public void InvokeTest()
        {
            var first = ConverterMiddleware.Link(new PropertiesConverter());
            var model = new Model {
                Age = 18, Name = "laojiu"
            };
            var context = new ConvertContext("name", model, 0, new WebApiClient.FormatOptions {
                UseCamelCase = true
            });
            var kvs = first.Invoke(context)
                      .ToDictionary(item => item.Key, item => item.Value);

            Assert.True(kvs["name"] == "laojiu");
            Assert.True(kvs["age"] == "18");
            Assert.True(kvs["email"] == null);
            Assert.False(kvs.ContainsKey("birthday"));
        }
Ejemplo n.º 6
0
        public void InvokeTest()
        {
            var first = ConverterMiddleware.Link(new SimpleTypeConverter());

            var context = new ConvertContext("name", "laojiu", 0, null);
            var kvs     = first.Invoke(context)
                          .ToDictionary(item => item.Key, item => item.Value);

            Assert.True(kvs["name"] == "laojiu");

            context = new ConvertContext("age", 18, 0, null);
            kvs     = first.Invoke(context)
                      .ToDictionary(item => item.Key, item => item.Value);
            Assert.True(kvs["age"] == "18");

            context = new ConvertContext("Time", DateTime.Parse("2010-10-10 10:10:10"), 0, new WebApiClient.FormatOptions {
                DateTimeFormat = "yyyy-MM", UseCamelCase = true
            });
            kvs = first.Invoke(context)
                  .ToDictionary(item => item.Key, item => item.Value);
            Assert.True(kvs["time"] == "2010-10");

            context = new ConvertContext("e", E.e, 0, null);
            kvs     = first.Invoke(context)
                      .ToDictionary(item => item.Key, item => item.Value);
            Assert.True(kvs["e"] == "1");

            context = new ConvertContext("f", "1.0", 0, null);
            kvs     = first.Invoke(context)
                      .ToDictionary(item => item.Key, item => item.Value);
            Assert.True(kvs["f"] == "1.0");

            context = new ConvertContext("v", Version.Parse("1.0"), 0, null);
            kvs     = first.Invoke(context)
                      .ToDictionary(item => item.Key, item => item.Value);
            Assert.True(kvs["v"] == "1.0");
        }