public void AddCustomUriLiteralParser_CannotAddNullEdmTypeReferenceWithLiteralParser()
        {
            MyCustomBooleanUriLiteralParser customBooleanUriTypePraser =
                new MyCustomBooleanUriLiteralParser();

            Action addCustomUriLiteralParserWithNullEdmType = () =>
                CustomUriLiteralParsers.AddCustomUriLiteralParser(null, customBooleanUriTypePraser);

            addCustomUriLiteralParserWithNullEdmType.ShouldThrow<ArgumentNullException>();
        }
        public void AddCustomUriLiteralParser_GeneralParsers_CanAdd()
        {
            RegisterTestCase("AddCustomUriLiteralParser_GeneralParsers_CanAdd");
            MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();

            try
            {
                CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser);

                // Test of custom parser is working
                this.ParseNonConvetionalBooleanValueSuccessfully();
            }
            finally
            {
                // Clean up from cache
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue();
            }
        }
        public void ParseUriStringToType_RegisterToEdmType_ParserIsRegisteredToDifferentEdmType()
        {
            MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();
            try
            {
                IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser);

                UriLiteralParsingException exception;
                object output =
                    CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, EdmCoreModel.Instance.GetString(true), out exception);

                // Assert
                output.Should().BeNull();
                exception.Should().BeNull();
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue();
            }
        }
        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();
            }
        }
        public void ParseUriStringToType_RegisterToEdmType_ValidValue_ParsingSucceeded()
        {
            RegisterTestCase("ParseUriStringToType_RegisterToEdmType_ValidValue_ParsingSucceeded");
            MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();
            try
            {
                IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser);

                UriLiteralParsingException exception;
                object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE, booleanTypeReference, out exception);

                // Assert
                exception.Should().BeNull();
                output.ShouldBeEquivalentTo(true);
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue();
            }
        }
        public void ParseUriStringToType_RegisterToEdmType_ParserCannotParse_ParsingHasFailed()
        {
            RegisterTestCase("ParseUriStringToType_RegisterToEdmType_ParserCannotParse_ParsingHasFailed");
            MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();
            try
            {
                IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser);

                UriLiteralParsingException exception;
                object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, booleanTypeReference, out exception);

                // Assert
                output.Should().BeNull();

                Action action = () =>
                {
                    throw exception;
                };

                action.ShouldThrow<UriLiteralParsingException>();
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue();
            }
        }
        public void RemoveCustomUriLiteralParser_CanRemoveGeneralParser()
        {
            RegisterTestCase("RemoveCustomUriLiteralParser_CanRemoveGeneralParser");
            IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();
            CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser);

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

            this.NoParsesForNonConvetionalBooleanValue();
        }
        public void RemoveCustomUriLiteralParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndRegistedWithEdmType()
        {
            RegisterTestCase("RemoveCustomUriLiteralParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndRegistedWithEdmType");
            IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();
            IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);

            CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser);
            CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser);

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

            this.NoParsesForNonConvetionalBooleanValue();
        }
        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();
            }
        }
예제 #10
0
        public void RemoveCustomUriLiteralParser_CannotRemoveNotExistingParser()
        {
            IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();
            bool isRemoveSucceeded = CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser);

            // Assert
            isRemoveSucceeded.Should().BeFalse();
        }
예제 #11
0
        public void AddCustomUriLiteralParser_GeneralParsers_CanAddIfSameParserInstanceAlreadyRegisteredToEdmType()
        {
            RegisterTestCase("AddCustomUriLiteralParser_GeneralParsers_CanAddIfSameParserInstanceAlreadyRegisteredToEdmType");
            IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();

            try
            {
                // Add once with registered EdmType
                IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser);

                // Add again as general LiteralParser (with no specific EdmType)
                CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser);

                // Test of custom parser is working
                this.ParseNonConvetionalBooleanValueSuccessfully();
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue();
            }
        }
예제 #12
0
        public void AddCustomUriLiteralParser_RegisterToEdmType_CannotAddIfAlreadyRegistedToTheSameEdmType()
        {
            RegisterTestCase("AddCustomUriLiteralParser_RegisterToEdmType_CannotAddIfAlreadyRegistedToTheSameEdmType");
            MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();
            IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);
            try
            {
                // Add once
                CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser);

                // Add again - Should throw exception
                Action addCustomUriLiteralParser = () =>
                    CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser);

                addCustomUriLiteralParser.ShouldThrow<ODataException>().
                    WithMessage(Strings.UriCustomTypeParsers_AddCustomUriTypeParserEdmTypeExists(booleanTypeReference.FullName()));
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue();
            }
        }
예제 #13
0
        public void AddCustomUriLiteralParser_RegisterToEdmType_CanAddCustomParser()
        {
            RegisterTestCase("AddCustomUriLiteralParser_RegisterToEdmType_CanAddCustomParser");
            MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();
            IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);

            try
            {
                CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser);

                // Test of custom parser is working
                this.ParseNonConvetionalBooleanValueSuccessfully();
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue();
            }
        }
예제 #14
0
        public void AddCustomUriLiteralParser_GeneralParsers_CannotAddToGeneraldIfSameInstanceAlreadyExists()
        {
            RegisterTestCase("AddCustomUriLiteralParser_GeneralParsers_CannotAddToGeneraldIfSameInstanceAlreadyExists");
            MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser();

            try
            {
                // Add Once
                CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser);

                // Add again - Should throw exception
                Action addCustomUriLiteralParser = () =>
                    CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser);

                addCustomUriLiteralParser.ShouldThrow<ODataException>().
                    WithMessage(Strings.UriCustomTypeParsers_AddCustomUriTypeParserAlreadyExists);
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue();
            }
        }
예제 #15
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();
            }
        }