コード例 #1
0
        public void StringToUpperEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductName.ToUpper() == "CHAI";

            Assert.Equal("toupper(ProductName) eq 'CHAI'", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #2
0
        public void EqualDateTimeOffset()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.Updated == new DateTimeOffset(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc));

            Assert.Equal($"Updated eq {FormatSettings.GetDateTimeOffsetFormat("2013-01-01T00:00:00Z")}", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #3
0
        public void LengthOfStringEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductName.Length == 4;

            Assert.Equal("length(ProductName) eq 4", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #4
0
        public void ModEqualNumeric()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductID % 1 == 2;

            Assert.Equal("ProductID mod 1 eq 2", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #5
0
        public void EqualDecimalWithFractionalPart()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.Price == 1.23M;

            Assert.Equal($"Price eq 1.23{FormatSettings.DecimalNumberSuffix}", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #6
0
        public void EqualFieldToString()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductName.ToString() == "Chai";

            Assert.Equal("ProductName eq 'Chai'", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #7
0
        public void GreaterOrEqualNumeric()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductID >= 1.5;

            Assert.Equal($"ProductID ge 1.5{FormatSettings.DoubleNumberSuffix}", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #8
0
        public void MonthEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.CreationTime.Month == 2;

            Assert.Equal("month(CreationTime) eq 2", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #9
0
        public void YearEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.CreationTime.Year == 3;

            Assert.Equal("year(CreationTime) eq 3", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #10
0
        public void ConcatEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => string.Concat(x.ProductName, "Chai") == "ChaiChai";

            Assert.Equal("concat(ProductName,'Chai') eq 'ChaiChai'", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #11
0
        public void DayEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.CreationTime.Day == 1;

            Assert.Equal("day(CreationTime) eq 1", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #12
0
        public void ReplaceStringEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductName.Replace("a", "o") == "Choi";

            Assert.Equal("replace(ProductName,'a','o') eq 'Choi'", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #13
0
        public void SubstringWithPositionAndLengthEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductName.Substring(1, 2) == "ha";

            Assert.Equal("substring(ProductName,1,2) eq 'ha'", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #14
0
        public void IndexOfStringEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductName.IndexOf("ai") == 1;

            Assert.Equal("indexof(ProductName,'ai') eq 1", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #15
0
 public void ExpressionBuilderGeneric()
 {
     var filter = new ODataExpression<TestEntity>(x => x.ProductName == "Chai");
     filter = filter || new ODataExpression<TestEntity>(x => x.ProductID == 1);
     Assert.Equal("ProductName eq 'Chai' or ProductID eq 1", filter.AsString(_session));
 }
コード例 #16
0
        public void HourEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.CreationTime.Hour == 4;

            Assert.Equal("hour(CreationTime) eq 4", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #17
0
        public void Precedence()
        {
            Expression <Func <TestEntity, bool> > filter = x => (x.ProductID == 1 || x.ProductID == 2) && x.ProductName == "Chai";

            Assert.Equal("(ProductID eq 1 or ProductID eq 2) and ProductName eq 'Chai'", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #18
0
        public void MinuteEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.CreationTime.Minute == 5;

            Assert.Equal("minute(CreationTime) eq 5", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #19
0
        public void GreaterNumeric()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductID > 1;

            Assert.Equal("ProductID gt 1", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #20
0
        public void SecondEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.CreationTime.Second == 6;

            Assert.Equal("second(CreationTime) eq 6", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #21
0
        public void LessOrEqualNumeric()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductID <= 1;

            Assert.Equal("ProductID le 1", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #22
0
        public void FloorEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => decimal.Floor(x.Price) == 1;

            Assert.Equal(string.Format("floor(Price) eq 1{0}", FormatSettings.DecimalNumberSuffix), ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #23
0
        public void EqualLong()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductID == 1L;

            Assert.Equal($"ProductID eq 1{FormatSettings.LongNumberSuffix}", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #24
0
        public void CeilingEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => decimal.Ceiling(x.Price) == 2;

            Assert.Equal(string.Format("ceiling(Price) eq 2{0}", FormatSettings.DecimalNumberSuffix), ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #25
0
        public void EqualGuid()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.LinkID == Guid.Empty;

            Assert.Equal($"LinkID eq {FormatSettings.GetGuidFormat("00000000-0000-0000-0000-000000000000")}", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #26
0
        public void EqualNestedProperty()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.Nested.ProductID == 1;

            Assert.Equal("Nested/ProductID eq 1", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #27
0
        public void EqualTimeSpan()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.Period == new TimeSpan(1, 2, 3);

            Assert.Equal($"Period eq {FormatSettings.TimeSpanPrefix}'PT1H2M3S'", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #28
0
        public void Or()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductName == "Chai" || x.ProductID == 1;

            Assert.Equal("ProductName eq 'Chai' or ProductID eq 1", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #29
0
        public void StringToLowerEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductName.ToLower() == "chai";

            Assert.Equal("tolower(ProductName) eq 'chai'", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #30
0
        public void Not()
        {
            Expression <Func <TestEntity, bool> > filter = x => !(x.ProductName == "Chai");

            Assert.Equal("not (ProductName eq 'Chai')", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #31
0
        public void StringEndsWithEqual()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductName.EndsWith("Ch") == true;

            Assert.Equal("endswith(ProductName,'Ch') eq true", ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
コード例 #32
0
 public void ExpressionBuilder()
 {
     Expression<Predicate<TestEntity>> condition1 = x => x.ProductName == "Chai";
     Expression<Func<TestEntity, bool>> condition2 = x => x.ProductID == 1;
     var filter = new ODataExpression(condition1);
     filter = filter || new ODataExpression(condition2);
     Assert.Equal("ProductName eq 'Chai' or ProductID eq 1", filter.AsString(_session));
 }