예제 #1
0
 public void TestGet()
 {
     var row = new ODataEntity(new Dictionary<string, object> { { "a", 1 }, { "b", "2" } });
     row.Get<int>("A").ShouldEqual(1);
     row.Get<string>("b").ShouldEqual("2");
     UnitTestHelpers.AssertThrows<InvalidCastException>(() => row.Get<string>("a"));
     UnitTestHelpers.AssertThrows<ArgumentException>(() => row.Get<string>("c"));
 }
예제 #2
0
        public void TestGet()
        {
            var row = new ODataEntity(new Dictionary <string, object> {
                { "a", 1 }, { "b", "2" }
            });

            row.Get <int>("A").ShouldEqual(1);
            row.Get <string>("b").ShouldEqual("2");
            UnitTestHelpers.AssertThrows <InvalidCastException>(() => row.Get <string>("a"));
            UnitTestHelpers.AssertThrows <ArgumentException>(() => row.Get <string>("c"));
        }
예제 #3
0
        public void ODataEntityTestNumericCastIssue()
        {
            var entity = new ODataEntity(new[] { new KeyValuePair <string, object>("x", 1.5), new KeyValuePair <string, object>("y", long.MaxValue) });

            var ex = UnitTestHelpers.AssertThrows <InvalidCastException>(() => entity.Get <int>("x"));

            ex.Message.ShouldEqual("Failed to convert property 'x' value '1.5' of type System.Double to requested type System.Int32");

            var ex2 = UnitTestHelpers.AssertThrows <InvalidCastException>(() => entity.Get <int>("y"));

            ex2.Message.ShouldEqual("Failed to convert property 'y' value '9223372036854775807' of type System.Int64 to requested type System.Int32");
        }
예제 #4
0
        public void ODataEntityTestIncompatibleGet()
        {
            var entity = new ODataEntity(new[] { KeyValuePair.Create("A", "100".As <object>()) });

            var ex = UnitTestHelpers.AssertThrows <InvalidCastException>(() => entity.Get <double?>("A"));

            ex.Message.ShouldEqual("value '100' of type System.String for property 'A' is not compatible with requested type System.Nullable`1[System.Double]");
        }
예제 #5
0
        public void TestGetValuesFromODataEntity()
        {
            var entity = new ODataEntity(new Dictionary <string, object>
            {
                { "A", null },
                { "B", 1 },
                { "C", new ODataEntity(new Dictionary <string, object> {
                        { "X", "abc" }
                    }) },
                { "D", ODataValue.FromObject(-1) },
                { "F", 1.5 },
            });

            entity.Get <string>("A").ShouldEqual(null);
            entity.Get <int>("b").ShouldEqual(1);
            entity.Get <int?>("b").ShouldEqual(1);
            entity.Get <ODataValue>("B").Value.ShouldEqual(1);
            entity.Get <ODataEntity>("c").Get <string>("x").ShouldEqual("abc");
            entity.Get <ODataObject>("C").GetType().ShouldEqual(typeof(ODataEntity));
            entity.Get <int>("d").ShouldEqual(-1);

            UnitTestHelpers.AssertThrows <InvalidCastException>(() => entity.Get <int>("a"));
            UnitTestHelpers.AssertThrows <InvalidCastException>(() => entity.Get <long>("F"));
        }