diff --git a/src/Microsoft.OData.Core/Build.Net35/Microsoft.OData.Core.NetFX35.csproj b/src/Microsoft.OData.Core/Build.Net35/Microsoft.OData.Core.NetFX35.csproj index 970426fc51..b6e7df38cd 100644 --- a/src/Microsoft.OData.Core/Build.Net35/Microsoft.OData.Core.NetFX35.csproj +++ b/src/Microsoft.OData.Core/Build.Net35/Microsoft.OData.Core.NetFX35.csproj @@ -1800,23 +1800,23 @@ Microsoft\OData\Core\WriterValidatorMinimalValidation.cs - - Microsoft\OData\Core\UriParser\CustomUriTypePrefixLiterals.cs + + Microsoft\OData\Core\UriParser\CustomUriLiteralPrefixes.cs - - Microsoft\OData\Core\UriParser\Parsers\TypeParsers\Common\IUriTypeParser.cs + + Microsoft\OData\Core\UriParser\Parsers\LiteralParsers\Common\IUriLiteralParser.cs - - Microsoft\OData\Core\UriParser\Parsers\TypeParsers\Common\UriTypeParsingException.cs + + Microsoft\OData\Core\UriParser\Parsers\LiteralParsers\Common\UriLiteralParsingException.cs - - Microsoft\OData\Core\UriParser\Parsers\TypeParsers\DefaultUriTypeParser.cs + + Microsoft\OData\Core\UriParser\Parsers\LiteralParsers\DefaultUriLiteralParser.cs - - Microsoft\OData\Core\UriParser\Parsers\TypeParsers\UriCustomTypeParsers.cs + + Microsoft\OData\Core\UriParser\Parsers\LiteralParsers\CustomUriLiteralParsers.cs - - Microsoft\OData\Core\UriParser\Parsers\TypeParsers\UriPrimitiveTypeParser.cs + + Microsoft\OData\Core\UriParser\Parsers\LiteralParsers\UriPrimitiveTypeParser.cs Microsoft\OData\Core\UriParser\Parsers\UriParserHelper.cs diff --git a/src/Microsoft.OData.Core/GlobalSuppressions.cs b/src/Microsoft.OData.Core/GlobalSuppressions.cs index 4f9ba1f9d6..e308f63c97 100644 --- a/src/Microsoft.OData.Core/GlobalSuppressions.cs +++ b/src/Microsoft.OData.Core/GlobalSuppressions.cs @@ -110,4 +110,4 @@ [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.OData.Core.JsonLight.ODataJsonLightDeltaReader.#IsTopLevel")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.OData.Core.JsonLight.ODataJsonLightDeltaWriter.#IsTopLevel")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Scope = "member", Target = "Microsoft.OData.Core.UriParser.FunctionSignatureWithReturnType.#ArgumentTypes")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "Microsoft.OData.Core.UriParser.Parsers.TypeParsers.UriPrimitiveTypeParser.#TryUriStringToPrimitive(System.String,Microsoft.OData.Edm.IEdmTypeReference,System.Object&,Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common.UriTypeParsingException&)")] \ No newline at end of file +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "Microsoft.OData.Core.UriParser.Parsers.UriPrimitiveTypeParser.#TryUriStringToPrimitive(System.String,Microsoft.OData.Edm.IEdmTypeReference,System.Object&,Microsoft.OData.Core.UriParser.Parsers.Common.UriLiteralParsingException&)")] diff --git a/src/Microsoft.OData.Core/Microsoft.OData.Core.Net45.csproj b/src/Microsoft.OData.Core/Microsoft.OData.Core.Net45.csproj index 11b775f67e..edef8920bb 100644 --- a/src/Microsoft.OData.Core/Microsoft.OData.Core.Net45.csproj +++ b/src/Microsoft.OData.Core/Microsoft.OData.Core.Net45.csproj @@ -422,7 +422,7 @@ - + @@ -467,11 +467,11 @@ - - - - - + + + + + diff --git a/src/Microsoft.OData.Core/Microsoft.OData.Core.Portable45.Profile111.csproj b/src/Microsoft.OData.Core/Microsoft.OData.Core.Portable45.Profile111.csproj index 61a2c40a18..fef18b2514 100644 --- a/src/Microsoft.OData.Core/Microsoft.OData.Core.Portable45.Profile111.csproj +++ b/src/Microsoft.OData.Core/Microsoft.OData.Core.Portable45.Profile111.csproj @@ -420,7 +420,7 @@ - + @@ -465,11 +465,11 @@ - - - - - + + + + + diff --git a/src/Microsoft.OData.Core/Microsoft.OData.Core.Portable45.csproj b/src/Microsoft.OData.Core/Microsoft.OData.Core.Portable45.csproj index b035df13cc..8877d20f3b 100644 --- a/src/Microsoft.OData.Core/Microsoft.OData.Core.Portable45.csproj +++ b/src/Microsoft.OData.Core/Microsoft.OData.Core.Portable45.csproj @@ -421,7 +421,7 @@ - + @@ -466,11 +466,11 @@ - - - - - + + + + + diff --git a/src/Microsoft.OData.Core/Microsoft.OData.Core.csproj b/src/Microsoft.OData.Core/Microsoft.OData.Core.csproj index 61789a6bf0..a677250dfd 100644 --- a/src/Microsoft.OData.Core/Microsoft.OData.Core.csproj +++ b/src/Microsoft.OData.Core/Microsoft.OData.Core.csproj @@ -421,7 +421,7 @@ - + @@ -466,11 +466,11 @@ - - - - - + + + + + diff --git a/src/Microsoft.OData.Core/UriParser/CustomUriFunctions.cs b/src/Microsoft.OData.Core/UriParser/CustomUriFunctions.cs index dd1413b424..232c28c85e 100644 --- a/src/Microsoft.OData.Core/UriParser/CustomUriFunctions.cs +++ b/src/Microsoft.OData.Core/UriParser/CustomUriFunctions.cs @@ -47,23 +47,6 @@ private static readonly Dictionary Cu /// Throws if built-in function signature overload already exists. /// Throws if custom function signature overload already exists public static void AddCustomUriFunction(string functionName, FunctionSignatureWithReturnType functionSignature) - { - AddCustomUriFunction(functionName, functionSignature, false); - } - - /// - /// Add a custom uri function to extend or override the built-in OData protocol of uri functions. - /// In case the function signature already exists as a built-in function, if requested (addAsOverloadToBuiltInFunction = true), the new function signature will be added as another overload. - /// In case the function name already exists as a custom function, the signature will be added as an another overload. - /// - /// The new custom function name - /// The new custom function signature - /// If 'True', add as another overload to the existing built-in function in case signature already exists - /// Arguments are null, or function signature return type is null - /// Throws if built-in function name already exists, and parameter 'addAsOverloadToBuiltInFunction' is not 'True' - /// Throws if built-in function signature overload already exists. - /// Throws if custom function signature overload already exists - public static void AddCustomUriFunction(string functionName, FunctionSignatureWithReturnType functionSignature, bool addAsOverloadToBuiltInFunction) { // Parameters validation ExceptionUtils.CheckArgumentStringNotNullOrEmpty(functionName, "customFunctionName"); @@ -80,12 +63,6 @@ public static void AddCustomUriFunction(string functionName, FunctionSignatureWi FunctionSignatureWithReturnType[] existingBuiltInFunctionOverload; if (BuiltInUriFunctions.TryGetBuiltInFunction(functionName, out existingBuiltInFunctionOverload)) { - // Built-In function with the same signature already exists, and will not be added as an another overload by user request. - if (!addAsOverloadToBuiltInFunction) - { - throw new ODataException(Strings.CustomUriFunctions_AddCustomUriFunction_BuiltInExistsNotAddingAsOverload(functionName)); - } - // Function name exists, check if full signature exists among the overloads. if (existingBuiltInFunctionOverload.Any(builtInFunction => AreFunctionsSignatureEqual(functionSignature, builtInFunction))) @@ -208,7 +185,7 @@ private static void AddCustomFunction(string customFunctionName, FunctionSignatu } // Add the custom function as an overload to the same function name - CustomFunctions[customFunctionName] = + CustomFunctions[customFunctionName] = existingCustomFunctionOverloads.Concat(new FunctionSignatureWithReturnType[] { newCustomFunctionSignature }).ToArray(); } } diff --git a/src/Microsoft.OData.Core/UriParser/CustomUriTypePrefixLiterals.cs b/src/Microsoft.OData.Core/UriParser/CustomUriLiteralPrefixes.cs similarity index 51% rename from src/Microsoft.OData.Core/UriParser/CustomUriTypePrefixLiterals.cs rename to src/Microsoft.OData.Core/UriParser/CustomUriLiteralPrefixes.cs index 5ef5acccdc..645f7d8ca1 100644 --- a/src/Microsoft.OData.Core/UriParser/CustomUriTypePrefixLiterals.cs +++ b/src/Microsoft.OData.Core/UriParser/CustomUriLiteralPrefixes.cs @@ -1,5 +1,5 @@ //--------------------------------------------------------------------- -// +// // Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. // //--------------------------------------------------------------------- @@ -20,67 +20,67 @@ namespace Microsoft.OData.Core.UriParser /// Extends the uri parsing system of Literal Prefix. /// With this class, you can add a custom literal prefix for any EdmType. /// - public static class CustomUriTypePrefixLiterals + public static class CustomUriLiteralPrefixes { #region Fields private static readonly object Locker = new object(); - private static Dictionary PrefixLiteralsOfEdmTypes = new Dictionary(StringComparer.Ordinal); + private static Dictionary CustomLiteralPrefixesOfEdmTypes = new Dictionary(StringComparer.Ordinal); #endregion #region Public Static Methods /// - /// Add a type prefix literal for the given EdmType. + /// Add a literal prefix for the given EdmType. /// /// filter=MyProperty eq MyCustomLiteral'VALUE'. - /// "MyCustomLiteral" is the literalPrefixName and the is the type of the "VALUE". - /// The custom name of the new type prefix literal name + /// "MyCustomLiteral" is the literal prefix and the is the type of the "VALUE". + /// The custom name of the literal prefix /// The edm type of the custom literal /// Arguments are null or empty /// The given literal prefix is not valid /// The given literal prefix already exists - public static void AddCustomUriTypePrefixLiteral(string typePrefixLiteralName, IEdmTypeReference literalEdmTypeReference) + public static void AddCustomLiteralPrefix(string literalPrefix, IEdmTypeReference literalEdmTypeReference) { // Arguments validation ExceptionUtils.CheckArgumentNotNull(literalEdmTypeReference, "literalEdmTypeReference"); - ExceptionUtils.CheckArgumentStringNotNullOrEmpty(typePrefixLiteralName, "typePrefixLiteralName"); + ExceptionUtils.CheckArgumentStringNotNullOrEmpty(literalPrefix, "literalPrefix"); - UriParserHelper.ValidatePrefixLiteral(typePrefixLiteralName); + UriParserHelper.ValidatePrefixLiteral(literalPrefix); // Try to add the custom uri literal to cache lock (Locker) { // Check if literal does already exists - if (PrefixLiteralsOfEdmTypes.ContainsKey(typePrefixLiteralName)) + if (CustomLiteralPrefixesOfEdmTypes.ContainsKey(literalPrefix)) { - throw new ODataException(ODataErrorStrings.CustomUriTypePrefixLiterals_AddCustomUriTypePrefixLiteralAlreadyExists(typePrefixLiteralName)); + throw new ODataException(ODataErrorStrings.CustomUriTypePrefixLiterals_AddCustomUriTypePrefixLiteralAlreadyExists(literalPrefix)); } - PrefixLiteralsOfEdmTypes.Add(typePrefixLiteralName, literalEdmTypeReference); + CustomLiteralPrefixesOfEdmTypes.Add(literalPrefix, literalEdmTypeReference); } } /// - /// Remove the given type prefix literal. + /// Remove the given literal prefix /// - /// The custom name of the new type prefix literal name - /// 'true' if the prefix literal is successfully found and removed; otherwise, 'false'. + /// The custom name of the literal prefix + /// 'true' if the literal prefix is successfully found and removed; otherwise, 'false'. /// Argument is null or empty - public static bool RemoveCustomUriTypePrefixLiteral(string typePrefixLiteralName) + public static bool RemoveCustomLiteralPrefix(string literalPrefix) { // Arguments validation - ExceptionUtils.CheckArgumentStringNotNullOrEmpty(typePrefixLiteralName, "typePrefixLiteralName"); + ExceptionUtils.CheckArgumentStringNotNullOrEmpty(literalPrefix, "literalPrefix"); - UriParserHelper.ValidatePrefixLiteral(typePrefixLiteralName); + UriParserHelper.ValidatePrefixLiteral(literalPrefix); - // Try to remove the custom uri literal from cache + // Try to remove the custom uri literal prefix from cache lock (Locker) { - return PrefixLiteralsOfEdmTypes.Remove(typePrefixLiteralName); + return CustomLiteralPrefixesOfEdmTypes.Remove(literalPrefix); } } @@ -89,18 +89,18 @@ public static bool RemoveCustomUriTypePrefixLiteral(string typePrefixLiteralName #region Internal Methods /// - /// Gets the EdmTypeReference of the given literal prefix name + /// Gets the EdmTypeReference of the given literal prefix /// - /// The prefix literal name of the EdmType - /// Null if the literal prefix has no registered custom EdmType. - internal static IEdmTypeReference GetCustomEdmTypeByLiteralPrefix(string typePrefixLiteralName) + /// The literal prefix of the EdmType + /// Null if the custom literal prefix has no registered EdmType. + internal static IEdmTypeReference GetEdmTypeByCustomLiteralPrefix(string literalPrefix) { lock (Locker) { - IEdmTypeReference customEdmTypeReference; - if (PrefixLiteralsOfEdmTypes.TryGetValue(typePrefixLiteralName, out customEdmTypeReference)) + IEdmTypeReference edmTypeReference; + if (CustomLiteralPrefixesOfEdmTypes.TryGetValue(literalPrefix, out edmTypeReference)) { - return customEdmTypeReference; + return edmTypeReference; } } diff --git a/src/Microsoft.OData.Core/UriParser/ExpressionLexer.cs b/src/Microsoft.OData.Core/UriParser/ExpressionLexer.cs index 3ccbb16398..7f36190461 100644 --- a/src/Microsoft.OData.Core/UriParser/ExpressionLexer.cs +++ b/src/Microsoft.OData.Core/UriParser/ExpressionLexer.cs @@ -733,7 +733,7 @@ private void HandleTypePrefixedLiterals() if (this.ch == '\'') { // Get custom literal if exists. - IEdmTypeReference edmTypeOfCustomLiteral = CustomUriTypePrefixLiterals.GetCustomEdmTypeByLiteralPrefix(this.token.Text); + IEdmTypeReference edmTypeOfCustomLiteral = CustomUriLiteralPrefixes.GetEdmTypeByCustomLiteralPrefix(this.token.Text); if (edmTypeOfCustomLiteral != null) { this.token.SetCustomEdmTypeLiteral(edmTypeOfCustomLiteral); diff --git a/src/Microsoft.OData.Core/UriParser/ExpressionLexerLiteralExtensions.cs b/src/Microsoft.OData.Core/UriParser/ExpressionLexerLiteralExtensions.cs index fe9306d17e..8d2d1e607f 100644 --- a/src/Microsoft.OData.Core/UriParser/ExpressionLexerLiteralExtensions.cs +++ b/src/Microsoft.OData.Core/UriParser/ExpressionLexerLiteralExtensions.cs @@ -10,8 +10,8 @@ namespace Microsoft.OData.Core.UriParser using System; using System.Diagnostics; - using Microsoft.OData.Core.UriParser.Parsers.TypeParsers; - using Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common; + using Microsoft.OData.Core.UriParser.Parsers; + using Microsoft.OData.Core.UriParser.Parsers.Common; using Microsoft.OData.Core.UriParser.TreeNodeKinds; using Microsoft.OData.Edm; using ODataErrorStrings = Microsoft.OData.Core.Strings; @@ -94,8 +94,8 @@ private static object ParseNullLiteral(this ExpressionLexer expressionLexer) /// The literal token produced by building the given literal. private static object ParseTypedLiteral(this ExpressionLexer expressionLexer, IEdmTypeReference targetTypeReference) { - UriTypeParsingException typeParsingException; - object targetValue = DefaultUriTypeParser.Instance.ParseUriStringToType(expressionLexer.CurrentToken.Text, targetTypeReference, out typeParsingException); + UriLiteralParsingException typeParsingException; + object targetValue = DefaultUriLiteralParser.Instance.ParseUriStringToType(expressionLexer.CurrentToken.Text, targetTypeReference, out typeParsingException); if (targetValue == null) { string message; @@ -117,7 +117,7 @@ private static object ParseTypedLiteral(this ExpressionLexer expressionLexer, IE expressionLexer.CurrentToken.Text, expressionLexer.CurrentToken.Position, expressionLexer.ExpressionText, - typeParsingException.ParsingFailureReason); + typeParsingException.Message); throw new ODataException(message, typeParsingException); } diff --git a/src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/Common/IUriTypeParser.cs b/src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/Common/IUriLiteralParser.cs similarity index 86% rename from src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/Common/IUriTypeParser.cs rename to src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/Common/IUriLiteralParser.cs index 76cb519402..6014888309 100644 --- a/src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/Common/IUriTypeParser.cs +++ b/src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/Common/IUriLiteralParser.cs @@ -1,10 +1,10 @@ //--------------------------------------------------------------------- -// +// // Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. // //--------------------------------------------------------------------- -namespace Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common +namespace Microsoft.OData.Core.UriParser.Parsers.Common { #region Namespaces @@ -13,11 +13,11 @@ namespace Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common #endregion /// - /// Interface for UriTypeParser. - /// To parse the uri of an OData request into objects, the ODataUriParser uses UriTypeParses. + /// Interface for Uri literal parser. + /// To parse the uri of an OData request into objects, the ODataUriParser uses UriLiteralParses. /// Implementation of this interface will parse a text of an EdmType to it's instance. /// - public interface IUriTypeParser + public interface IUriLiteralParser { /// /// Parse the given text of EdmType to it's object instance. @@ -28,7 +28,7 @@ public interface IUriTypeParser /// The type which the uri text has to be parsed to /// Assign the exception only in case the text could be parsed to the but failed during the parsing process /// If the parsing proceess has succeeded, returns the parsed object, otherwise returns 'Null' - object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriTypeParsingException parsingException); + object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriLiteralParsingException parsingException); // Consider add this API: // bool TryParseUriStringToType(string text, IEdmTypeReference targetType,out object targetValue, out UriTypeParsingException parsingException); diff --git a/src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/Common/UriTypeParsingException.cs b/src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/Common/UriLiteralParsingException.cs similarity index 52% rename from src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/Common/UriTypeParsingException.cs rename to src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/Common/UriLiteralParsingException.cs index 7276d60e46..7a4eb94c2a 100644 --- a/src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/Common/UriTypeParsingException.cs +++ b/src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/Common/UriLiteralParsingException.cs @@ -1,10 +1,10 @@ //--------------------------------------------------------------------- -// +// // Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. // //--------------------------------------------------------------------- -namespace Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common +namespace Microsoft.OData.Core.UriParser.Parsers.Common { #region Namespaces @@ -21,8 +21,8 @@ namespace Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common /// Throw this expcetion when the parser can parse the target type but failed to do so. /// Do not throw when parser is not able to parse the target type. /// - [DebuggerDisplay("{Message};{ParsingFailureReason}")] - public sealed class UriTypeParsingException : ODataException + [DebuggerDisplay("{Message}")] + public sealed class UriLiteralParsingException : ODataException { /// Creates a new instance of the class with default values. /// @@ -30,14 +30,14 @@ public sealed class UriTypeParsingException : ODataException /// that describes the error. This message takes into account the /// current system culture. /// - public UriTypeParsingException() + public UriLiteralParsingException() : base() { } /// Creates a new instance of the class with an error message. /// The plain text error message for this exception. - public UriTypeParsingException(string message) + public UriLiteralParsingException(string message) : base(message) { } @@ -45,36 +45,9 @@ public UriTypeParsingException(string message) /// Creates a new instance of the class with an error message and an inner exception. /// The plain text error message for this exception. /// The inner exception that is the cause of this exception to be thrown. - public UriTypeParsingException(string message, Exception innerException) + public UriLiteralParsingException(string message, Exception innerException) : base(message, innerException) { } - - /// - /// Creates an exception when parsing is failed. - /// - /// Exception message - /// The reason of parsing failure - public UriTypeParsingException(string message, string parsingFailureReason) - : this(message, null, parsingFailureReason) - { - } - - /// - /// Creates an exception when parsing is failed. - /// - /// Exception message - /// Inner Exception - /// The reason of parsing failure - public UriTypeParsingException(string message, Exception innerException, string parsingFailureReason) - : this(message, innerException) - { - this.ParsingFailureReason = parsingFailureReason; - } - - /// - /// The reason describing why the parsing process has failed. - /// - public string ParsingFailureReason { get; private set; } } } diff --git a/src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/UriCustomTypeParsers.cs b/src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/CustomUriLiteralParsers.cs similarity index 51% rename from src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/UriCustomTypeParsers.cs rename to src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/CustomUriLiteralParsers.cs index 40a4c9ea76..1829890d5e 100644 --- a/src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/UriCustomTypeParsers.cs +++ b/src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/CustomUriLiteralParsers.cs @@ -1,46 +1,46 @@ //--------------------------------------------------------------------- -// +// // Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. // //--------------------------------------------------------------------- -namespace Microsoft.OData.Core.UriParser.Parsers.TypeParsers +namespace Microsoft.OData.Core.UriParser.Parsers { #region Namespaces using System; using System.Collections.Generic; using System.Linq; - using Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common; + using Microsoft.OData.Core.UriParser.Parsers.Common; using Microsoft.OData.Edm; using ODataErrorStrings = Microsoft.OData.Core.Strings; #endregion /// - /// This class is the CustomTypeParser manager and parser. - /// Add a UriCustomTypeParser thourgh this class. - /// This class is also used as an UriTypeParser. + /// This class is the custom literal parser manager and parser. + /// Add a Uri custom literal parser through this class. + /// This class is also used as an UriLiteralParser. /// - public sealed class UriCustomTypeParsers : IUriTypeParser + public sealed class CustomUriLiteralParsers : IUriLiteralParser { #region Fields private static readonly object Locker = new object(); /// - /// Used for General UriTypeParsers. These parsers will be called for every text that has to parsed. + /// Used for General uri literal parsers. These parsers will be called for every text that has to parsed. /// The parses could parse multiple EdmTypes. /// - private static List CustomUriTypeParsers = new List(); + private static List customUriLiteralParsers = new List(); /// - /// "Registered" UriTypeParser to an EdmType. These parses will be called when the text has to be parsed to the + /// "Registered" uri literal parser to an EdmType. These parsers will be called when the text has to be parsed to the /// specific EdmType they had registered to. Each of these parsers could parse only one EdmType. Better performace. /// - private static List UriCustomTypeParserPerEdmType = new List(); + private static List customUriLiteralParserPerEdmType = new List(); - //// TODO: Consider use Dictionary which is a better solution. + //// TODO: Consider use Dictionary which is a better solution. //// The problem with dictionary is to generate an HashCode for an EdmTypeReference. #endregion @@ -48,19 +48,19 @@ public sealed class UriCustomTypeParsers : IUriTypeParser #region Singleton // Internal Singleton so only interal assemblies could parse by the custom parsers. - private static UriCustomTypeParsers singleInstance; + private static CustomUriLiteralParsers singleInstance; - private UriCustomTypeParsers() + private CustomUriLiteralParsers() { } - internal static UriCustomTypeParsers Instance + internal static CustomUriLiteralParsers Instance { get { if (singleInstance == null) { - singleInstance = new UriCustomTypeParsers(); + singleInstance = new CustomUriLiteralParsers(); } return singleInstance; @@ -69,11 +69,11 @@ internal static UriCustomTypeParsers Instance #endregion - #region IUriTypeParser Implementation - Internal + #region IUriLiteralParser Implementation - Internal /// /// Parse the given uri text. - /// Try to parse with a specific UriTypeParser regeistered for the target EdmType. + /// Try to parse with a specific Uri literal parser regeistered for the target EdmType. /// If no parser is registered, try to parse with the general parsers. /// This method is public becuase of the Interface, but the Singleton instance in internal so it could not be accessed by clients. /// @@ -81,25 +81,25 @@ internal static UriCustomTypeParsers Instance /// The type which the uri text has to be parsed to /// Assign the exception only in case the text could be parsed to the but failed during the parsing process /// If parsing proceess has succeeded, returns the parsed object, otherwise returns 'Null' - public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriTypeParsingException parsingException) + public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriLiteralParsingException parsingException) { object targetValue; lock (Locker) { - // Search for UriTypeParser which is registered for the given EdmType - IUriTypeParser uriTypeParserForEdmType = GetUriTypeParserByEdmType(targetType); - if (uriTypeParserForEdmType != null) + // Search for Uri literal parser which is registered for the given EdmType + IUriLiteralParser uriLiteralParserForEdmType = GetUriLiteralParserByEdmType(targetType); + if (uriLiteralParserForEdmType != null) { - return uriTypeParserForEdmType.ParseUriStringToType(text, targetType, out parsingException); + return uriLiteralParserForEdmType.ParseUriStringToType(text, targetType, out parsingException); } // Parse with all the general parsers // Stop when a parser succeeded parsing the text. - foreach (IUriTypeParser uriCustomTypeParser in CustomUriTypeParsers) + foreach (IUriLiteralParser customUriLiteralParser in customUriLiteralParsers) { // Try to parse - targetValue = uriCustomTypeParser.ParseUriStringToType(text, targetType, out parsingException); + targetValue = customUriLiteralParser.ParseUriStringToType(text, targetType, out parsingException); // The uriCustomParser could parse the given targetType but failed during the parsing proccess if (parsingException != null) @@ -125,37 +125,37 @@ public object ParseUriStringToType(string text, IEdmTypeReference targetType, ou #region Public Static Methods /// - /// Add a custom 'IUriTypeParser' which will be called to parse uri values during the uri parsing proccess. + /// Add a custom 'IUriLiteralParser' which will be called to parse uri values during the uri parsing proccess. /// - /// The custom uri parser - /// is null - /// The given IUriTypeParser instance already exists - public static void AddCustomUriTypeParser(IUriTypeParser uriCustomTypeParser) + /// The custom uri parser + /// is null + /// The given IUriLiteralParser instance already exists + public static void AddCustomUriLiteralParser(IUriLiteralParser customUriLiteralParser) { - ExceptionUtils.CheckArgumentNotNull(uriCustomTypeParser, "uriCustomTypeParser"); + ExceptionUtils.CheckArgumentNotNull(customUriLiteralParser, "customUriLiteralParser"); lock (Locker) { - if (CustomUriTypeParsers.Contains(uriCustomTypeParser)) + if (customUriLiteralParsers.Contains(customUriLiteralParser)) { throw new ODataException(ODataErrorStrings.UriCustomTypeParsers_AddCustomUriTypeParserAlreadyExists); } - CustomUriTypeParsers.Add(uriCustomTypeParser); + customUriLiteralParsers.Add(customUriLiteralParser); } } /// - /// Add a custom 'IUriTypeParser' which will be called to parse a value of the given EdmType during the UriParsing proccess. + /// Add a custom 'IUriLiteralParser' which will be called to parse a value of the given EdmType during the UriParsing proccess. /// - /// The EdmType the UriTypeParser can parse. - /// The custom uri type parser to add. - /// is null. + /// The EdmType the Uri literal parser can parse. + /// The custom uri type parser to add. + /// is null. /// is null. - /// Another UriTypeParser is already registered for the given EdmType - public static void AddCustomUriTypeParser(IEdmTypeReference edmTypeReference, IUriTypeParser uriCustomTypeParser) + /// Another Uri literal parser is already registered for the given EdmType + public static void AddCustomUriLiteralParser(IEdmTypeReference edmTypeReference, IUriLiteralParser customUriLiteralParser) { - ExceptionUtils.CheckArgumentNotNull(uriCustomTypeParser, "uriCustomTypeParser"); + ExceptionUtils.CheckArgumentNotNull(customUriLiteralParser, "customUriLiteralParser"); ExceptionUtils.CheckArgumentNotNull(edmTypeReference, "edmTypeReference"); lock (Locker) @@ -165,33 +165,33 @@ public static void AddCustomUriTypeParser(IEdmTypeReference edmTypeReference, IU throw new ODataException(ODataErrorStrings.UriCustomTypeParsers_AddCustomUriTypeParserEdmTypeExists(edmTypeReference.FullName())); } - UriCustomTypeParserPerEdmType.Add( - new UriTypeParserPerEdmType + customUriLiteralParserPerEdmType.Add( + new UriLiteralParserPerEdmType { EdmTypeOfUriParser = edmTypeReference, - UriTypeParser = uriCustomTypeParser + UriLiteralParser = customUriLiteralParser }); } } /// - /// Remove the given custom 'IUriTypeParser' form cache. + /// Remove the given custom 'IUriLiteralParser' form cache. /// It will be removed from both regular parsers and parsers registered with EdmType. /// - /// The custom uri type parser to remove + /// The custom uri type parser to remove /// 'False' if the given parser to remove doesn't exist. 'True' if the parser has successfully removed - /// UriTypeParser is null - public static bool RemoveCustomUriTypeParser(IUriTypeParser uriCustomTypeParser) + /// Uri literal parser is null + public static bool RemoveCustomUriLiteralParser(IUriLiteralParser customUriLiteralParser) { - ExceptionUtils.CheckArgumentNotNull(uriCustomTypeParser, "uriCustomTypeParser"); + ExceptionUtils.CheckArgumentNotNull(customUriLiteralParser, "customUriLiteralParser"); lock (Locker) { - // Remove parser from the UriCustmTypeParsers per EdmType. Same instance can be registered to multiple EdmTypes. - int numberOfParsersRemoved = UriCustomTypeParserPerEdmType.RemoveAll((parser) => parser.UriTypeParser.Equals(uriCustomTypeParser)); + // Remove parser from the customUriLiteralParserPerEdmType. Same instance can be registered to multiple EdmTypes. + int numberOfParsersRemoved = customUriLiteralParserPerEdmType.RemoveAll((parser) => parser.UriLiteralParser.Equals(customUriLiteralParser)); - // Remove parser from the general UriCustmTypeParsers. Same instacne can be add only once. - bool isGeneralParserRemoved = CustomUriTypeParsers.Remove(uriCustomTypeParser); + // Remove parser from the general custom uri literal parsers. Same instance can be add only once. + bool isGeneralParserRemoved = customUriLiteralParsers.Remove(customUriLiteralParser); // Returns 'True' if at least one parser has been removed from the general parser of those registered to EdmType return (numberOfParsersRemoved > 0) || isGeneralParserRemoved; @@ -204,32 +204,32 @@ public static bool RemoveCustomUriTypeParser(IUriTypeParser uriCustomTypeParser) private static bool IsEdmTypeAlreadyRegistered(IEdmTypeReference edmTypeReference) { - return UriCustomTypeParserPerEdmType.Any(uriParserOfEdmType => + return customUriLiteralParserPerEdmType.Any(uriParserOfEdmType => uriParserOfEdmType.EdmTypeOfUriParser.IsEquivalentTo(edmTypeReference)); } - private static IUriTypeParser GetUriTypeParserByEdmType(IEdmTypeReference edmTypeReference) + private static IUriLiteralParser GetUriLiteralParserByEdmType(IEdmTypeReference edmTypeReference) { - UriTypeParserPerEdmType requestedUriTypeParser = - UriCustomTypeParserPerEdmType.FirstOrDefault(uriParserOfEdmType => + UriLiteralParserPerEdmType requestedUriLiteralParser = + customUriLiteralParserPerEdmType.FirstOrDefault(uriParserOfEdmType => uriParserOfEdmType.EdmTypeOfUriParser.IsEquivalentTo(edmTypeReference)); - if (requestedUriTypeParser == null) + if (requestedUriLiteralParser == null) { return null; } - return requestedUriTypeParser.UriTypeParser; + return requestedUriLiteralParser.UriLiteralParser; } #endregion - private sealed class UriTypeParserPerEdmType + private sealed class UriLiteralParserPerEdmType { internal IEdmTypeReference EdmTypeOfUriParser { get; set; } - internal IUriTypeParser UriTypeParser { get; set; } + internal IUriLiteralParser UriLiteralParser { get; set; } } } } \ No newline at end of file diff --git a/src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/DefaultUriTypeParser.cs b/src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/DefaultUriLiteralParser.cs similarity index 71% rename from src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/DefaultUriTypeParser.cs rename to src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/DefaultUriLiteralParser.cs index ef0087b546..c92312c947 100644 --- a/src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/DefaultUriTypeParser.cs +++ b/src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/DefaultUriLiteralParser.cs @@ -1,43 +1,43 @@ //--------------------------------------------------------------------- -// +// // Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. // //--------------------------------------------------------------------- -namespace Microsoft.OData.Core.UriParser.Parsers.TypeParsers +namespace Microsoft.OData.Core.UriParser.Parsers { #region Namespaces using System.Collections.Generic; - using Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common; + using Microsoft.OData.Core.UriParser.Parsers.Common; using Microsoft.OData.Edm; #endregion - internal sealed class DefaultUriTypeParser : IUriTypeParser + internal sealed class DefaultUriLiteralParser : IUriLiteralParser { #region Fields - // All Uri Type Parsers - private List uriTypeParsers; + // All Uri Literal Parsers + private List uriTypeParsers; #endregion #region Singleton - private static DefaultUriTypeParser singleInstance = new DefaultUriTypeParser(); + private static DefaultUriLiteralParser singleInstance = new DefaultUriLiteralParser(); - private DefaultUriTypeParser() + private DefaultUriLiteralParser() { // It is important that UriCustomTypeParsers will be added first, so it will be called before the others built-in parsers - uriTypeParsers = new List + uriTypeParsers = new List { - { UriCustomTypeParsers.Instance }, + { CustomUriLiteralParsers.Instance }, { UriPrimitiveTypeParser.Instance } }; } - internal static DefaultUriTypeParser Instance + internal static DefaultUriLiteralParser Instance { get { @@ -47,7 +47,7 @@ internal static DefaultUriTypeParser Instance #endregion - #region IUriTypeParser Implementation + #region IUriLiteralParser Implementation /// /// Try to parse the given text by each parser. @@ -56,13 +56,13 @@ internal static DefaultUriTypeParser Instance /// The type which the uri text has to be parsed to /// Assign the exception only in case the text could be parsed to the but failed during the parsing process /// If the parsing proceess has succeeded, returns the parsed object, otherwise returns 'Null' - public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriTypeParsingException parsingException) + public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriLiteralParsingException parsingException) { parsingException = null; object targetValue; // Try to parse the uri text with each parser - foreach (IUriTypeParser uriTypeParser in uriTypeParsers) + foreach (IUriLiteralParser uriTypeParser in uriTypeParsers) { targetValue = uriTypeParser.ParseUriStringToType(text, targetType, out parsingException); diff --git a/src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/UriPrimitiveTypeParser.cs b/src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/UriPrimitiveTypeParser.cs similarity index 91% rename from src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/UriPrimitiveTypeParser.cs rename to src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/UriPrimitiveTypeParser.cs index e5bde02ee2..46db87fdc6 100644 --- a/src/Microsoft.OData.Core/UriParser/Parsers/TypeParsers/UriPrimitiveTypeParser.cs +++ b/src/Microsoft.OData.Core/UriParser/Parsers/LiteralParsers/UriPrimitiveTypeParser.cs @@ -4,7 +4,7 @@ // //--------------------------------------------------------------------- -namespace Microsoft.OData.Core.UriParser.Parsers.TypeParsers +namespace Microsoft.OData.Core.UriParser.Parsers { #region Namespaces @@ -15,7 +15,7 @@ namespace Microsoft.OData.Core.UriParser.Parsers.TypeParsers using System.Text; using System.Xml; using Microsoft.OData.Core.Metadata; - using Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common; + using Microsoft.OData.Core.UriParser.Parsers.Common; using Microsoft.OData.Core.UriParser.Parsers.UriParsers; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Library; @@ -27,7 +27,7 @@ namespace Microsoft.OData.Core.UriParser.Parsers.TypeParsers /// /// Parser which consumes the URI format of primitive types and converts it to primitive types. /// - internal sealed class UriPrimitiveTypeParser : IUriTypeParser + internal sealed class UriPrimitiveTypeParser : IUriLiteralParser { #region Singletons @@ -47,9 +47,9 @@ public static UriPrimitiveTypeParser Instance #endregion - #region IUriTypeParser Implementation + #region IUriLiteralParser Implementation - public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriTypeParsingException parsingException) + public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriLiteralParsingException parsingException) { object targetValue; @@ -65,7 +65,7 @@ public object ParseUriStringToType(string text, IEdmTypeReference targetType, ou #region Internal Methods - internal bool TryParseUriStringToType(string text, IEdmTypeReference targetType, out object targetValue, out UriTypeParsingException parsingException) + internal bool TryParseUriStringToType(string text, IEdmTypeReference targetType, out object targetValue, out UriLiteralParsingException parsingException) { return this.TryUriStringToPrimitive(text, targetType, out targetValue, out parsingException); } @@ -83,7 +83,7 @@ internal bool TryParseUriStringToType(string text, IEdmTypeReference targetType, /// Copy of the WebConvert.TryKeyStringToPrimitive [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Complexity is not too high; handling all the cases in one method is preferable to refactoring.")] [SuppressMessage("DataWeb.Usage", "AC0014:DoNotHandleProhibitedExceptionsRule", Justification = "We're calling this correctly")] - private bool TryUriStringToPrimitive(string text, IEdmTypeReference targetType, out object targetValue, out UriTypeParsingException exception) + private bool TryUriStringToPrimitive(string text, IEdmTypeReference targetType, out object targetValue, out UriLiteralParsingException exception) { Debug.Assert(text != null, "text != null"); Debug.Assert(targetType != null, "targetType != null"); @@ -260,7 +260,7 @@ private bool TryUriStringToPrimitive(string text, IEdmTypeReference targetType, } catch (Exception primitiveParserException) { - exception = new UriTypeParsingException( + exception = new UriLiteralParsingException( string.Format(CultureInfo.InvariantCulture, ODataErrorStrings.UriPrimitiveTypeParsers_FailedToParseTextToPrimitiveValue(text, targetType), primitiveParserException)); targetValue = null; @@ -277,7 +277,7 @@ private bool TryUriStringToPrimitive(string text, IEdmTypeReference targetType, [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Complexity is not too high; handling all the cases in one method is preferable to refactoring.")] private bool TryUriStringToPrimitive(string text, IEdmTypeReference targetType, out object targetValue) { - UriTypeParsingException exception; + UriLiteralParsingException exception; return TryUriStringToPrimitive(text, targetType, out targetValue, out exception); } @@ -355,11 +355,11 @@ private static bool TryUriStringToDuration(string text, out TimeSpan targetValue /// /// Text to parse. /// Geography to return. - /// The detailed reason of parsing error. + /// The detailed reason of parsing error. /// True if succeeds, false if not. - private static bool TryUriStringToGeography(string text, out Geography targetValue, out UriTypeParsingException parsingFailureReasonException) + private static bool TryUriStringToGeography(string text, out Geography targetValue, out UriLiteralParsingException parsingException) { - parsingFailureReasonException = null; + parsingException = null; if (!UriParserHelper.TryRemoveLiteralPrefix(ExpressionConstants.LiteralPrefixGeography, ref text)) { @@ -381,8 +381,7 @@ private static bool TryUriStringToGeography(string text, out Geography targetVal catch (ParseErrorException e) { targetValue = default(Geography); - parsingFailureReasonException = - new UriTypeParsingException(ODataErrorStrings.UriPrimitiveTypeParsers_FailedToParseStringToGeography, e.Message); + parsingException = new UriLiteralParsingException(e.Message); return false; } } @@ -394,7 +393,7 @@ private static bool TryUriStringToGeography(string text, out Geography targetVal /// Geometry to return. /// The detailed reason of parsing error. /// True if succeeds, false if not. - private static bool TryUriStringToGeometry(string text, out Geometry targetValue, out UriTypeParsingException parsingFailureReasonException) + private static bool TryUriStringToGeometry(string text, out Geometry targetValue, out UriLiteralParsingException parsingFailureReasonException) { parsingFailureReasonException = null; @@ -418,8 +417,9 @@ private static bool TryUriStringToGeometry(string text, out Geometry targetValue catch (ParseErrorException e) { targetValue = default(Geometry); + parsingFailureReasonException = - new UriTypeParsingException("Failed to parse string to 'Geometry'", e.Message); + new UriLiteralParsingException(e.Message); return false; } } diff --git a/src/Microsoft.OData.Core/UriParser/Parsers/UriQueryExpressionParser.cs b/src/Microsoft.OData.Core/UriParser/Parsers/UriQueryExpressionParser.cs index 3da19703c8..99e505e801 100644 --- a/src/Microsoft.OData.Core/UriParser/Parsers/UriQueryExpressionParser.cs +++ b/src/Microsoft.OData.Core/UriParser/Parsers/UriQueryExpressionParser.cs @@ -11,13 +11,13 @@ namespace Microsoft.OData.Core.UriParser.Parsers using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; - using Microsoft.OData.Core.UriParser.Parsers.TypeParsers; - using Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common; - using Microsoft.OData.Core.UriParser.Syntactic; + using Microsoft.OData.Core.UriParser.Parsers; + using Microsoft.OData.Core.UriParser.Parsers.Common; + using Microsoft.OData.Core.UriParser.Syntactic; using Microsoft.OData.Core.UriParser.Aggregation; using Microsoft.OData.Core.UriParser.TreeNodeKinds; using Microsoft.OData.Edm; - using Microsoft.OData.Edm.Library; + using Microsoft.OData.Edm.Library; using ODataErrorStrings = Microsoft.OData.Core.Strings; #endregion Namespaces @@ -153,7 +153,7 @@ internal static LiteralToken TryParseLiteral(ExpressionLexer lexer) internal static string GetEdmConstantNames(IEdmTypeReference edmTypeReference) { Debug.Assert(edmTypeReference != null, "Cannot be null"); - + switch (edmTypeReference.PrimitiveKind()) { case EdmPrimitiveTypeKind.Boolean: @@ -481,11 +481,11 @@ private static Exception ParseError(string message) /// Creates an exception for a parse error. /// Message text. - /// Type Parsing exception + /// Type Parsing exception /// A new Exception. - private static Exception ParseError(string message, UriTypeParsingException parseException) + private static Exception ParseError(string message, UriLiteralParsingException parsingException) { - return new ODataException(message, parseException); + return new ODataException(message, parsingException); } /// @@ -512,8 +512,8 @@ private static LiteralToken ParseTypedLiteral(ExpressionLexer lexer, IEdmTypeRef { Debug.Assert(lexer != null, "lexer != null"); - UriTypeParsingException typeParsingException; - object targetValue = DefaultUriTypeParser.Instance.ParseUriStringToType(lexer.CurrentToken.Text, targetTypeReference, out typeParsingException); + UriLiteralParsingException typeParsingException; + object targetValue = DefaultUriLiteralParser.Instance.ParseUriStringToType(lexer.CurrentToken.Text, targetTypeReference, out typeParsingException); if (targetValue == null) { @@ -536,7 +536,7 @@ private static LiteralToken ParseTypedLiteral(ExpressionLexer lexer, IEdmTypeRef lexer.CurrentToken.Text, lexer.CurrentToken.Position, lexer.ExpressionText, - typeParsingException.ParsingFailureReason); + typeParsingException.Message); throw ParseError(message, typeParsingException); } diff --git a/test/FunctionalTests/Microsoft.OData.Core.Tests/Microsoft.OData.Core.Tests.csproj b/test/FunctionalTests/Microsoft.OData.Core.Tests/Microsoft.OData.Core.Tests.csproj index 3b2b6fade9..cb4112963e 100644 --- a/test/FunctionalTests/Microsoft.OData.Core.Tests/Microsoft.OData.Core.Tests.csproj +++ b/test/FunctionalTests/Microsoft.OData.Core.Tests/Microsoft.OData.Core.Tests.csproj @@ -322,8 +322,8 @@ - - + + diff --git a/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/CustomUriFunctionsTests.cs b/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/CustomUriFunctionsTests.cs index ab84bf64c5..9ac15fc326 100644 --- a/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/CustomUriFunctionsTests.cs +++ b/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/CustomUriFunctionsTests.cs @@ -82,31 +82,6 @@ public void AddCustomFunction_CannotAddFunctionSignatureWithNullReturnType() #endregion - [Fact] - public void AddCustomFunction_CannotAddFunctionWithNameAlreadyExistsAsBuildIsFunction_AddAsOverloadFalse_SameNameDifferentArguments() - { - FunctionSignatureWithReturnType customFunctionSignature = - new FunctionSignatureWithReturnType(EdmCoreModel.Instance.GetDouble(false), - EdmCoreModel.Instance.GetBoolean(false)); - - Action addExistingCustomFunctionSignature = () => - CustomUriFunctions.AddCustomUriFunction(BUILT_IN_GEODISTANCE_FUNCTION_NAME, customFunctionSignature); - - addExistingCustomFunctionSignature.ShouldThrow(). - WithMessage(Strings.CustomUriFunctions_AddCustomUriFunction_BuiltInExistsNotAddingAsOverload(BUILT_IN_GEODISTANCE_FUNCTION_NAME)); - } - - [Fact] - public void AddCustomFunction_CannotAddFunctionWithNameAlreadyExistsAsBuildIsFunction_AddAsOverloadFalse_SameNameSameArguments() - { - Action addExistingCustomFunctionSignature = () => - CustomUriFunctions.AddCustomUriFunction(BUILT_IN_GEODISTANCE_FUNCTION_NAME, - GEO_DISTANCE_BUILTIN_FUNCTION_SIGNATURE); - - addExistingCustomFunctionSignature.ShouldThrow(). - WithMessage(Strings.CustomUriFunctions_AddCustomUriFunction_BuiltInExistsNotAddingAsOverload(BUILT_IN_GEODISTANCE_FUNCTION_NAME)); - } - [Fact] public void AddCustomFunction_CannotAddFunctionWhichAlreadyExistsAsBuiltInWithSameFullSignature_AddAsOverload() { @@ -115,8 +90,7 @@ public void AddCustomFunction_CannotAddFunctionWhichAlreadyExistsAsBuiltInWithSa // Add exisiting with 'addAsOverload' 'true' Action addCustomFunction = () => CustomUriFunctions.AddCustomUriFunction(BUILT_IN_GEODISTANCE_FUNCTION_NAME, - GEO_DISTANCE_BUILTIN_FUNCTION_SIGNATURE, - true); + GEO_DISTANCE_BUILTIN_FUNCTION_SIGNATURE); // Assert addCustomFunction.ShouldThrow(). @@ -139,7 +113,7 @@ public void AddCustomFunction_ShouldAddFunctionWhichAlreadyExistsAsBuiltInWithSa EdmCoreModel.Instance.GetBoolean(false)); // Add with 'addAsOverload' 'true' - CustomUriFunctions.AddCustomUriFunction(BUILT_IN_GEODISTANCE_FUNCTION_NAME, customFunctionSignature, true); + CustomUriFunctions.AddCustomUriFunction(BUILT_IN_GEODISTANCE_FUNCTION_NAME, customFunctionSignature); FunctionSignatureWithReturnType[] resultFunctionSignaturesWithReturnType = this.GetCustomFunctionSignaturesOrNull(BUILT_IN_GEODISTANCE_FUNCTION_NAME); @@ -198,7 +172,7 @@ public void AddCustomFunction_CannotAddFunctionWithFullSignatureExistsAsCustomFu var newCustomFunctionSignature = new FunctionSignatureWithReturnType(EdmCoreModel.Instance.GetDouble(false), EdmCoreModel.Instance.GetBoolean(false)); Action addCustomFunction = () => - CustomUriFunctions.AddCustomUriFunction(customFunctionName, newCustomFunctionSignature, true); + CustomUriFunctions.AddCustomUriFunction(customFunctionName, newCustomFunctionSignature); // Asserts addCustomFunction.ShouldThrow(). @@ -224,7 +198,7 @@ public void AddCustomFunction_CustomFunctionDoesntExist_ShouldAdd() // Assert // Make sure both signatures exists - FunctionSignatureWithReturnType[] customFunctionSignatures = + FunctionSignatureWithReturnType[] customFunctionSignatures = GetCustomFunctionSignaturesOrNull(customFunctionName); customFunctionSignatures.Length.Should().Be(1); @@ -487,7 +461,7 @@ public void RemoveCustomFunction_RemoveFunctionWithSameNameAndSignature_OtherOve // Validate that the two overloads as GetCustomFunctionSignaturesOrNull(customFunctionName). - All(funcSignature => funcSignature.Equals(existingCustomFunctionSignature) || + All(funcSignature => funcSignature.Equals(existingCustomFunctionSignature) || funcSignature.Equals(existingCustomFunctionSignatureTwo)). Should().BeTrue(); @@ -539,14 +513,14 @@ FunctionSignatureWithReturnType myStringFunction [Fact] public void ParseWithCustomUriFunction_AddAsOverloadToBuiltIn() { - FunctionSignatureWithReturnType customStartWithFunctionSignature = + FunctionSignatureWithReturnType customStartWithFunctionSignature = new FunctionSignatureWithReturnType(EdmCoreModel.Instance.GetBoolean(true), EdmCoreModel.Instance.GetString(true), EdmCoreModel.Instance.GetInt32(true)); try { // Add with override 'true' - CustomUriFunctions.AddCustomUriFunction("startswith", customStartWithFunctionSignature, true); + CustomUriFunctions.AddCustomUriFunction("startswith", customStartWithFunctionSignature); var fullUri = new Uri("http://www.odata.com/OData/People" + "?$filter=startswith(Name, 66)"); ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri); diff --git a/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/ParsePrimitiveValuesTests.cs b/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/ParsePrimitiveValuesTests.cs index 53782b5f52..65811ce3c3 100644 --- a/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/ParsePrimitiveValuesTests.cs +++ b/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/ParsePrimitiveValuesTests.cs @@ -6,8 +6,8 @@ using System; using FluentAssertions; -using Microsoft.OData.Core.UriParser.Parsers.TypeParsers; -using Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common; +using Microsoft.OData.Core.UriParser.Parsers; +using Microsoft.OData.Core.UriParser.Parsers.Common; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Library; using Xunit; @@ -57,7 +57,7 @@ private static bool TryParse(string input, IEdmPrimitiveTypeReference asType, realResult = default(T); object result; - UriTypeParsingException exception; + UriLiteralParsingException exception; bool parseSuceeded = UriPrimitiveTypeParser.Instance.TryParseUriStringToType(input, asType, out result, out exception); if (parseSuceeded) { diff --git a/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Binders/FunctionCallBinderTests.cs b/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Binders/FunctionCallBinderTests.cs index dd24851b54..cf8b90723e 100644 --- a/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Binders/FunctionCallBinderTests.cs +++ b/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Binders/FunctionCallBinderTests.cs @@ -1268,9 +1268,8 @@ public void GetUriFunction_CombineCustomFunctionsAndBuiltInFunctions() EdmCoreModel.Instance.GetBoolean(false)); // Add with 'addAsOverload' 'true' - CustomUriFunctions.AddCustomUriFunction(BUILT_IN_GEODISTANCE_FUNCTION_NAME, customFunctionSignature, true); + CustomUriFunctions.AddCustomUriFunction(BUILT_IN_GEODISTANCE_FUNCTION_NAME, customFunctionSignature); - FunctionSignatureWithReturnType[] resultUriFunctionSignatures = FunctionCallBinder.GetUriFunctionSignatures(BUILT_IN_GEODISTANCE_FUNCTION_NAME); diff --git a/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/UriCustomTypeParserTests.cs b/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/CustomUriLiteralParserTests.cs similarity index 51% rename from test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/UriCustomTypeParserTests.cs rename to test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/CustomUriLiteralParserTests.cs index 256046d542..627ea7806f 100644 --- a/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/UriCustomTypeParserTests.cs +++ b/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/CustomUriLiteralParserTests.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using FluentAssertions; using Microsoft.OData.Core.UriParser; -using Microsoft.OData.Core.UriParser.Parsers.TypeParsers; -using Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common; +using Microsoft.OData.Core.UriParser.Parsers; +using Microsoft.OData.Core.UriParser.Parsers.Common; using Microsoft.OData.Core.UriParser.Parsers.UriParsers; using Microsoft.OData.Core.UriParser.Semantic; using Microsoft.OData.Core.UriParser.TreeNodeKinds; @@ -14,9 +14,9 @@ namespace Microsoft.OData.Core.Tests.UriParser.Parsers { /// - /// Test the public API of UriCustomTypeParser class + /// Test the public API of CustomUriLiteralParser class /// - public class UriCustomTypeParserUnitTests + public class CustomUriLiteralParserUnitTests { #region Consts @@ -34,64 +34,64 @@ public class UriCustomTypeParserUnitTests public const string CUSTOM_PARSER_STRING_VALUE_CAUSEBUG = "StringValueWithBug"; - public const string BOOLEAN_TYPE_PREFIX_LITERAL = "myCustomBooleanTypePrefixLiteral"; + public const string BOOLEAN_LITERAL_PREFIX = "myCustomBooleanTypePrefixLiteral"; - public const string STRING_TYPE_PREFIX_LITERAL = "myCustomStringTypePrefixLiteral"; + public const string STRING_LITERAL_PREFIX = "myCustomStringTypePrefixLiteral"; #endregion - #region AddCustomUriTypeParser Method + #region AddCustomUriLiteralParser Method [Fact] - public void AddCustomUriTypeParser_CannotAddNullTypeParser() + public void AddCustomUriLiteralParser_CannotAddNullLiteralParser() { - Action addNullCustomUriTypeParser = () => - UriCustomTypeParsers.AddCustomUriTypeParser(null); + Action addNullCustomUriLiteralParser = () => + CustomUriLiteralParsers.AddCustomUriLiteralParser(null); - addNullCustomUriTypeParser.ShouldThrow(); + addNullCustomUriLiteralParser.ShouldThrow(); } [Fact] - public void AddCustomUriTypeParser_CannotAddNullTypeParserAndNullEdmTypeReference() + public void AddCustomUriLiteralParser_CannotAddNullLiteralParserAndNullEdmTypeReference() { - Action addNullCustomUriTypeParserAndNullParser = () => - UriCustomTypeParsers.AddCustomUriTypeParser(null, null); + Action addNullCustomUriLiteralParserAndNullParser = () => + CustomUriLiteralParsers.AddCustomUriLiteralParser(null, null); - addNullCustomUriTypeParserAndNullParser.ShouldThrow(); + addNullCustomUriLiteralParserAndNullParser.ShouldThrow(); } [Fact] - public void AddCustomUriTypeParser_CannotAddNullTypeParserWithEdmType() + public void AddCustomUriLiteralParser_CannotAddNullLiteralParserWithEdmType() { IEdmTypeReference typeReference = EdmCoreModel.Instance.GetBoolean(false); - Action addNullCustomUriTypeParser = () => - UriCustomTypeParsers.AddCustomUriTypeParser(typeReference, null); + Action addNullCustomUriLiteralParser = () => + CustomUriLiteralParsers.AddCustomUriLiteralParser(typeReference, null); - addNullCustomUriTypeParser.ShouldThrow(); + addNullCustomUriLiteralParser.ShouldThrow(); } [Fact] - public void AddCustomUriTypeParser_CannotAddNullEdmTypeReferenceWithTypeParser() + public void AddCustomUriLiteralParser_CannotAddNullEdmTypeReferenceWithLiteralParser() { - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = - new MyCustomBooleanUriTypeParser(); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = + new MyCustomBooleanUriLiteralParser(); - Action addCustomUriTypeParserWithNullEdmType = () => - UriCustomTypeParsers.AddCustomUriTypeParser(null, customBooleanUriTypePraser); + Action addCustomUriLiteralParserWithNullEdmType = () => + CustomUriLiteralParsers.AddCustomUriLiteralParser(null, customBooleanUriTypePraser); - addCustomUriTypeParserWithNullEdmType.ShouldThrow(); + addCustomUriLiteralParserWithNullEdmType.ShouldThrow(); } [Fact] - public void AddCustomUriTypeParser_GeneralParsers_CanAdd() + public void AddCustomUriLiteralParser_GeneralParsers_CanAdd() { - RegisterTestCase("AddCustomUriTypeParser_GeneralParsers_CanAdd"); - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + RegisterTestCase("AddCustomUriLiteralParser_GeneralParsers_CanAdd"); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); try { - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser); // Test of custom parser is working this.ParseNonConvetionalBooleanValueSuccessfully(); @@ -99,21 +99,22 @@ public void AddCustomUriTypeParser_GeneralParsers_CanAdd() finally { // Clean up from cache - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } [Fact] - public void AddCustomUriTypeParser_GeneralParsers_CanAddMultipleDifferentInstances() + public void AddCustomUriLiteralParser_GeneralParsers_CanAddMultipleDifferentInstances() { - IUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); - IUriTypeParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriTypeParser(); + RegisterTestCase("AddCustomUriLiteralParser_GeneralParsers_CanAddMultipleDifferentInstances"); + IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); + IUriLiteralParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriLiteralParser(); try { - // Add two different instances to GeneralTypeParsers - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanUriTypePraser); - UriCustomTypeParsers.AddCustomUriTypeParser(customIntBooleanUriTypePraser); + // Add two different instances to GeneralLiteralParsers + CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(customIntBooleanUriTypePraser); // Test of custom parser is working this.ParseNonConvetionalBooleanValueSuccessfully(); @@ -122,69 +123,69 @@ public void AddCustomUriTypeParser_GeneralParsers_CanAddMultipleDifferentInstanc finally { // Clean up from cache - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); - UriCustomTypeParsers.RemoveCustomUriTypeParser(customIntBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customIntBooleanUriTypePraser).Should().BeTrue(); } } [Fact] - public void AddCustomUriTypeParser_GeneralParsers_CannotAddToGeneraldIfSameInstanceAlreadyExists() + public void AddCustomUriLiteralParser_GeneralParsers_CannotAddToGeneraldIfSameInstanceAlreadyExists() { - RegisterTestCase("AddCustomUriTypeParser_GeneralParsers_CannotAddToGeneraldIfSameInstanceAlreadyExists"); - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + RegisterTestCase("AddCustomUriLiteralParser_GeneralParsers_CannotAddToGeneraldIfSameInstanceAlreadyExists"); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); try { // Add Once - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser); // Add again - Should throw exception - Action addCustomUriTypeParser = () => - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanUriTypePraser); + Action addCustomUriLiteralParser = () => + CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser); - addCustomUriTypeParser.ShouldThrow(). + addCustomUriLiteralParser.ShouldThrow(). WithMessage(Strings.UriCustomTypeParsers_AddCustomUriTypeParserAlreadyExists); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } [Fact] - public void AddCustomUriTypeParser_RegisterToEdmType_CanAddCustomParser() + public void AddCustomUriLiteralParser_RegisterToEdmType_CanAddCustomParser() { - RegisterTestCase("AddCustomUriTypeParser_RegisterToEdmType_CanAddCustomParser"); - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + RegisterTestCase("AddCustomUriLiteralParser_RegisterToEdmType_CanAddCustomParser"); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); try { - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); // Test of custom parser is working this.ParseNonConvetionalBooleanValueSuccessfully(); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } [Fact] - public void AddCustomUriTypeParser_RegisterToEdmType_CanAddMultipleDifferentInstances() + public void AddCustomUriLiteralParser_RegisterToEdmType_CanAddMultipleDifferentInstances() { - RegisterTestCase("AddCustomUriTypeParser_RegisterToEdmType_CanAddMultipleDifferentInstances"); - IUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + RegisterTestCase("AddCustomUriLiteralParser_RegisterToEdmType_CanAddMultipleDifferentInstances"); + IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - IUriTypeParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriTypeParser(); + IUriLiteralParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriLiteralParser(); IEdmTypeReference intEdmTypeReference = EdmCoreModel.Instance.GetInt32(false); try { - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); - UriCustomTypeParsers.AddCustomUriTypeParser(intEdmTypeReference, customIntBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(intEdmTypeReference, customIntBooleanUriTypePraser); // Test of custom parser is working this.ParseNonConvetionalBooleanValueSuccessfully(); @@ -192,50 +193,50 @@ public void AddCustomUriTypeParser_RegisterToEdmType_CanAddMultipleDifferentInst } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); - UriCustomTypeParsers.RemoveCustomUriTypeParser(customIntBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customIntBooleanUriTypePraser).Should().BeTrue(); } } [Fact] - public void AddCustomUriTypeParser_RegisterToEdmType_CannotAddIfAlreadyRegistedToTheSameEdmType() + public void AddCustomUriLiteralParser_RegisterToEdmType_CannotAddIfAlreadyRegistedToTheSameEdmType() { - RegisterTestCase("AddCustomUriTypeParser_RegisterToEdmType_CannotAddIfAlreadyRegistedToTheSameEdmType"); - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + RegisterTestCase("AddCustomUriLiteralParser_RegisterToEdmType_CannotAddIfAlreadyRegistedToTheSameEdmType"); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); try { // Add once - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); // Add again - Should throw exception - Action addCustomUriTypeParser = () => - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + Action addCustomUriLiteralParser = () => + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); - addCustomUriTypeParser.ShouldThrow(). + addCustomUriLiteralParser.ShouldThrow(). WithMessage(Strings.UriCustomTypeParsers_AddCustomUriTypeParserEdmTypeExists(booleanTypeReference.FullName())); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } [Fact] - public void AddCustomUriTypeParser_RegisterToEdmType_CanAddIfSameParserInstanceExistsButRegisteredToDifferentEdmType() + public void AddCustomUriLiteralParser_RegisterToEdmType_CanAddIfSameParserInstanceExistsButRegisteredToDifferentEdmType() { - RegisterTestCase("AddCustomUriTypeParser_RegisterToEdmType_CanAddIfSameParserInstanceExistsButRegisteredToDifferentEdmType"); - IUriTypeParser customIntAndBooleanUriTypePraser = new MyCustomIntAndBooleanUriTypeParser(); + RegisterTestCase("AddCustomUriLiteralParser_RegisterToEdmType_CanAddIfSameParserInstanceExistsButRegisteredToDifferentEdmType"); + IUriLiteralParser customIntAndBooleanUriTypePraser = new MyCustomIntAndBooleanUriLiteralParser(); try { // Add once IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customIntAndBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customIntAndBooleanUriTypePraser); // Add same type converter but registered to a different EdmType(string instead of boolean) IEdmTypeReference intTypeReference = EdmCoreModel.Instance.GetInt32(false); - UriCustomTypeParsers.AddCustomUriTypeParser(intTypeReference, customIntAndBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(intTypeReference, customIntAndBooleanUriTypePraser); // Test of custom parser is working this.ParseNonConvetionalBooleanValueSuccessfully(); @@ -243,75 +244,75 @@ public void AddCustomUriTypeParser_RegisterToEdmType_CanAddIfSameParserInstanceE } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customIntAndBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customIntAndBooleanUriTypePraser).Should().BeTrue(); } } [Fact] - public void AddCustomUriTypeParser_RegisterToEdmType_CanAddIfSameParserInstanceExistsAsGeneralTypeParser() + public void AddCustomUriLiteralParser_RegisterToEdmType_CanAddIfSameParserInstanceExistsAsGeneralLiteralParser() { - RegisterTestCase("AddCustomUriTypeParser_RegisterToEdmType_CanAddIfSameParserInstanceExistsAsGeneralTypeParser"); - IUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + RegisterTestCase("AddCustomUriLiteralParser_RegisterToEdmType_CanAddIfSameParserInstanceExistsAsGeneralLiteralParser"); + IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); try { - // Add once as general TypeParser (with no specific EdmType) - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanUriTypePraser); + // Add once as general LiteralParser (with no specific EdmType) + CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser); // Add again with registered EdmType IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); // Test of custom parser is working this.ParseNonConvetionalBooleanValueSuccessfully(); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } [Fact] - public void AddCustomUriTypeParser_GeneralParsers_CanAddIfSameParserInstanceAlreadyRegisteredToEdmType() + public void AddCustomUriLiteralParser_GeneralParsers_CanAddIfSameParserInstanceAlreadyRegisteredToEdmType() { - RegisterTestCase("AddCustomUriTypeParser_GeneralParsers_CanAddIfSameParserInstanceAlreadyRegisteredToEdmType"); - IUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + RegisterTestCase("AddCustomUriLiteralParser_GeneralParsers_CanAddIfSameParserInstanceAlreadyRegisteredToEdmType"); + IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); try { // Add once with registered EdmType IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); - // Add again as general TypeParser (with no specific EdmType) - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanUriTypePraser); + // Add again as general LiteralParser (with no specific EdmType) + CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser); // Test of custom parser is working this.ParseNonConvetionalBooleanValueSuccessfully(); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } [Fact] - public void AddCustomUriTypeParser_CanAddMultipleDifferentInstancesToRegisteredAndGeneral() + public void AddCustomUriLiteralParser_CanAddMultipleDifferentInstancesToRegisteredAndGeneral() { - RegisterTestCase("AddCustomUriTypeParser_CanAddMultipleDifferentInstancesToRegisteredAndGeneral"); + RegisterTestCase("AddCustomUriLiteralParser_CanAddMultipleDifferentInstancesToRegisteredAndGeneral"); - IUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - IUriTypeParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriTypeParser(); + IUriLiteralParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriLiteralParser(); try { // Add to registered edm types - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); // Add to general parsers - UriCustomTypeParsers.AddCustomUriTypeParser(customIntBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(customIntBooleanUriTypePraser); // Test of custom parser is working this.ParseNonConvetionalBooleanValueSuccessfully(); @@ -319,16 +320,16 @@ public void AddCustomUriTypeParser_CanAddMultipleDifferentInstancesToRegisteredA } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); - UriCustomTypeParsers.RemoveCustomUriTypeParser(customIntBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customIntBooleanUriTypePraser).Should().BeTrue(); } } #endregion - #region RemoveCustomUriTypeParser Method + #region RemoveCustomUriLiteralParser Method - // ** Test 'RemoveCustomUriTypeParser' Method ** + // ** Test 'RemoveCustomUriLiteralParser' Method ** // Remove Validation // Cannot remove parser which is not added @@ -338,47 +339,47 @@ public void AddCustomUriTypeParser_CanAddMultipleDifferentInstancesToRegisteredA // Can remove if exists in general and 2 in registred [Fact] - public void RemoveCustomUriTypeParser_CannotRemoveNull() + public void RemoveCustomUriLiteralParser_CannotRemoveNull() { - Action removeNullCustomUriTypeParser = () => - UriCustomTypeParsers.RemoveCustomUriTypeParser(null); + Action removeNullCustomUriLiteralParser = () => + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(null); - removeNullCustomUriTypeParser.ShouldThrow(); + removeNullCustomUriLiteralParser.ShouldThrow(); } [Fact] - public void RemoveCustomUriTypeParser_CannotRemoveNotExistingParser() + public void RemoveCustomUriLiteralParser_CannotRemoveNotExistingParser() { - IUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); - bool isRemoveSucceeded = UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser); + IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); + bool isRemoveSucceeded = CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser); // Assert isRemoveSucceeded.Should().BeFalse(); } [Fact] - public void RemoveCustomUriTypeParser_CanRemoveGeneralParser() + public void RemoveCustomUriLiteralParser_CanRemoveGeneralParser() { - RegisterTestCase("RemoveCustomUriTypeParser_CanRemoveGeneralParser"); - IUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanUriTypePraser); + RegisterTestCase("RemoveCustomUriLiteralParser_CanRemoveGeneralParser"); + IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); + CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser); - bool isRemoved = UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser); + bool isRemoved = CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser); isRemoved.Should().BeTrue(); this.NoParsesForNonConvetionalBooleanValue(); } [Fact] - public void RemoveCustomUriTypeParser_CanRemoveParserWhichIsRegisteredToEdmType() + public void RemoveCustomUriLiteralParser_CanRemoveParserWhichIsRegisteredToEdmType() { - RegisterTestCase("RemoveCustomUriTypeParser_CanRemoveParserWhichIsRegisteredToEdmType"); - IUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + RegisterTestCase("RemoveCustomUriLiteralParser_CanRemoveParserWhichIsRegisteredToEdmType"); + IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); - bool isRemoved = UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser); + bool isRemoved = CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser); isRemoved.Should().BeTrue(); this.NoParsesForNonConvetionalBooleanValue(); @@ -388,16 +389,16 @@ public void RemoveCustomUriTypeParser_CanRemoveParserWhichIsRegisteredToEdmType( /// Should remove both from registered and general parsers. /// [Fact] - public void RemoveCustomUriTypeParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndRegistedWithEdmType() + public void RemoveCustomUriLiteralParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndRegistedWithEdmType() { - RegisterTestCase("RemoveCustomUriTypeParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndRegistedWithEdmType"); - IUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + RegisterTestCase("RemoveCustomUriLiteralParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndRegistedWithEdmType"); + IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanUriTypePraser); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); - bool isRemoved = UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser); + bool isRemoved = CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser); isRemoved.Should().BeTrue(); this.NoParsesForNonConvetionalBooleanValue(); @@ -407,18 +408,18 @@ public void RemoveCustomUriTypeParser_CanRemoveSameInstanceOfParserAddedAsGenera /// Should remove both from registered and general parsers. /// [Fact] - public void RemoveCustomUriTypeParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndMultipleRegistedWithEdmType() + public void RemoveCustomUriLiteralParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndMultipleRegistedWithEdmType() { - RegisterTestCase("RemoveCustomUriTypeParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndMultipleRegistedWithEdmType"); - IUriTypeParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriTypeParser(); + RegisterTestCase("RemoveCustomUriLiteralParser_CanRemoveSameInstanceOfParserAddedAsGeneralAndMultipleRegistedWithEdmType"); + IUriLiteralParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriLiteralParser(); IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); IEdmTypeReference intTypeReference = EdmCoreModel.Instance.GetInt32(false); - UriCustomTypeParsers.AddCustomUriTypeParser(customIntBooleanUriTypePraser); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customIntBooleanUriTypePraser); - UriCustomTypeParsers.AddCustomUriTypeParser(intTypeReference, customIntBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(customIntBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customIntBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(intTypeReference, customIntBooleanUriTypePraser); - bool isRemoved = UriCustomTypeParsers.RemoveCustomUriTypeParser(customIntBooleanUriTypePraser); + bool isRemoved = CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customIntBooleanUriTypePraser); isRemoved.Should().BeTrue(); this.NoParsesForNonConvetionalBooleanValue(); @@ -443,15 +444,15 @@ public void RemoveCustomUriTypeParser_CanRemoveSameInstanceOfParserAddedAsGenera public void ParseUriStringToType_GeneralParsers_ValidValue_ParsingSucceeded() { RegisterTestCase("ParseUriStringToType_GeneralParsers_ValidValue_ParsingSucceeded"); - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); try { // Add to general parsers - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser); IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE, EdmCoreModel.Instance.GetBoolean(false), out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE, EdmCoreModel.Instance.GetBoolean(false), out exception); // Assert exception.Should().BeNull(); @@ -459,7 +460,7 @@ public void ParseUriStringToType_GeneralParsers_ValidValue_ParsingSucceeded() } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } @@ -467,15 +468,15 @@ public void ParseUriStringToType_GeneralParsers_ValidValue_ParsingSucceeded() public void ParseUriStringToType_GeneralParsers_InvalidValue_ParsingHasFailed() { RegisterTestCase("ParseUriStringToType_GeneralParsers_InvalidValue_ParsingHasFailed"); - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); try { // Add to general parsers - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser); IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, EdmCoreModel.Instance.GetBoolean(false), out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, EdmCoreModel.Instance.GetBoolean(false), out exception); // Assert output.Should().BeNull(); @@ -485,11 +486,11 @@ public void ParseUriStringToType_GeneralParsers_InvalidValue_ParsingHasFailed() throw exception; }; - action.ShouldThrow(); + action.ShouldThrow(); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } @@ -497,13 +498,13 @@ public void ParseUriStringToType_GeneralParsers_InvalidValue_ParsingHasFailed() public void ParseUriStringToType_GeneralParsers_ParserCannotParse_ParsingHasFailed() { RegisterTestCase("ParseUriStringToType_GeneralParsers_ParserCannotParse_ParsingHasFailed"); - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); try { - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(customBooleanUriTypePraser); - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, EdmCoreModel.Instance.GetBoolean(false), out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, EdmCoreModel.Instance.GetBoolean(false), out exception); // Assert output.Should().BeNull(); @@ -513,11 +514,11 @@ public void ParseUriStringToType_GeneralParsers_ParserCannotParse_ParsingHasFail throw exception; }; - action.ShouldThrow(); + action.ShouldThrow(); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } @@ -525,14 +526,14 @@ public void ParseUriStringToType_GeneralParsers_ParserCannotParse_ParsingHasFail public void ParseUriStringToType_RegisterToEdmType_ValidValue_ParsingSucceeded() { RegisterTestCase("ParseUriStringToType_RegisterToEdmType_ValidValue_ParsingSucceeded"); - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); try { IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE, booleanTypeReference, out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE, booleanTypeReference, out exception); // Assert exception.Should().BeNull(); @@ -540,7 +541,7 @@ public void ParseUriStringToType_RegisterToEdmType_ValidValue_ParsingSucceeded() } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } @@ -548,14 +549,14 @@ public void ParseUriStringToType_RegisterToEdmType_ValidValue_ParsingSucceeded() public void ParseUriStringToType_RegisterToEdmType_InvalidValue_ParsingHasFailed() { RegisterTestCase("ParseUriStringToType_RegisterToEdmType_InvalidValue_ParsingHasFailed"); - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); try { IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, booleanTypeReference, out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, booleanTypeReference, out exception); // Assert output.Should().BeNull(); @@ -565,11 +566,11 @@ public void ParseUriStringToType_RegisterToEdmType_InvalidValue_ParsingHasFailed throw exception; }; - action.ShouldThrow(); + action.ShouldThrow(); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } @@ -577,14 +578,14 @@ public void ParseUriStringToType_RegisterToEdmType_InvalidValue_ParsingHasFailed public void ParseUriStringToType_RegisterToEdmType_ParserCannotParse_ParsingHasFailed() { RegisterTestCase("ParseUriStringToType_RegisterToEdmType_ParserCannotParse_ParsingHasFailed"); - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); try { IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, booleanTypeReference, out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, booleanTypeReference, out exception); // Assert output.Should().BeNull(); @@ -594,26 +595,26 @@ public void ParseUriStringToType_RegisterToEdmType_ParserCannotParse_ParsingHasF throw exception; }; - action.ShouldThrow(); + action.ShouldThrow(); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } [Fact] public void ParseUriStringToType_RegisterToEdmType_ParserIsRegisteredToDifferentEdmType() { - MyCustomBooleanUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); + MyCustomBooleanUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); try { IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriTypePraser); - UriTypeParsingException exception; + UriLiteralParsingException exception; object output = - UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, EdmCoreModel.Instance.GetString(true), out exception); + CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_INVALID_VALUE, EdmCoreModel.Instance.GetString(true), out exception); // Assert output.Should().BeNull(); @@ -621,7 +622,7 @@ public void ParseUriStringToType_RegisterToEdmType_ParserIsRegisteredToDifferent } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); } } @@ -630,8 +631,8 @@ public void ParseUriStringToType_TryParseWithoutParsersAdded() { IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE, booleanTypeReference, out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE, booleanTypeReference, out exception); // Assert output.Should().BeNull(); @@ -642,21 +643,21 @@ public void ParseUriStringToType_TryParseWithoutParsersAdded() public void ParseUriStringToType_ParseFirstWithRegisteredEdmType() { RegisterTestCase("ParseUriStringToType_ParseFirstWithRegisteredEdmType"); - IUriTypeParser customBooleanUriTypePraser = new MyCustomBooleanUriTypeParser(); - IUriTypeParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriTypeParser(); + IUriLiteralParser customBooleanUriTypePraser = new MyCustomBooleanUriLiteralParser(); + IUriLiteralParser customIntBooleanUriTypePraser = new MyCustomIntAndBooleanUriLiteralParser(); try { IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypePraser); - UriCustomTypeParsers.AddCustomUriTypeParser(customIntBooleanUriTypePraser); + 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 - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALUE_TRUE_VALID, booleanTypeReference, out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALUE_TRUE_VALID, booleanTypeReference, out exception); // Assert output.Should().Be(true); @@ -664,8 +665,8 @@ public void ParseUriStringToType_ParseFirstWithRegisteredEdmType() } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypePraser).Should().BeTrue(); - UriCustomTypeParsers.RemoveCustomUriTypeParser(customIntBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriTypePraser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customIntBooleanUriTypePraser).Should().BeTrue(); } } @@ -677,10 +678,10 @@ public void ParseUriStringToType_ParseFirstWithRegisteredEdmType() public void ParseWithCustomUriFunction_CanParseByGeneralCustomParser() { RegisterTestCase("ParseWithCustomUriFunction_CanParseByGeneralCustomParser"); - IUriTypeParser customStringTypeParser = new MyCustomStringUriTypeParser(); + IUriLiteralParser customStringLiteralParser = new MyCustomStringUriLiteralParser(); try { - UriCustomTypeParsers.AddCustomUriTypeParser(customStringTypeParser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(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); @@ -690,7 +691,7 @@ public void ParseWithCustomUriFunction_CanParseByGeneralCustomParser() } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customStringTypeParser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customStringLiteralParser).Should().BeTrue(); } } @@ -698,10 +699,10 @@ public void ParseWithCustomUriFunction_CanParseByGeneralCustomParser() public void ParseWithCustomUriFunction_CanParseByCustomParserRegisterdToEdmTpe() { RegisterTestCase("ParseWithCustomUriFunction_CanParseByCustomParserRegisterdToEdmTpe"); - IUriTypeParser customStringTypeParser = new MyCustomStringUriTypeParser(); + IUriLiteralParser customStringLiteralParser = new MyCustomStringUriLiteralParser(); try { - UriCustomTypeParsers.AddCustomUriTypeParser(EdmCoreModel.Instance.GetString(true), customStringTypeParser); + 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); @@ -711,7 +712,7 @@ public void ParseWithCustomUriFunction_CanParseByCustomParserRegisterdToEdmTpe() } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customStringTypeParser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customStringLiteralParser).Should().BeTrue(); } } @@ -719,10 +720,10 @@ public void ParseWithCustomUriFunction_CanParseByCustomParserRegisterdToEdmTpe() public void ParseWithCustomUriFunction_CustomGeneralParserThrowsException() { RegisterTestCase("ParseWithCustomUriFunction_CustomGeneralParserThrowsException"); - IUriTypeParser customStringTypeParser = new MyCustomStringUriTypeParser(); + IUriLiteralParser customStringLiteralParser = new MyCustomStringUriLiteralParser(); try { - UriCustomTypeParsers.AddCustomUriTypeParser(customStringTypeParser); + CustomUriLiteralParsers.AddCustomUriLiteralParser(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); @@ -731,11 +732,11 @@ public void ParseWithCustomUriFunction_CustomGeneralParserThrowsException() parser.ParseFilter(); parseUriAction.ShouldThrow(). - WithInnerException(); + WithInnerException(); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customStringTypeParser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customStringLiteralParser).Should().BeTrue(); } } @@ -743,10 +744,10 @@ public void ParseWithCustomUriFunction_CustomGeneralParserThrowsException() public void ParseWithCustomUriFunction_CustomParserRegisteredToEdmTypeThrowsException() { RegisterTestCase("ParseWithCustomUriFunction_CustomParserRegisteredToEdmTypeThrowsException"); - IUriTypeParser customStringTypeParser = new MyCustomStringUriTypeParser(); + IUriLiteralParser customStringLiteralParser = new MyCustomStringUriLiteralParser(); try { - UriCustomTypeParsers.AddCustomUriTypeParser(EdmCoreModel.Instance.GetString(true), customStringTypeParser); + 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); @@ -755,26 +756,26 @@ public void ParseWithCustomUriFunction_CustomParserRegisteredToEdmTypeThrowsExce parser.ParseFilter(); parseUriAction.ShouldThrow(). - WithInnerException(); + WithInnerException(); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customStringTypeParser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customStringLiteralParser).Should().BeTrue(); } } /// - /// Similates a stituation which the client implements a buggy UriTypeParser. + /// Similates a stituation which the client implements a buggy UriLiteralParser. /// It throw an exception and returns a value which is not null. /// [Fact] public void ParseWithCustomUriFunction_CustomParserThrowsExceptionAndReturnNotNullValue() { RegisterTestCase("ParseWithCustomUriFunction_CustomParserThrowsExceptionAndReturnNotNullValue"); - IUriTypeParser customStringTypeParser = new MyCustomStringUriTypeParser(); + IUriLiteralParser customStringLiteralParser = new MyCustomStringUriLiteralParser(); try { - UriCustomTypeParsers.AddCustomUriTypeParser(EdmCoreModel.Instance.GetString(true), customStringTypeParser); + 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); @@ -783,64 +784,64 @@ public void ParseWithCustomUriFunction_CustomParserThrowsExceptionAndReturnNotNu parser.ParseFilter(); parseUriAction.ShouldThrow(). - WithInnerException(); + WithInnerException(); } finally { - UriCustomTypeParsers.RemoveCustomUriTypeParser(customStringTypeParser).Should().BeTrue(); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customStringLiteralParser).Should().BeTrue(); } } /// - /// In fact, this test shows the real power of the customization of UriTypeParser and LiteralPrefix. + /// In fact, this test shows the real power of the customization of UriLiteralParser and LiteralPrefix. /// Here we can see a special parsing for an EdmType 'Heartbeat' which is a complex type. /// The 'Heartbeat' type has it's own LiteralPrefix. /// The result is an instacne object of 'Heartbeat' class. /// [Fact] - public void UriCustomTypePrefixLiteral_CanSetCustomLiteralWithCustomTypeParserCustomType() + public void CustomUriLiteralPrefix_CanSetCustomLiteralWithCustomLiteralParserCustomType() { - RegisterTestCase("UriCustomTypePrefixLiteral_CanSetCustomLiteralWithCustomTypeParserCustomType"); - const string HEARTBEAT_TYPE_PREFIX_LITERAL = "myCustomHeartbeatTypePrefixLiteral"; - IUriTypeParser customHeartbeatUriTypePraser = new HeatBeatCustomUriTypeParser(); - IEdmTypeReference heartbeatTypeReference = HeatBeatCustomUriTypeParser.HeartbeatComplexType; + RegisterTestCase("CustomUriLiteralPrefix_CanSetCustomLiteralWithCustomLiteralParserCustomType"); + const string HEARTBEAT_LITERAL_PREFIX = "myCustomHeartbeatTypePrefixLiteral"; + IUriLiteralParser customHeartbeatUriTypePraser = new HeatBeatCustomUriLiteralParser(); + IEdmTypeReference heartbeatTypeReference = HeatBeatCustomUriLiteralParser.HeartbeatComplexType; try { - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(HEARTBEAT_TYPE_PREFIX_LITERAL, heartbeatTypeReference); - UriCustomTypeParsers.AddCustomUriTypeParser(heartbeatTypeReference, customHeartbeatUriTypePraser); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(HEARTBEAT_LITERAL_PREFIX, heartbeatTypeReference); + CustomUriLiteralParsers.AddCustomUriLiteralParser(heartbeatTypeReference, customHeartbeatUriTypePraser); - var fullUri = new Uri("http://www.odata.com/OData/Lions" + string.Format("?$filter=LionHeartbeat eq {0}'55.9'", HEARTBEAT_TYPE_PREFIX_LITERAL)); + var fullUri = new Uri("http://www.odata.com/OData/Lions" + string.Format("?$filter=LionHeartbeat eq {0}'55.9'", HEARTBEAT_LITERAL_PREFIX)); ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri); - HeatBeatCustomUriTypeParser.HeatBeat heartbeatValue = + HeatBeatCustomUriLiteralParser.HeatBeat heartbeatValue = (parser.ParseFilter().Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal).And.Right.ShouldBeConvertQueryNode(heartbeatTypeReference).And.Source as ConstantNode). - Value.As(); + Value.As(); heartbeatValue.Should().NotBeNull(); heartbeatValue.Frequency.Should().Be(55.9); } finally { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(HEARTBEAT_TYPE_PREFIX_LITERAL); - UriCustomTypeParsers.RemoveCustomUriTypeParser(customHeartbeatUriTypePraser); + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(HEARTBEAT_LITERAL_PREFIX); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customHeartbeatUriTypePraser); } } [Fact] - public void UriCustomTypePrefixLiteral_CanSetCustomLiteralWithCustomTypeParser() + public void CustomUriLiteralPrefix_CanSetCustomLiteralWithCustomLiteralParser() { - RegisterTestCase("UriCustomTypePrefixLiteral_CanSetCustomLiteralWithCustomTypeParser"); - IUriTypeParser customstringUriTypePraser = new MyCustomStringUriTypeParser(); + RegisterTestCase("CustomUriLiteralPrefix_CanSetCustomLiteralWithCustomLiteralParser"); + IUriLiteralParser customstringUriTypePraser = new MyCustomStringUriLiteralParser(); IEdmTypeReference stringTypeReference = EdmCoreModel.Instance.GetString(true); try { - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(STRING_TYPE_PREFIX_LITERAL, stringTypeReference); - UriCustomTypeParsers.AddCustomUriTypeParser(stringTypeReference, customstringUriTypePraser); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(STRING_LITERAL_PREFIX, stringTypeReference); + CustomUriLiteralParsers.AddCustomUriLiteralParser(stringTypeReference, customstringUriTypePraser); - var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq {0}'{1}'", STRING_TYPE_PREFIX_LITERAL, CUSTOM_PARSER_STRING_VALID_VALUE)); + var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq {0}'{1}'", STRING_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) @@ -848,24 +849,24 @@ public void UriCustomTypePrefixLiteral_CanSetCustomLiteralWithCustomTypeParser() } finally { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(STRING_TYPE_PREFIX_LITERAL); - UriCustomTypeParsers.RemoveCustomUriTypeParser(customstringUriTypePraser); + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(STRING_LITERAL_PREFIX); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customstringUriTypePraser); } } [Fact] - public void UriCustomTypePrefixLiteral_ParseTypeWithCorrectLiteralPrefixAndUriParser() + public void CustomUriLiteralPrefix_ParseTypeWithCorrectLiteralPrefixAndUriParser() { - RegisterTestCase("UriCustomTypePrefixLiteral_ParseTypeWithCorrectLiteralPrefixAndUriParser"); - var customBooleanAndIntUriTypeParser = new MyCustomIntAndBooleanUriTypeParser(); + RegisterTestCase("CustomUriLiteralPrefix_ParseTypeWithCorrectLiteralPrefixAndUriParser"); + var customBooleanAndIntUriLiteralParser = new MyCustomIntAndBooleanUriLiteralParser(); try { IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(BOOLEAN_TYPE_PREFIX_LITERAL, booleanTypeReference); - UriCustomTypeParsers.AddCustomUriTypeParser(customBooleanAndIntUriTypeParser); + 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_TYPE_PREFIX_LITERAL, CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE)); + 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) @@ -873,23 +874,23 @@ public void UriCustomTypePrefixLiteral_ParseTypeWithCorrectLiteralPrefixAndUriPa } finally { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(BOOLEAN_TYPE_PREFIX_LITERAL); - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanAndIntUriTypeParser); + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(BOOLEAN_LITERAL_PREFIX); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanAndIntUriLiteralParser); } } [Fact] - public void UriCustomTypePrefixLiteral_ParseTypeWithCorrectLiteralPrefixAndUriParserPerEdmType() + public void CustomUriLiteralPrefix_ParseTypeWithCorrectLiteralPrefixAndUriParserPerEdmType() { - RegisterTestCase("UriCustomTypePrefixLiteral_ParseTypeWithCorrectLiteralPrefixAndUriParserPerEdmType"); - var customBooleanUriTypeParser = new UriCustomTypeParserUnitTests.MyCustomBooleanUriTypeParser(); + RegisterTestCase("CustomUriLiteralPrefix_ParseTypeWithCorrectLiteralPrefixAndUriParserPerEdmType"); + var customBooleanUriLiteralParser = new CustomUriLiteralParserUnitTests.MyCustomBooleanUriLiteralParser(); try { IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(UriCustomTypeParserUnitTests.BOOLEAN_TYPE_PREFIX_LITERAL, booleanTypeReference); - UriCustomTypeParsers.AddCustomUriTypeParser(booleanTypeReference, customBooleanUriTypeParser); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(CustomUriLiteralParserUnitTests.BOOLEAN_LITERAL_PREFIX, booleanTypeReference); + CustomUriLiteralParsers.AddCustomUriLiteralParser(booleanTypeReference, customBooleanUriLiteralParser); - var fullUri = new Uri("http://www.odata.com/OData/Chimeras" + string.Format("?$filter=Upgraded eq {0}'{1}'", UriCustomTypeParserUnitTests.BOOLEAN_TYPE_PREFIX_LITERAL, UriCustomTypeParserUnitTests.CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE)); + var fullUri = new Uri("http://www.odata.com/OData/Chimeras" + string.Format("?$filter=Upgraded eq {0}'{1}'", CustomUriLiteralParserUnitTests.BOOLEAN_LITERAL_PREFIX, CustomUriLiteralParserUnitTests.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) @@ -897,26 +898,26 @@ public void UriCustomTypePrefixLiteral_ParseTypeWithCorrectLiteralPrefixAndUriPa } finally { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(UriCustomTypeParserUnitTests.BOOLEAN_TYPE_PREFIX_LITERAL); - UriCustomTypeParsers.RemoveCustomUriTypeParser(customBooleanUriTypeParser); + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(CustomUriLiteralParserUnitTests.BOOLEAN_LITERAL_PREFIX); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customBooleanUriLiteralParser); } } [Fact] - public void UriCustomTypePrefixLiteral_CanSetCustomLiteralToQuotedValue() + public void CustomUriLiteralPrefix_CanSetCustomLiteralToQuotedValue() { - RegisterTestCase("UriCustomTypePrefixLiteral_CanSetCustomLiteralToQuotedValue"); - const string TYPE_PREFIX_LITERAL = "myCustomStringTypePrefixLiteral"; - IUriTypeParser customstringUriTypePraser = new MyCustomStringUriTypeParser(); + RegisterTestCase("CustomUriLiteralPrefix_CanSetCustomLiteralToQuotedValue"); + const string LITERAL_PREFIX = "myCustomStringTypePrefixLiteral"; + IUriLiteralParser customstringUriTypePraser = new MyCustomStringUriLiteralParser(); IEdmTypeReference stringTypeReference = EdmCoreModel.Instance.GetString(true); try { - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(TYPE_PREFIX_LITERAL, stringTypeReference); - UriCustomTypeParsers.AddCustomUriTypeParser(stringTypeReference, customstringUriTypePraser); + 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}'", TYPE_PREFIX_LITERAL, CUSTOM_PARSER_STRING_VALID_VALUE)); + 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) @@ -924,8 +925,8 @@ public void UriCustomTypePrefixLiteral_CanSetCustomLiteralToQuotedValue() } finally { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(TYPE_PREFIX_LITERAL); - UriCustomTypeParsers.RemoveCustomUriTypeParser(customstringUriTypePraser); + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(LITERAL_PREFIX); + CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customstringUriTypePraser); } } @@ -935,7 +936,7 @@ public void UriCustomTypePrefixLiteral_CanSetCustomLiteralToQuotedValue() /// /// Try to convert a valid value that the Custom boolean type parser can parse. - /// If the parser has been added successfully to the UriCustmTypeParser, this method will passed successfully. + /// If the parser has been added successfully to the UriCustomLiteralParser, this method will passed successfully. /// private void ParseNonConvetionalBooleanValueSuccessfully() { @@ -944,8 +945,8 @@ private void ParseNonConvetionalBooleanValueSuccessfully() IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE, booleanTypeReference, out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE, booleanTypeReference, out exception); // Assert exception.Should().BeNull(); @@ -954,7 +955,7 @@ private void ParseNonConvetionalBooleanValueSuccessfully() /// /// Try to convert a valid value that the Custom int type parser can parse. - /// If the parser has been added successfully to the UriCustmTypeParser, this method will passed successfully. + /// If the parser has been added successfully to the UriCustomLiteralParser, this method will passed successfully. /// private void ParseNonConvetionalIntValueSuccessfully() { @@ -964,8 +965,8 @@ private void ParseNonConvetionalIntValueSuccessfully() IEdmTypeReference Int32TypeReference = EdmCoreModel.Instance.GetInt32(false); - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_INT_VALID_VALUE, Int32TypeReference, out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_INT_VALID_VALUE, Int32TypeReference, out exception); // Assert exception.Should().BeNull(); @@ -974,14 +975,14 @@ private void ParseNonConvetionalIntValueSuccessfully() /// /// Try to convert a valid value that the Custom boolean type parser can parse. - /// If the parser has NOT been added to the UriCustmTypeParser, this method will passed successfully. + /// If the parser has NOT been added to the UriCustomLiteralParser, this method will passed successfully. /// private void NoParsesForNonConvetionalBooleanValue() { IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE, booleanTypeReference, out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_BOOLEAN_VALID_VALUE_TRUE, booleanTypeReference, out exception); // Assert exception.Should().BeNull(); @@ -990,14 +991,14 @@ private void NoParsesForNonConvetionalBooleanValue() /// /// Try to convert a valid value that the Custom Int32 type parser can parse. - /// If the parser has NOT been added to the UriCustmTypeParser, this method will passed successfully. + /// If the parser has NOT been added to the UriCustomLiteralParser, this method will passed successfully. /// private void NoParsesForNonConvetionalIntValue() { IEdmTypeReference Int32TypeReference = EdmCoreModel.Instance.GetInt32(false); - UriTypeParsingException exception; - object output = UriCustomTypeParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_INT_VALID_VALUE, Int32TypeReference, out exception); + UriLiteralParsingException exception; + object output = CustomUriLiteralParsers.Instance.ParseUriStringToType(CUSTOM_PARSER_INT_VALID_VALUE, Int32TypeReference, out exception); // Assert exception.Should().BeNull(); @@ -1020,9 +1021,9 @@ public static void RegisterTestCase(string caseName) #region Custom Type Parsers - internal class MyCustomBooleanUriTypeParser : IUriTypeParser + internal class MyCustomBooleanUriLiteralParser : IUriLiteralParser { - public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriTypeParsingException parsingException) + public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriLiteralParsingException parsingException) { parsingException = null; @@ -1037,9 +1038,9 @@ public object ParseUriStringToType(string text, IEdmTypeReference targetType, ou } // Take care of literals - if (text.StartsWith(BOOLEAN_TYPE_PREFIX_LITERAL)) + if (text.StartsWith(BOOLEAN_LITERAL_PREFIX)) { - text = text.Replace(BOOLEAN_TYPE_PREFIX_LITERAL, string.Empty); + text = text.Replace(BOOLEAN_LITERAL_PREFIX, string.Empty); text = UriParserHelper.RemoveQuotes(text); } @@ -1053,7 +1054,7 @@ public object ParseUriStringToType(string text, IEdmTypeReference targetType, ou } else if (text == CUSTOM_PARSER_BOOLEAN_INVALID_VALUE) { - parsingException = new UriTypeParsingException("Failed to convert boolean.", "Value must be bla bla bla"); + parsingException = new UriLiteralParsingException("Failed to convert boolean."); return null; } @@ -1061,9 +1062,9 @@ public object ParseUriStringToType(string text, IEdmTypeReference targetType, ou } } - internal class MyCustomIntAndBooleanUriTypeParser : IUriTypeParser + internal class MyCustomIntAndBooleanUriLiteralParser : IUriLiteralParser { - public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriTypeParsingException parsingException) + public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriLiteralParsingException parsingException) { if (!RegisteredTestCases.Exists(testCase => Environment.StackTrace.ToString().Contains(testCase))) { @@ -1085,7 +1086,7 @@ public object ParseUriStringToType(string text, IEdmTypeReference targetType, ou return null; } - private object ParseUriStringToInt(string text, out UriTypeParsingException parsingException) + private object ParseUriStringToInt(string text, out UriLiteralParsingException parsingException) { parsingException = null; @@ -1102,7 +1103,7 @@ private object ParseUriStringToInt(string text, out UriTypeParsingException pars return null; } - public object ParseUriStringToBoolean(string text, out UriTypeParsingException parsingException) + public object ParseUriStringToBoolean(string text, out UriLiteralParsingException parsingException) { parsingException = null; @@ -1112,9 +1113,9 @@ public object ParseUriStringToBoolean(string text, out UriTypeParsingException p } // Take care of literals - if (text.StartsWith(BOOLEAN_TYPE_PREFIX_LITERAL)) + if (text.StartsWith(BOOLEAN_LITERAL_PREFIX)) { - text = text.Replace(BOOLEAN_TYPE_PREFIX_LITERAL, string.Empty); + text = text.Replace(BOOLEAN_LITERAL_PREFIX, string.Empty); text = UriParserHelper.RemoveQuotes(text); } @@ -1124,11 +1125,11 @@ public object ParseUriStringToBoolean(string text, out UriTypeParsingException p } else if (text == CUSTOM_PARSER_BOOLEAN_VALUE_TRUE_VALID) { - parsingException = new UriTypeParsingException("Failed to convert boolean.", "Value must be bla bla bla"); + parsingException = new UriLiteralParsingException("Failed to convert boolean."); } else if (text == CUSTOM_PARSER_BOOLEAN_INVALID_VALUE) { - parsingException = new UriTypeParsingException("Failed to convert boolean.", "Value must be bla bla bla"); + parsingException = new UriLiteralParsingException("Failed to convert boolean."); return null; } @@ -1136,9 +1137,9 @@ public object ParseUriStringToBoolean(string text, out UriTypeParsingException p } } - internal class MyCustomStringUriTypeParser : IUriTypeParser + internal class MyCustomStringUriLiteralParser : IUriLiteralParser { - public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriTypeParsingException parsingException) + public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriLiteralParsingException parsingException) { parsingException = null; if (!RegisteredTestCases.Exists(testCase => Environment.StackTrace.ToString().Contains(testCase))) @@ -1158,9 +1159,9 @@ public object ParseUriStringToType(string text, IEdmTypeReference targetType, ou bool isLiteralPrefixExists = false; // Take care of literals - if (text.StartsWith(STRING_TYPE_PREFIX_LITERAL)) + if (text.StartsWith(STRING_LITERAL_PREFIX)) { - text = text.Replace(STRING_TYPE_PREFIX_LITERAL, string.Empty); + text = text.Replace(STRING_LITERAL_PREFIX, string.Empty); // If Literal exists, not need of quotes isLiteralPrefixExists = true; @@ -1168,7 +1169,7 @@ public object ParseUriStringToType(string text, IEdmTypeReference targetType, ou if (!isLiteralPrefixExists && !UriParserHelper.IsUriValueQuoted(text)) { - parsingException = new UriTypeParsingException("Edm.String value must be quoted"); + parsingException = new UriLiteralParsingException("Edm.String value must be quoted"); return null; } @@ -1177,7 +1178,7 @@ public object ParseUriStringToType(string text, IEdmTypeReference targetType, ou // Simulates a bug in a client Parser if (text == CUSTOM_PARSER_STRING_VALUE_CAUSEBUG) { - parsingException = new UriTypeParsingException("Parsing to Edm.String has failed for some reasons"); + parsingException = new UriLiteralParsingException("Parsing to Edm.String has failed for some reasons"); return "RetunsAValueButSupposeToBeNull"; } @@ -1190,16 +1191,16 @@ public object ParseUriStringToType(string text, IEdmTypeReference targetType, ou } } - internal class HeatBeatCustomUriTypeParser : IUriTypeParser + internal class HeatBeatCustomUriLiteralParser : IUriLiteralParser { public static EdmComplexTypeReference HeartbeatComplexType; - static HeatBeatCustomUriTypeParser() + static HeatBeatCustomUriLiteralParser() { HeartbeatComplexType = new EdmComplexTypeReference(HardCodedTestModel.GetHeatbeatComplexType(), false); } - public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriTypeParsingException parsingException) + public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriLiteralParsingException parsingException) { parsingException = null; if (!RegisteredTestCases.Exists(testCase => Environment.StackTrace.ToString().Contains(testCase))) @@ -1226,7 +1227,7 @@ public object ParseUriStringToType(string text, IEdmTypeReference targetType, ou if (!UriParserHelper.IsUriValueQuoted(text)) { - parsingException = new UriTypeParsingException("Edm.Heartbeat value must be quoted"); + parsingException = new UriLiteralParsingException("Edm.Heartbeat value must be quoted"); return null; } diff --git a/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/CustomUriLiteralPrefixesTests.cs b/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/CustomUriLiteralPrefixesTests.cs new file mode 100644 index 0000000000..db185355a8 --- /dev/null +++ b/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/CustomUriLiteralPrefixesTests.cs @@ -0,0 +1,353 @@ +using System; +using FluentAssertions; +using Microsoft.OData.Core.UriParser; +using Microsoft.OData.Core.UriParser.Parsers; +using Microsoft.OData.Core.UriParser.TreeNodeKinds; +using Microsoft.OData.Edm; +using Microsoft.OData.Edm.Library; +using Xunit; + +namespace Microsoft.OData.Core.Tests.UriParser.Parsers +{ + /// + /// Tests the CustomUriLiteralPreix class public API + /// + public class CustomUriLiteralPrefixUnitsTests + { + #region AddCustomLiteralPrefix Method + + // Validation + [Fact] + public void CustomUriLiteralPrefix_CannotAddWithNullLiteralName() + { + // Add null literal prefix name + Action addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(null, EdmCoreModel.Instance.GetBoolean(false)); + + addCustomUriLiteralPrefix.ShouldThrow(); + } + + [Fact] + public void CustomUriLiteralPrefix_CannotAddWithEmptyLiteralName() + { + // Add Empty literal prefix name + Action addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(string.Empty, EdmCoreModel.Instance.GetBoolean(false)); + + addCustomUriLiteralPrefix.ShouldThrow(); + } + + [Fact] + public void CustomUriLiteralPrefix_CannotAddWithNullEdmType() + { + // Add literal prefix name as null value + Action addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.AddCustomLiteralPrefix("MyCustomLiteralPrefix", null); + + addCustomUriLiteralPrefix.ShouldThrow(); + } + + [Fact] + public void CustomUriLiteralPrefix_Add_LiteralNameValidation() + { + const string INVALID_LITERAL_PREFIX_NUMBER = "myCustomUriLiteralPrefix56"; + const string INVALID_LITERAL_PREFIX_PUNCTUATION = "myCustomUriLiteralPrefix?"; + const string INVALID_LITERAL_PREFIX_WHITESPACE = "myCustomUriLiteralPrefix "; + const string INVALID_LITERAL_PREFIX_SIGN = "myCustomUriLiteralPrefix*"; + + Action addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(INVALID_LITERAL_PREFIX_NUMBER, EdmCoreModel.Instance.GetBoolean(false)); + addCustomUriLiteralPrefix.ShouldThrow(); + + addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(INVALID_LITERAL_PREFIX_PUNCTUATION, EdmCoreModel.Instance.GetBoolean(false)); + addCustomUriLiteralPrefix.ShouldThrow(); + + addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(INVALID_LITERAL_PREFIX_WHITESPACE, EdmCoreModel.Instance.GetBoolean(false)); + addCustomUriLiteralPrefix.ShouldThrow(); + + addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(INVALID_LITERAL_PREFIX_SIGN, EdmCoreModel.Instance.GetBoolean(false)); + addCustomUriLiteralPrefix.ShouldThrow(); + + const string VALID_LITERAL_PREFIX_LETTERS = "myCustomUriLiteralPrefix"; + const string VALID_LITERAL_PREFIX_POINT = "myCustom.LiteralPrefix"; + + try + { + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(VALID_LITERAL_PREFIX_LETTERS, EdmCoreModel.Instance.GetBoolean(false)); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(VALID_LITERAL_PREFIX_POINT, EdmCoreModel.Instance.GetBoolean(false)); + } + finally + { + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(VALID_LITERAL_PREFIX_LETTERS); + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(VALID_LITERAL_PREFIX_POINT); + } + } + + // AddCustom type prefix literal + [Fact] + public void CustomUriLiteralPrefix_CannotAddExistingPrefixNameWithExistingEdmType() + { + const string LITERAL_PREFIX = "myCustomUriLiteralPrefix"; + + try + { + IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(LITERAL_PREFIX, booleanTypeReference); + + // Should throw exception + Action addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(LITERAL_PREFIX, booleanTypeReference); + + addCustomUriLiteralPrefix.ShouldThrow(). + WithMessage(Strings.CustomUriTypePrefixLiterals_AddCustomUriTypePrefixLiteralAlreadyExists(LITERAL_PREFIX)); + } + finally + { + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(LITERAL_PREFIX).Should().BeTrue(); + } + } + + [Fact] + public void CustomUriLiteralPrefix_CannotAddExistingPrefixNameWithDifferentEdmType() + { + const string LITERAL_PREFIX = "myCustomUriLiteralPrefix"; + + try + { + IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(LITERAL_PREFIX, booleanTypeReference); + + IEdmTypeReference intTypeReference = EdmCoreModel.Instance.GetInt32(false); + + // Should throw exception + Action addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(LITERAL_PREFIX, intTypeReference); + + addCustomUriLiteralPrefix.ShouldThrow(). + WithMessage(Strings.CustomUriTypePrefixLiterals_AddCustomUriTypePrefixLiteralAlreadyExists(LITERAL_PREFIX)); + } + finally + { + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(LITERAL_PREFIX).Should().BeTrue(); + } + } + + [Fact] + public void CustomUriLiteralPrefix_CanAddDifferentPrefixNameWithExistingEdmTypeWith() + { + const string FIRST_LITERAL_PREFIX = "myFirstCustomLiteralPrefix"; + const string SECOND_LITERAL_PREFIX = "mySecondCustomLiteralPrefix"; + + try + { + IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(FIRST_LITERAL_PREFIX, booleanTypeReference); + + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(SECOND_LITERAL_PREFIX, booleanTypeReference); + + CustomUriLiteralPrefixes.GetEdmTypeByCustomLiteralPrefix(FIRST_LITERAL_PREFIX).IsEquivalentTo(booleanTypeReference).Should().BeTrue(); + CustomUriLiteralPrefixes.GetEdmTypeByCustomLiteralPrefix(SECOND_LITERAL_PREFIX).IsEquivalentTo(booleanTypeReference).Should().BeTrue(); + } + finally + { + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(FIRST_LITERAL_PREFIX).Should().BeTrue(); + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(SECOND_LITERAL_PREFIX).Should().BeTrue(); + } + } + + [Fact] + public void CustomUriLiteralPrefix_CanAddDifferentPrefixNameWithDifferentEdmTypeWith() + { + const string FIRST_LITERAL_PREFIX = "myFirstCustomLiteralPrefix"; + const string SECOND_LITERAL_PREFIX = "mySecondCustomLiteralPrefix"; + + try + { + IEdmTypeReference first_booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(FIRST_LITERAL_PREFIX, first_booleanTypeReference); + + IEdmTypeReference second_stringTypeReference = EdmCoreModel.Instance.GetString(false); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(SECOND_LITERAL_PREFIX, second_stringTypeReference); + + CustomUriLiteralPrefixes.GetEdmTypeByCustomLiteralPrefix(FIRST_LITERAL_PREFIX).IsEquivalentTo(first_booleanTypeReference).Should().BeTrue(); + CustomUriLiteralPrefixes.GetEdmTypeByCustomLiteralPrefix(SECOND_LITERAL_PREFIX).IsEquivalentTo(second_stringTypeReference).Should().BeTrue(); + } + finally + { + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(FIRST_LITERAL_PREFIX).Should().BeTrue(); + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(SECOND_LITERAL_PREFIX).Should().BeTrue(); + } + } + + [Fact] + public void CustomUriLiteralPrefix_CanAddLiteralPrefixNameOfBuiltInLiteral() + { + const string EXISITING_BUILTIN_LITERAL_NAME = "geometry"; + + try + { + IEdmTypeReference first_booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(EXISITING_BUILTIN_LITERAL_NAME, first_booleanTypeReference); + + CustomUriLiteralPrefixes.GetEdmTypeByCustomLiteralPrefix(EXISITING_BUILTIN_LITERAL_NAME).IsEquivalentTo(first_booleanTypeReference).Should().BeTrue(); + } + finally + { + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(EXISITING_BUILTIN_LITERAL_NAME).Should().BeTrue(); + } + } + + #endregion + + #region RemoveCustomLiteralPrefix Method + + [Fact] + public void CustomUriLiteralPrefix_CannotRemoveWithNullLiteralName() + { + // Remove 'null' literal prefix name + Action removeCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(null); + + removeCustomUriLiteralPrefix.ShouldThrow(); + } + + [Fact] + public void CustomUriLiteralPrefix_CannotRemoveWithEmptyLiteralName() + { + // Rempve empty literal prefix name + Action removeCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(string.Empty); + + removeCustomUriLiteralPrefix.ShouldThrow(); + } + + [Fact] + public void CustomUriLiteralPrefix_Remove_LiteralNameValidation() + { + const string INVALID_LITERAL_PREFIX_NUMBER = "myCustomUriLiteralPrefix56"; + const string INVALID_LITERAL_PREFIX_PUNCTUATION = "myCustomUriLiteralPrefix?"; + const string INVALID_LITERAL_PREFIX_WHITESPACE = "myCustomUriLiteralPrefix "; + const string INVALID_LITERAL_PREFIX_SIGN = "myCustomUriLiteralPrefix*"; + + Action addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(INVALID_LITERAL_PREFIX_NUMBER); + addCustomUriLiteralPrefix.ShouldThrow(); + + addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(INVALID_LITERAL_PREFIX_PUNCTUATION); + addCustomUriLiteralPrefix.ShouldThrow(); + + addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(INVALID_LITERAL_PREFIX_WHITESPACE); + addCustomUriLiteralPrefix.ShouldThrow(); + + addCustomUriLiteralPrefix = () => + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(INVALID_LITERAL_PREFIX_SIGN); + addCustomUriLiteralPrefix.ShouldThrow(); + + const string VALID_LITERAL_PREFIX_LETTERS = "myCustomUriLiteralPrefix"; + const string VALID_LITERAL_PREFIX_POINT = "myCustom.LiteralPrefix"; + + try + { + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(VALID_LITERAL_PREFIX_LETTERS); + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(VALID_LITERAL_PREFIX_POINT); + } + finally + { + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(VALID_LITERAL_PREFIX_LETTERS); + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(VALID_LITERAL_PREFIX_POINT); + } + } + + [Fact] + public void CustomUriLiteralPrefix_CanRemoveExistingLiteral() + { + const string LITERAL_PREFIX = "myCustomUriLiteralPrefix"; + + IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(LITERAL_PREFIX, booleanTypeReference); + + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(LITERAL_PREFIX).Should().BeTrue(); + } + + [Fact] + public void CustomUriLiteralPrefix_CannotRemoveNotExistingLiteral() + { + const string LITERAL_PREFIX = "myCustomUriLiteralPrefix"; + + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(LITERAL_PREFIX).Should().BeFalse(); + } + + #endregion + + #region GetEdmTypeByCustomLiteralPrefix Method + + [Fact] + public void CustomUriLiteralPrefix_GetNotExistingPrefix() + { + const string NOT_EXISTING_PREFIX_NAME = "NOT_EXISTING_PREFIX_NAME"; + + IEdmTypeReference edmType = + CustomUriLiteralPrefixes.GetEdmTypeByCustomLiteralPrefix(NOT_EXISTING_PREFIX_NAME); + + edmType.Should().BeNull(); + } + + #endregion + + #region ODataUriParser + + /// + /// In this case, the built-in parser for Edm.String cannot parse myCustomStringLiteralPrefix'MyString' so it fails. + /// Edm.String is just an example. + /// + [Fact] + public void CustomUriLiteralPrefix_CannotParseWithCustomLiteralPrefix_IfBuiltInParserDontRecognizeCustomLiteral() + { + const string STRING_LITERAL_PREFIX = "myCustomStringLiteralPrefix"; + + try + { + IEdmTypeReference stringTypeReference = EdmCoreModel.Instance.GetString(true); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(STRING_LITERAL_PREFIX, stringTypeReference); + + var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq {0}'{1}'", STRING_LITERAL_PREFIX, CustomUriLiteralParserUnitTests.CUSTOM_PARSER_STRING_VALID_VALUE)); + ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri); + + Action parsingFilter = () => parser.ParseFilter(); + parsingFilter.ShouldThrow(); + } + finally + { + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(STRING_LITERAL_PREFIX); + } + } + + [Fact] + public void CustomUriLiteralPrefix_CannotParseTypeWithWrongLiteralPrefix() + { + try + { + IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); + CustomUriLiteralPrefixes.AddCustomLiteralPrefix(CustomUriLiteralParserUnitTests.BOOLEAN_LITERAL_PREFIX, booleanTypeReference); + + var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq {0}'{1}'", CustomUriLiteralParserUnitTests.BOOLEAN_LITERAL_PREFIX, CustomUriLiteralParserUnitTests.CUSTOM_PARSER_STRING_VALID_VALUE)); + ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri); + + Action parsingFilterAction = () => + parser.ParseFilter(); + + parsingFilterAction.ShouldThrow(); + } + finally + { + CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(CustomUriLiteralParserUnitTests.BOOLEAN_LITERAL_PREFIX); + } + } + #endregion + } +} diff --git a/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/UriCustomTypePrefixLiteralTests.cs b/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/UriCustomTypePrefixLiteralTests.cs deleted file mode 100644 index 76d5177711..0000000000 --- a/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/UriCustomTypePrefixLiteralTests.cs +++ /dev/null @@ -1,353 +0,0 @@ -using System; -using FluentAssertions; -using Microsoft.OData.Core.UriParser; -using Microsoft.OData.Core.UriParser.Parsers.TypeParsers; -using Microsoft.OData.Core.UriParser.TreeNodeKinds; -using Microsoft.OData.Edm; -using Microsoft.OData.Edm.Library; -using Xunit; - -namespace Microsoft.OData.Core.Tests.UriParser.Parsers -{ - /// - /// Tests the CustomTypePreixLiteral class public API - /// - public class UriCustomTypePrefixLiteralUnitsTests - { - #region AddCustomUriTypePrefixLiteral Method - - // Validation - [Fact] - public void UriCustomTypePrefixLiteral_CannotAddWithNullLiteralName() - { - // Add null literal prefix name - Action addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(null, EdmCoreModel.Instance.GetBoolean(false)); - - addUriCustomTypeLitral.ShouldThrow(); - } - - [Fact] - public void UriCustomTypePrefixLiteral_CannotAddWithEmptyLiteralName() - { - // Add Empty literal prefix name - Action addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(string.Empty, EdmCoreModel.Instance.GetBoolean(false)); - - addUriCustomTypeLitral.ShouldThrow(); - } - - [Fact] - public void UriCustomTypePrefixLiteral_CannotAddWithNullEdmType() - { - // Add literal prefix name as null value - Action addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral("MyCustomLiteralPrefix", null); - - addUriCustomTypeLitral.ShouldThrow(); - } - - [Fact] - public void UriCustomTypePrefixLiteral_Add_LiteralNameValidation() - { - const string INVALID_TYPE_PREFIX_LITERAL_NUMBER = "myCustomTypePrefixLiteral56"; - const string INVALID_TYPE_PREFIX_LITERAL_PUNCTUATION = "myCustomTypePrefixLiteral?"; - const string INVALID_TYPE_PREFIX_LITERAL_WHITESPACE = "myCustomTypePrefixLiteral "; - const string INVALID_TYPE_PREFIX_LITERAL_SIGN = "myCustomTypePrefixLiteral*"; - - Action addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(INVALID_TYPE_PREFIX_LITERAL_NUMBER, EdmCoreModel.Instance.GetBoolean(false)); - addUriCustomTypeLitral.ShouldThrow(); - - addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(INVALID_TYPE_PREFIX_LITERAL_PUNCTUATION, EdmCoreModel.Instance.GetBoolean(false)); - addUriCustomTypeLitral.ShouldThrow(); - - addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(INVALID_TYPE_PREFIX_LITERAL_WHITESPACE, EdmCoreModel.Instance.GetBoolean(false)); - addUriCustomTypeLitral.ShouldThrow(); - - addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(INVALID_TYPE_PREFIX_LITERAL_SIGN, EdmCoreModel.Instance.GetBoolean(false)); - addUriCustomTypeLitral.ShouldThrow(); - - const string VALID_TYPE_PREFIX_LITERAL_LETTERS = "myCustomTypePrefixLiteral"; - const string VALID_TYPE_PREFIX_LITERAL_POINT = "myCustom.TypePrefixLiteral"; - - try - { - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(VALID_TYPE_PREFIX_LITERAL_LETTERS, EdmCoreModel.Instance.GetBoolean(false)); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(VALID_TYPE_PREFIX_LITERAL_POINT, EdmCoreModel.Instance.GetBoolean(false)); - } - finally - { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(VALID_TYPE_PREFIX_LITERAL_LETTERS); - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(VALID_TYPE_PREFIX_LITERAL_POINT); - } - } - - // AddCustom type prefix literal - [Fact] - public void UriCustomTypePrefixLiteral_CannotAddExistingPrefixNameWithExistingEdmType() - { - const string TYPE_PREFIX_LITERAL = "myCustomTypePrefixLiteral"; - - try - { - IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(TYPE_PREFIX_LITERAL, booleanTypeReference); - - // Should throw exception - Action addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(TYPE_PREFIX_LITERAL, booleanTypeReference); - - addUriCustomTypeLitral.ShouldThrow(). - WithMessage(Strings.CustomUriTypePrefixLiterals_AddCustomUriTypePrefixLiteralAlreadyExists(TYPE_PREFIX_LITERAL)); - } - finally - { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(TYPE_PREFIX_LITERAL).Should().BeTrue(); - } - } - - [Fact] - public void UriCustomTypePrefixLiteral_CannotAddExistingPrefixNameWithDifferentEdmType() - { - const string TYPE_PREFIX_LITERAL = "myCustomTypePrefixLiteral"; - - try - { - IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(TYPE_PREFIX_LITERAL, booleanTypeReference); - - IEdmTypeReference intTypeReference = EdmCoreModel.Instance.GetInt32(false); - - // Should throw exception - Action addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(TYPE_PREFIX_LITERAL, intTypeReference); - - addUriCustomTypeLitral.ShouldThrow(). - WithMessage(Strings.CustomUriTypePrefixLiterals_AddCustomUriTypePrefixLiteralAlreadyExists(TYPE_PREFIX_LITERAL)); - } - finally - { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(TYPE_PREFIX_LITERAL).Should().BeTrue(); - } - } - - [Fact] - public void UriCustomTypePrefixLiteral_CanAddDifferentPrefixNameWithExistingEdmTypeWith() - { - const string FIRST_TYPE_PREFIX_LITERAL = "myFirstCustomTypePrefixLiteral"; - const string SECOND_TYPE_PREFIX_LITERAL = "mySecondCustomTypePrefixLiteral"; - - try - { - IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(FIRST_TYPE_PREFIX_LITERAL, booleanTypeReference); - - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(SECOND_TYPE_PREFIX_LITERAL, booleanTypeReference); - - CustomUriTypePrefixLiterals.GetCustomEdmTypeByLiteralPrefix(FIRST_TYPE_PREFIX_LITERAL).IsEquivalentTo(booleanTypeReference).Should().BeTrue(); - CustomUriTypePrefixLiterals.GetCustomEdmTypeByLiteralPrefix(SECOND_TYPE_PREFIX_LITERAL).IsEquivalentTo(booleanTypeReference).Should().BeTrue(); - } - finally - { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(FIRST_TYPE_PREFIX_LITERAL).Should().BeTrue(); - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(SECOND_TYPE_PREFIX_LITERAL).Should().BeTrue(); - } - } - - [Fact] - public void UriCustomTypePrefixLiteral_CanAddDifferentPrefixNameWithDifferentEdmTypeWith() - { - const string FIRST_TYPE_PREFIX_LITERAL = "myFirstCustomTypePrefixLiteral"; - const string SECOND_TYPE_PREFIX_LITERAL = "mySecondCustomTypePrefixLiteral"; - - try - { - IEdmTypeReference first_booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(FIRST_TYPE_PREFIX_LITERAL, first_booleanTypeReference); - - IEdmTypeReference second_stringTypeReference = EdmCoreModel.Instance.GetString(false); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(SECOND_TYPE_PREFIX_LITERAL, second_stringTypeReference); - - CustomUriTypePrefixLiterals.GetCustomEdmTypeByLiteralPrefix(FIRST_TYPE_PREFIX_LITERAL).IsEquivalentTo(first_booleanTypeReference).Should().BeTrue(); - CustomUriTypePrefixLiterals.GetCustomEdmTypeByLiteralPrefix(SECOND_TYPE_PREFIX_LITERAL).IsEquivalentTo(second_stringTypeReference).Should().BeTrue(); - } - finally - { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(FIRST_TYPE_PREFIX_LITERAL).Should().BeTrue(); - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(SECOND_TYPE_PREFIX_LITERAL).Should().BeTrue(); - } - } - - [Fact] - public void UriCustomTypePrefixLiteral_CanAddLiteralPrefixNameOfBuiltInLiteral() - { - const string EXISITING_BUILTIN_LITERAL_NAME = "geometry"; - - try - { - IEdmTypeReference first_booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(EXISITING_BUILTIN_LITERAL_NAME, first_booleanTypeReference); - - CustomUriTypePrefixLiterals.GetCustomEdmTypeByLiteralPrefix(EXISITING_BUILTIN_LITERAL_NAME).IsEquivalentTo(first_booleanTypeReference).Should().BeTrue(); - } - finally - { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(EXISITING_BUILTIN_LITERAL_NAME).Should().BeTrue(); - } - } - - #endregion - - #region RemoveCustomUriTypePrefixLiteral Method - - [Fact] - public void UriCustomTypePrefixLiteral_CannotRemoveWithNullLiteralName() - { - // Remove 'null' literal prefix name - Action removeUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(null); - - removeUriCustomTypeLitral.ShouldThrow(); - } - - [Fact] - public void UriCustomTypePrefixLiteral_CannotRemoveWithEmptyLiteralName() - { - // Rempve empty literal prefix name - Action removeUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(string.Empty); - - removeUriCustomTypeLitral.ShouldThrow(); - } - - [Fact] - public void UriCustomTypePrefixLiteral_Remove_LiteralNameValidation() - { - const string INVALID_TYPE_PREFIX_LITERAL_NUMBER = "myCustomTypePrefixLiteral56"; - const string INVALID_TYPE_PREFIX_LITERAL_PUNCTUATION = "myCustomTypePrefixLiteral?"; - const string INVALID_TYPE_PREFIX_LITERAL_WHITESPACE = "myCustomTypePrefixLiteral "; - const string INVALID_TYPE_PREFIX_LITERAL_SIGN = "myCustomTypePrefixLiteral*"; - - Action addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(INVALID_TYPE_PREFIX_LITERAL_NUMBER); - addUriCustomTypeLitral.ShouldThrow(); - - addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(INVALID_TYPE_PREFIX_LITERAL_PUNCTUATION); - addUriCustomTypeLitral.ShouldThrow(); - - addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(INVALID_TYPE_PREFIX_LITERAL_WHITESPACE); - addUriCustomTypeLitral.ShouldThrow(); - - addUriCustomTypeLitral = () => - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(INVALID_TYPE_PREFIX_LITERAL_SIGN); - addUriCustomTypeLitral.ShouldThrow(); - - const string VALID_TYPE_PREFIX_LITERAL_LETTERS = "myCustomTypePrefixLiteral"; - const string VALID_TYPE_PREFIX_LITERAL_POINT = "myCustom.TypePrefixLiteral"; - - try - { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(VALID_TYPE_PREFIX_LITERAL_LETTERS); - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(VALID_TYPE_PREFIX_LITERAL_POINT); - } - finally - { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(VALID_TYPE_PREFIX_LITERAL_LETTERS); - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(VALID_TYPE_PREFIX_LITERAL_POINT); - } - } - - [Fact] - public void UriCustomTypePrefixLiteral_CanRemoveExistingLiteral() - { - const string TYPE_PREFIX_LITERAL = "myCustomTypePrefixLiteral"; - - IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(TYPE_PREFIX_LITERAL, booleanTypeReference); - - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(TYPE_PREFIX_LITERAL).Should().BeTrue(); - } - - [Fact] - public void UriCustomTypePrefixLiteral_CannotRemoveNotExistingLiteral() - { - const string TYPE_PREFIX_LITERAL = "myCustomTypePrefixLiteral"; - - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(TYPE_PREFIX_LITERAL).Should().BeFalse(); - } - - #endregion - - #region GetCustomEdmTypeByLiteralPrefix Method - - [Fact] - public void UriCustomTypePrefixLiteral_GetNotExistingPrefix() - { - const string NOT_EXISTING_PREFIX_NAME = "NOT_EXISTING_PREFIX_NAME"; - - IEdmTypeReference typePrefixEdmType = - CustomUriTypePrefixLiterals.GetCustomEdmTypeByLiteralPrefix(NOT_EXISTING_PREFIX_NAME); - - typePrefixEdmType.Should().BeNull(); - } - - #endregion - - #region ODataUriParser - - /// - /// In this case, the built-in parser for Edm.String cannot parse myCustomStringTypePrefixLiteral'MyString' so it fails. - /// Edm.String is just an example. - /// - [Fact] - public void UriCustomTypePrefixLiteral_CannotParseWithCustomLiteralPrefix_IfBuiltInParserDontRecognizeCustomLiteral() - { - const string STRING_TYPE_PREFIX_LITERAL = "myCustomStringTypePrefixLiteral"; - - try - { - IEdmTypeReference stringTypeReference = EdmCoreModel.Instance.GetString(true); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(STRING_TYPE_PREFIX_LITERAL, stringTypeReference); - - var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq {0}'{1}'", STRING_TYPE_PREFIX_LITERAL, UriCustomTypeParserUnitTests.CUSTOM_PARSER_STRING_VALID_VALUE)); - ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri); - - Action parsingFilter = () => parser.ParseFilter(); - parsingFilter.ShouldThrow(); - } - finally - { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(STRING_TYPE_PREFIX_LITERAL); - } - } - - [Fact] - public void UriCustomTypePrefixLiteral_CannotParseTypeWithWrongLiteralPrefix() - { - try - { - IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false); - CustomUriTypePrefixLiterals.AddCustomUriTypePrefixLiteral(UriCustomTypeParserUnitTests.BOOLEAN_TYPE_PREFIX_LITERAL, booleanTypeReference); - - var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq {0}'{1}'", UriCustomTypeParserUnitTests.BOOLEAN_TYPE_PREFIX_LITERAL, UriCustomTypeParserUnitTests.CUSTOM_PARSER_STRING_VALID_VALUE)); - ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri); - - Action parsingFilterAction = () => - parser.ParseFilter(); - - parsingFilterAction.ShouldThrow(); - } - finally - { - CustomUriTypePrefixLiterals.RemoveCustomUriTypePrefixLiteral(UriCustomTypeParserUnitTests.BOOLEAN_TYPE_PREFIX_LITERAL); - } - } - #endregion - } -} diff --git a/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/UriPrimitiveTypeParserTests.cs b/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/UriPrimitiveTypeParserTests.cs index 4c05ab2e43..7ac71c4f5d 100644 --- a/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/UriPrimitiveTypeParserTests.cs +++ b/test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/UriPrimitiveTypeParserTests.cs @@ -6,8 +6,8 @@ using System; using FluentAssertions; -using Microsoft.OData.Core.UriParser.Parsers.TypeParsers; -using Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common; +using Microsoft.OData.Core.UriParser.Parsers; +using Microsoft.OData.Core.UriParser.Parsers.Common; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Library; using Xunit; @@ -72,7 +72,7 @@ public void TryUriStringToPrimitiveWithOverflowingDurationLiteralShouldReturnFal private bool TryParseUriStringToPrimitiveType(string text, IEdmTypeReference targetType, out object targetValue) { - UriTypeParsingException exception; + UriLiteralParsingException exception; return UriPrimitiveTypeParser.Instance.TryParseUriStringToType(text, targetType, out targetValue, out exception); } diff --git a/test/FunctionalTests/Tests/DataOData/Tests/OData.Common.Tests/PublicApi/PublicApi.bsl b/test/FunctionalTests/Tests/DataOData/Tests/OData.Common.Tests/PublicApi/PublicApi.bsl index 9043d44c71..d5a949886a 100644 --- a/test/FunctionalTests/Tests/DataOData/Tests/OData.Common.Tests/PublicApi/PublicApi.bsl +++ b/test/FunctionalTests/Tests/DataOData/Tests/OData.Common.Tests/PublicApi/PublicApi.bsl @@ -5105,14 +5105,13 @@ public enum Microsoft.OData.Core.UriParser.OrderByDirection : int { public sealed class Microsoft.OData.Core.UriParser.CustomUriFunctions { public static void AddCustomUriFunction (string functionName, Microsoft.OData.Core.UriParser.FunctionSignatureWithReturnType functionSignature) - public static void AddCustomUriFunction (string functionName, Microsoft.OData.Core.UriParser.FunctionSignatureWithReturnType functionSignature, bool addAsOverloadToBuiltInFunction) public static bool RemoveCustomUriFunction (string functionName) public static bool RemoveCustomUriFunction (string functionName, Microsoft.OData.Core.UriParser.FunctionSignatureWithReturnType functionSignature) } -public sealed class Microsoft.OData.Core.UriParser.CustomUriTypePrefixLiterals { - public static void AddCustomUriTypePrefixLiteral (string typePrefixLiteralName, Microsoft.OData.Edm.IEdmTypeReference literalEdmTypeReference) - public static bool RemoveCustomUriTypePrefixLiteral (string typePrefixLiteralName) +public sealed class Microsoft.OData.Core.UriParser.CustomUriLiteralPrefixes { + public static void AddCustomLiteralPrefix (string literalPrefix, Microsoft.OData.Edm.IEdmTypeReference literalEdmTypeReference) + public static bool RemoveCustomLiteralPrefix (string literalPrefix) } public sealed class Microsoft.OData.Core.UriParser.ODataUriUtils { @@ -5316,6 +5315,13 @@ public sealed class Microsoft.OData.Core.UriParser.Metadata.StringAsEnumResolver public virtual System.Collections.Generic.IDictionary`2[[Microsoft.OData.Edm.IEdmOperationParameter],[Microsoft.OData.Core.UriParser.Semantic.SingleValueNode]] ResolveOperationParameters (Microsoft.OData.Edm.IEdmOperation operation, System.Collections.Generic.IDictionary`2[[System.String],[Microsoft.OData.Core.UriParser.Semantic.SingleValueNode]] input) } +public sealed class Microsoft.OData.Core.UriParser.Parsers.CustomUriLiteralParsers : IUriLiteralParser { + public static void AddCustomUriLiteralParser (Microsoft.OData.Core.UriParser.Parsers.Common.IUriLiteralParser customUriLiteralParser) + public static void AddCustomUriLiteralParser (Microsoft.OData.Edm.IEdmTypeReference edmTypeReference, Microsoft.OData.Core.UriParser.Parsers.Common.IUriLiteralParser customUriLiteralParser) + public virtual object ParseUriStringToType (string text, Microsoft.OData.Edm.IEdmTypeReference targetType, out Microsoft.OData.Core.UriParser.Parsers.Common.UriLiteralParsingException& parsingException) + public static bool RemoveCustomUriLiteralParser (Microsoft.OData.Core.UriParser.Parsers.Common.IUriLiteralParser customUriLiteralParser) +} + public abstract class Microsoft.OData.Core.UriParser.Semantic.CollectionNode : Microsoft.OData.Core.UriParser.Semantic.QueryNode { protected CollectionNode () @@ -6156,28 +6162,17 @@ public abstract class Microsoft.OData.Core.UriParser.Visitors.SelectItemTranslat public virtual T Translate (Microsoft.OData.Core.UriParser.Semantic.WildcardSelectItem item) } -public sealed class Microsoft.OData.Core.UriParser.Parsers.TypeParsers.UriCustomTypeParsers : IUriTypeParser { - public static void AddCustomUriTypeParser (Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common.IUriTypeParser uriCustomTypeParser) - public static void AddCustomUriTypeParser (Microsoft.OData.Edm.IEdmTypeReference edmTypeReference, Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common.IUriTypeParser uriCustomTypeParser) - public virtual object ParseUriStringToType (string text, Microsoft.OData.Edm.IEdmTypeReference targetType, out Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common.UriTypeParsingException& parsingException) - public static bool RemoveCustomUriTypeParser (Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common.IUriTypeParser uriCustomTypeParser) -} - -public interface Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common.IUriTypeParser { - object ParseUriStringToType (string text, Microsoft.OData.Edm.IEdmTypeReference targetType, out Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common.UriTypeParsingException& parsingException) +public interface Microsoft.OData.Core.UriParser.Parsers.Common.IUriLiteralParser { + object ParseUriStringToType (string text, Microsoft.OData.Edm.IEdmTypeReference targetType, out Microsoft.OData.Core.UriParser.Parsers.Common.UriLiteralParsingException& parsingException) } [ DebuggerDisplayAttribute(), ] -public sealed class Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common.UriTypeParsingException : Microsoft.OData.Core.ODataException, _Exception, ISerializable { - public UriTypeParsingException () - public UriTypeParsingException (string message) - public UriTypeParsingException (string message, System.Exception innerException) - public UriTypeParsingException (string message, string parsingFailureReason) - public UriTypeParsingException (string message, System.Exception innerException, string parsingFailureReason) - - string ParsingFailureReason { public get; } +public sealed class Microsoft.OData.Core.UriParser.Parsers.Common.UriLiteralParsingException : Microsoft.OData.Core.ODataException, _Exception, ISerializable { + public UriLiteralParsingException () + public UriLiteralParsingException (string message) + public UriLiteralParsingException (string message, System.Exception innerException) } public enum Microsoft.OData.Client.DataServiceResponsePreference : int { diff --git a/test/FunctionalTests/Tests/DataOData/Tests/OData.Query.Tests/UriParser/SyntacticTree.cs b/test/FunctionalTests/Tests/DataOData/Tests/OData.Query.Tests/UriParser/SyntacticTree.cs index ee87450dd5..89ba005435 100644 --- a/test/FunctionalTests/Tests/DataOData/Tests/OData.Query.Tests/UriParser/SyntacticTree.cs +++ b/test/FunctionalTests/Tests/DataOData/Tests/OData.Query.Tests/UriParser/SyntacticTree.cs @@ -13,8 +13,7 @@ namespace Microsoft.OData.Core.UriParser using System.Collections.ObjectModel; using System.Diagnostics; using Microsoft.OData.Core.UriParser.Parsers; - using Microsoft.OData.Core.UriParser.Parsers.TypeParsers; - using Microsoft.OData.Core.UriParser.Parsers.TypeParsers.Common; + using Microsoft.OData.Core.UriParser.Parsers.Common; using Microsoft.OData.Core.UriParser.Syntactic; using Microsoft.OData.Edm.Library; @@ -387,7 +386,7 @@ private static bool TryUriStringToNonNegativeInteger(string text, out int nonNeg Debug.Assert(text != null, "text != null"); object valueAsObject; - UriTypeParsingException exception; + UriLiteralParsingException exception; if (!UriPrimitiveTypeParser.Instance.TryParseUriStringToType(text, EdmCoreModel.Instance.GetInt32(false), out valueAsObject, out exception)) { nonNegativeInteger = -1;