Ejemplo n.º 1
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]");
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
0
        public void TestConvertChecked()
        {
            NumberHelper.CheckedConvert <double>(20L).ShouldEqual(20.0);
            NumberHelper.CheckedConvert <int?>(10M).ShouldEqual(10);
            NumberHelper.CheckedConvert <decimal>(1.3f).ShouldEqual(1.3M);
            NumberHelper.CheckedConvert <int>((long)int.MaxValue).ShouldEqual(int.MaxValue);
            NumberHelper.CheckedConvert <int?>(null).ShouldEqual(null);

            UnitTestHelpers.AssertThrows <InvalidCastException>(() => NumberHelper.CheckedConvert <int>(1.5));
            UnitTestHelpers.AssertThrows <InvalidCastException>(() => NumberHelper.CheckedConvert <int>(1.111111e5f));
            UnitTestHelpers.AssertThrows <InvalidCastException>(() => NumberHelper.CheckedConvert <int>(-.1M));
            UnitTestHelpers.AssertThrows <InvalidCastException>(() => NumberHelper.CheckedConvert <int>(1.5));
            UnitTestHelpers.AssertThrows <OverflowException>(() => NumberHelper.CheckedConvert <byte>(-1L));
            UnitTestHelpers.AssertThrows <OverflowException>(() => NumberHelper.CheckedConvert <int?>(2.0 * int.MaxValue));
            UnitTestHelpers.AssertThrows <InvalidCastException>(() => NumberHelper.CheckedConvert <int>(null));
        }
Ejemplo n.º 4
0
        public void TestParseQueryWithEmpty()
        {
            var parameters = new[] { "top", "skip", "filter", "select", "orderby", "format", "inlinecount" };

            // empty is allowed (see http://services.odata.org/v3/odata/odata.svc/Categories?$filter=&$format=json)
            foreach (var parameter in parameters)
            {
                UnitTestHelpers.AssertDoesNotThrow(() => ODataQueryParser.Parse(typeof(A), string.Format("?${0}=", parameter)));
            }

            // whitespace is not allowed (see http://services.odata.org/v3/odata/odata.svc/Categories?$orderby=%20&$format=json)
            foreach (var parameter in parameters)
            {
                UnitTestHelpers.AssertThrows <ODataParseException>(() => ODataQueryParser.Parse(typeof(A), string.Format("?${0}= ", parameter)));
            }
        }
Ejemplo n.º 5
0
        public void TestOutOfOrder()
        {
            var outOfOrders = new Func <IQueryable <A>, IQueryable <A> >[]
            {
                q => q.OrderBy(a => a.Int).Where(a => a.Int > 0),
                q => q.Take(3).Skip(1),
                q => q.Take(1).Where(a => a.Int > 0),
                q => q.Skip(2).Where(a => a.Int > 0),
                q => q.Take(1).OrderBy(a => a.Int),
                q => q.Skip(1).OrderBy(a => a.Int),
                q => q.Where(a => a.Int > 0).OrderBy(a => a.Int).Where(a => a.Int < 0),
            };

            foreach (var outOfOrder in outOfOrders)
            {
                UnitTestHelpers.AssertThrows <ODataCompileException>(() => this.VerifyQuery(outOfOrder));
            }
        }
Ejemplo n.º 6
0
        public void TestNestedQuery()
        {
            var randomQuery = this.RandomQueryable(new Random(654321));

            UnitTestHelpers.AssertThrows <ODataCompileException>(() => this.VerifyQuery(q => q.Where(a => randomQuery.Any(aa => aa.Int > a.Int))));
        }
Ejemplo n.º 7
0
 public void TestRowErrors()
 {
     UnitTestHelpers.AssertThrows <ArgumentException>(() => this.VerifyQuery((IQueryable <ODataEntity> q) => q.Where(r => r.Get <string>("NullableDouble") != "0"), q => q));
     UnitTestHelpers.AssertThrows <ODataParseException>(() => this.VerifyQuery((IQueryable <ODataEntity> q) => q.Where(r => r.Get <int>("FakeInt") < 100), q => q));
 }
Ejemplo n.º 8
0
 public void TestParseIntegerOverflow()
 {
     UnitTestHelpers.AssertThrows <OverflowException>(() => this.TestParseExpressionLanguage("Int lt 2147483648"));
 }
 public void TestArgumentValidation()
 {
     UnitTestHelpers.AssertThrows <ArgumentNullException>(() => QueryStringParser.ParseQueryString(null));
     UnitTestHelpers.AssertThrows <ArgumentNullException>(() => HttpUtility.ParseQueryString(null));
 }