Exemplo n.º 1
0
        public void FacetShouldWorkWithNullableExpressions()
        {
            var expected1 = Facet <Person2> .Parse(x => x.Age1 < 15);

            var expected2 = Facet <Person2> .Parse(x => x.Age1 >= 15 && x.Age1 < 25);

            var actual1 = Facet <Person> .Parse(x => x.Age1 < 15);

            var actual2 = Facet <Person> .Parse(x => x.Age1 >= 15 && x.Age1 < 25);

            Assert.Equal(expected1, actual1);
            Assert.Equal(expected2, actual2);

            expected1 = Facet <Person2> .Parse(x => x.Age2 < 15);

            expected2 = Facet <Person2> .Parse(x => x.Age2 >= 15 && x.Age2 < 25);

            actual1 = Facet <Person> .Parse(x => x.Age2 < 15);

            actual2 = Facet <Person> .Parse(x => x.Age2 >= 15 && x.Age2 < 25);

            Assert.Equal(expected1, actual1);
            Assert.Equal(expected2, actual2);

            expected1 = Facet <Person2> .Parse(x => x.Age3 < 15);

            expected2 = Facet <Person2> .Parse(x => x.Age3 >= 15 && x.Age3 < 25);

            actual1 = Facet <Person> .Parse(x => x.Age3 < 15);

            actual2 = Facet <Person> .Parse(x => x.Age3 >= 15 && x.Age3 < 25);

            Assert.Equal(expected1, actual1);
            Assert.Equal(expected2, actual2);
        }
Exemplo n.º 2
0
        public void CanReturnDescriptiveParsingErrors()
        {
            var invalidOperatorEx = Assert.Throws <InvalidOperationException>(() => Facet <Employee> .Parse(x => x.Salary == 5));

            Assert.Equal("Cannot use Equal as facet range. Allowed operators: <, <=, >, >=.", invalidOperatorEx.Message);

            var invalidChaningEx = Assert.Throws <InvalidOperationException>(() => Facet <Employee> .Parse(x => x.Salary < 5 || x.Salary > 8));

            Assert.Equal("Range can be only specified using: \"&&\". Cannot use: \"OrElse\"", invalidChaningEx.Message);

            var rangeFieldsEx = Assert.Throws <InvalidOperationException>(() => Facet <Employee> .Parse(x => x.Salary < 5 && x.Salary > 8 && x.Salary > 60));

            Assert.Equal("Expressions on both sides of \"&&\" must point to range field. Ex. x => x.Age > 18 && x.Age < 99", rangeFieldsEx.Message);

            var differentFieldsEx = Assert.Throws <InvalidOperationException>(() => Facet <Employee> .Parse(x => x.Salary < 5 && x.Age > 15));

            Assert.Equal("Different range fields were detected: \"Salary\" and \"Age\"", differentFieldsEx.Message);

            var invalidOperatorsInChainEx = Assert.Throws <InvalidOperationException>(() => Facet <Employee> .Parse(x => x.Salary == 5 && x.Salary == 9));

            Assert.Equal("Members in sub-expression(s) are not the correct types (expected \"<\", \"<=\", \">\" or \">=\")", invalidOperatorsInChainEx.Message);

            var invalidRange1Ex = Assert.Throws <InvalidOperationException>(() => Facet <Employee> .Parse(x => x.Salary < 5 && x.Salary >= 15));

            Assert.Equal("Invalid range: 15..5", invalidRange1Ex.Message);

            var parsedRange1 = Facet <Employee> .Parse(x => x.Salary >= 5 && x.Salary <= 15);

            Assert.Equal("{5 TO 15}", parsedRange1);

            var invalidRange2Ex = Assert.Throws <InvalidOperationException>(() => Facet <Employee> .Parse(x => x.Salary >= 15 && x.Salary <= 5));

            Assert.Equal("Invalid range: 15..5", invalidRange2Ex.Message);

            var parsedRange2 = Facet <Employee> .Parse(x => x.Salary <= 15 && x.Salary >= 5);

            Assert.Equal("{5 TO 15}", parsedRange2);

            var parsedRange3 = Facet <Employee> .Parse(x => x.Salary >= 5.1m && x.Salary <= 5.1m);

            Assert.Equal("{5.1 TO 5.1}", parsedRange3);
        }