コード例 #1
0
        public void ParseWithCustomUriFunction_CustomParserThrowsExceptionAndReturnNotNullValue()
        {
            RegisterTestCase("ParseWithCustomUriFunction_CustomParserThrowsExceptionAndReturnNotNullValue");
            IUriLiteralParser customStringLiteralParser = new MyCustomStringUriLiteralParser();
            try
            {
                CustomUriLiteralParsers.AddCustomUriLiteralParser(EdmCoreModel.Instance.GetString(true), customStringLiteralParser);

                var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq '{0}'", CUSTOM_PARSER_STRING_VALUE_CAUSEBUG));
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri);

                Action parseUriAction = () =>
                    parser.ParseFilter();

                parseUriAction.ShouldThrow<ODataException>().
                    WithInnerException<UriLiteralParsingException>();
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customStringLiteralParser).Should().BeTrue();
            }
        }
コード例 #2
0
        public void CustomUriLiteralPrefix_CanSetCustomLiteralToQuotedValue()
        {
            RegisterTestCase("CustomUriLiteralPrefix_CanSetCustomLiteralToQuotedValue");
            const string LITERAL_PREFIX = "myCustomStringTypePrefixLiteral";
            IUriLiteralParser customstringUriTypePraser = new MyCustomStringUriLiteralParser();
            IEdmTypeReference stringTypeReference = EdmCoreModel.Instance.GetString(true);

            try
            {
                CustomUriLiteralPrefixes.AddCustomLiteralPrefix(LITERAL_PREFIX, stringTypeReference);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(stringTypeReference, customstringUriTypePraser);


                var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq {0}'{1}'", LITERAL_PREFIX, CUSTOM_PARSER_STRING_VALID_VALUE));
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri);

                parser.ParseFilter().Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal)
                    .And.Right.ShouldBeConstantQueryNode(CUSTOM_PARSER_STRING_VALID_VALUE + CUSTOM_PARSER_STRING_ADDED_VALUE);
            }
            finally
            {
                CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(LITERAL_PREFIX);
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customstringUriTypePraser);
            }
        }
コード例 #3
0
        public void ParseWithCustomUriFunction_CanParseByCustomParserRegisterdToEdmTpe()
        {
            RegisterTestCase("ParseWithCustomUriFunction_CanParseByCustomParserRegisterdToEdmTpe");
            IUriLiteralParser customStringLiteralParser = new MyCustomStringUriLiteralParser();
            try
            {
                CustomUriLiteralParsers.AddCustomUriLiteralParser(EdmCoreModel.Instance.GetString(true), customStringLiteralParser);

                var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq '{0}'", CUSTOM_PARSER_STRING_VALID_VALUE));
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri);

                parser.ParseFilter().Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal)
                    .And.Right.ShouldBeConstantQueryNode(CUSTOM_PARSER_STRING_VALID_VALUE + CUSTOM_PARSER_STRING_ADDED_VALUE);
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customStringLiteralParser).Should().BeTrue();
            }
        }