コード例 #1
0
        public void CustomUriLiteralPrefix_ParseTypeWithCorrectLiteralPrefixAndUriParser()
        {
            RegisterTestCase("CustomUriLiteralPrefix_ParseTypeWithCorrectLiteralPrefixAndUriParser");
            var customBooleanAndIntUriLiteralParser = new MyCustomIntAndBooleanUriLiteralParser();
            try
            {
                IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);
                CustomUriLiteralPrefixes.AddCustomLiteralPrefix(BOOLEAN_LITERAL_PREFIX, booleanTypeReference);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanAndIntUriLiteralParser);

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

                parser.ParseFilter().Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal)
                    .And.Right.ShouldBeConvertQueryNode(EdmCoreModel.Instance.GetBoolean(true)).And.Source.ShouldBeConstantQueryNode(true);
            }
            finally
            {
                CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(BOOLEAN_LITERAL_PREFIX);
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanAndIntUriLiteralParser);
            }
        }
コード例 #2
0
        public void ParseUriStringToType_ParseFirstWithRegisteredEdmType()
        {
            RegisterTestCase("ParseUriStringToType_ParseFirstWithRegisteredEdmType");
            IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();
            IUriLiteralParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriLiteralParser();

            try
            {
                IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(customIntBooleanUriTypePraser);

                // The boolean type parse will parse the value to 'True'
                // The int boolean type parse will throw exception.
                // If result is 'True' it means the registered parser is used first.
                // If result is exception it means the general parse is used first
                UriLiteralParsingException exception;
                object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALUE_TRUE_VALID, booleanTypeReference, out exception);

                // Assert
                output.Should().Be(true);
                exception.Should().BeNull();
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue();
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customIntBooleanUriTypePraser).Should().BeTrue();
            }
        }
コード例 #3
0
        public void RemoveCustomUriLiteralParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndMultipleRegistedWithEdmType()
        {
            RegisterTestCase("RemoveCustomUriLiteralParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndMultipleRegistedWithEdmType");
            IUriLiteralParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriLiteralParser();
            IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);
            IEdmTypeReference intTypeReference = EdmCoreModel.Instance.GetInt32(false);

            CustomUriLiteralParsers.AddCustomUriLiteralParser(customIntBooleanUriTypePraser);
            CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customIntBooleanUriTypePraser);
            CustomUriLiteralParsers.AddCustomUriLiteralParser(intTypeReference, customIntBooleanUriTypePraser);

            bool isRemoved = CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customIntBooleanUriTypePraser);
            isRemoved.Should().BeTrue();

            this.NoParsesForNonConvetionalBooleanValue();
            this.NoParsesForNonConvetionalIntValue();
        }
コード例 #4
0
        public void AddCustomUriLiteralParser_CanAddMultipleDifferentInstancesToRegisteredAndGeneral()
        {
            RegisterTestCase("AddCustomUriLiteralParser_CanAddMultipleDifferentInstancesToRegisteredAndGeneral");

            IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();
            IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);

            IUriLiteralParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriLiteralParser();

            try
            {
                // Add to registered edm types
                CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser);

                // Add to general parsers
                CustomUriLiteralParsers.AddCustomUriLiteralParser(customIntBooleanUriTypePraser);

                // Test of custom parser is working
                this.ParseNonConvetionalBooleanValueSuccessfully();
                this.ParseNonConvetionalIntValueSuccessfully();
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue();
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customIntBooleanUriTypePraser).Should().BeTrue();
            }
        }
コード例 #5
0
        public void AddCustomUriLiteralParser_RegisterToEdmType_CanAddIfSameParserInstanceExistsButRegisteredToDifferentEdmType()
        {
            RegisterTestCase("AddCustomUriLiteralParser_RegisterToEdmType_CanAddIfSameParserInstanceExistsButRegisteredToDifferentEdmType");
            IUriLiteralParser customIntAndBooleanUriTypePraser = new MyCustomIntAndBooleanUriLiteralParser();

            try
            {
                // Add once
                IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customIntAndBooleanUriTypePraser);

                // Add same type converter but registered to a different EdmType(string instead of boolean)
                IEdmTypeReference intTypeReference = EdmCoreModel.Instance.GetInt32(false);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(intTypeReference, customIntAndBooleanUriTypePraser);

                // Test of custom parser is working
                this.ParseNonConvetionalBooleanValueSuccessfully();
                this.ParseNonConvetionalIntValueSuccessfully();
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customIntAndBooleanUriTypePraser).Should().BeTrue();
            }
        }
コード例 #6
0
        public void AddCustomUriLiteralParser_GeneralParsers_CanAddMultipleDifferentInstances()
        {
            RegisterTestCase("AddCustomUriLiteralParser_GeneralParsers_CanAddMultipleDifferentInstances");
            IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();
            IUriLiteralParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriLiteralParser();

            try
            {
                // Add two different instances to GeneralLiteralParsers
                CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(customIntBooleanUriTypePraser);

                // Test of custom parser is working
                this.ParseNonConvetionalBooleanValueSuccessfully();
                this.ParseNonConvetionalIntValueSuccessfully();
            }
            finally
            {
                // Clean up from cache
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue();
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customIntBooleanUriTypePraser).Should().BeTrue();
            }
        }