/// <summary> /// Initializes a new instance of the ErrorResponseVerifier class /// </summary> /// <param name="expectedErrorMessage">Expected error message to compare against</param> /// <param name="resourceVerifier">resource verifier for to use for the error message. Can be null if the expected errors provide specific verifiers.</param> public ErrorResponseVerifier(ExpectedErrorMessage expectedErrorMessage, IStringResourceVerifier resourceVerifier) : base() { ExceptionUtilities.CheckArgumentNotNull(expectedErrorMessage, "expectedErrorMessage"); this.ExpectedErrorMessage = expectedErrorMessage; this.ResourceVerifier = resourceVerifier; }
/// <summary> /// Creates an expected error with the given information /// </summary> /// <param name="verifier">The verifier to use</param> /// <param name="identifier">The identifier for the error string</param> /// <param name="args">The arguments to the error string</param> /// <returns>The expected error</returns> public static ExpectedErrorMessage CreateExpectedError(this IStringResourceVerifier verifier, string identifier, params string[] args) { return(new ExpectedErrorMessage(identifier, args) { Verifier = verifier }); }
/// <summary> /// Verifies that the error matches /// </summary> /// <param name="expected">The expected error message</param> /// <param name="defaultVerifier">The verifier to use if the message does not have one set</param> /// <param name="actual">The actual error string</param> /// <param name="isExactMatch">Whether to perform an exact match</param> public static void VerifyMatch(this ExpectedErrorMessage expected, IStringResourceVerifier defaultVerifier, string actual, bool isExactMatch) { ExceptionUtilities.CheckArgumentNotNull(expected, "expected"); var verifier = expected.Verifier ?? defaultVerifier; ExceptionUtilities.CheckObjectNotNull(verifier, "Either a default verifier or specific message verifier must be provided"); verifier.VerifyMatch(expected.ResourceIdentifier, actual, isExactMatch, expected.Arguments.ToArray()); }
/// <summary> /// Initializes a new instance of the ProtocolQueryVerifier class. /// </summary> /// <param name="defaultAcceptType">The mime type to use in the 'accept' header</param> /// <param name="serviceRoot">The root uri of the service</param> /// <param name="maxProtocolVersion">The max protocol version of the service</param> /// <param name="resourceVerifier">The resource string verifier to use for errors</param> protected ProtocolQueryVerifier(string defaultAcceptType, Uri serviceRoot, DataServiceProtocolVersion maxProtocolVersion, IStringResourceVerifier resourceVerifier) { ExceptionUtilities.CheckArgumentNotNull(defaultAcceptType, "defaultAcceptType"); ExceptionUtilities.CheckArgumentNotNull(serviceRoot, "serviceRoot"); ExceptionUtilities.CheckArgumentNotNull(resourceVerifier, "resourceVerifier"); this.DefaultAcceptType = defaultAcceptType; this.ServiceRoot = serviceRoot; this.Logger = Logger.Null; this.MaxProtocolVersion = maxProtocolVersion; this.DataServiceVersion = DataServiceProtocolVersion.Unspecified; this.MaxDataServiceVersion = DataServiceProtocolVersion.Unspecified; this.ResourceVerifier = resourceVerifier; }
/// <summary> /// Retrieves the resource verifier for the specified assembly. /// </summary> /// <param name="assemblyFullName">The full name of the assembly to retrieve.</param> /// <returns>The resource verifier for the assembly.</returns> private static IStringResourceVerifier GetResourceVerifier(string assemblyFullName) { ExceptionUtilities.CheckStringArgumentIsNotNullOrEmpty(assemblyFullName, "assemblyFullName"); IStringResourceVerifier verifier = null; // Resource lookup not supported on Silverlight or Phone platforms. if (!resourceVerifierCache.TryGetValue(assemblyFullName, out verifier)) { Assembly assembly = Assembly.Load(new AssemblyName(assemblyFullName)); var lookup = new ODataAssemblyResourceLookup(assembly); verifier = new StringResourceVerifier(lookup); resourceVerifierCache.Add(assemblyFullName, verifier); } return(verifier); }
/// <summary> /// Verifies the ExceptionMessage recursively /// </summary> /// <param name="expectedErrorMessage">Error Message to Verify</param> /// <param name="resourceVerifier">Resource Verifier to use</param> /// <param name="errorPayload">Error payload to verify</param> /// <param name="assert">assert call to make</param> public static void VerifyExceptionMessage(this ExpectedErrorMessage expectedErrorMessage, IStringResourceVerifier resourceVerifier, ODataErrorPayload errorPayload, Action<bool, string> assert) { ExceptionUtilities.CheckArgumentNotNull(expectedErrorMessage, "expectedErrorMessage"); ExceptionUtilities.CheckArgumentNotNull(resourceVerifier, "resourceVerifier"); ExceptionUtilities.CheckArgumentNotNull(errorPayload, "errorPayload"); ExceptionUtilities.CheckArgumentNotNull(assert, "assert"); // Verify messages are the same // TODO: Need to also verify the language and code expectedErrorMessage.VerifyMatch(resourceVerifier, errorPayload.Message, true); ExpectedErrorMessage expectedInnerError = expectedErrorMessage.InnerError; ODataInternalExceptionPayload innerError = errorPayload.InnerError; // Set it to null so comparison won't occur if (expectedErrorMessage.SkipInnerErrorVerification) { innerError = null; expectedInnerError = null; } while (innerError != null) { // TODO: better error message assert(expectedInnerError != null, "Did not expect inner error"); // Verify messages are the same expectedInnerError.VerifyMatch(resourceVerifier, innerError.Message, true); if (expectedInnerError.SkipInnerErrorVerification) { innerError = null; expectedInnerError = null; } else { // TODO: verify stack trace, type name, etc innerError = innerError.InternalException; expectedInnerError = expectedInnerError.InnerError; } } }
private IResponseVerifier BuildErrorResponseVerifier(ExpectedErrorMessage expectedMessage, IStringResourceVerifier resourceVerifier) { return(new ErrorResponseVerifier(expectedMessage, resourceVerifier)); }
/// <summary> /// Returns a composite verifier with all standard verifiers attached /// </summary> /// <param name="expectedStatusCode">The expected status code of the response</param> /// <param name="expectedMessage">The expected error message</param> /// <param name="resourceVerifier">The resource verifier for the error message</param> /// <returns>A composite verifier</returns> public IResponseVerifier GetErrorVerifier(HttpStatusCode expectedStatusCode, ExpectedErrorMessage expectedMessage, IStringResourceVerifier resourceVerifier) { ExceptionUtilities.CheckArgumentNotNull(expectedMessage, "expectedMessage"); ExceptionUtilities.CheckArgumentNotNull(resourceVerifier, "resourceVerifier"); ExceptionUtilities.CheckObjectNotNull(this.BuildErrorVerifierFunc, "Delegate for building standard verifier cannot be null"); ExceptionUtilities.CheckAllRequiredDependencies(this); var verifier = this.BuildErrorVerifierFunc(expectedStatusCode, expectedMessage, resourceVerifier); this.Injector.InjectDependenciesInto(verifier); verifier.Verifiers.ForEach(v => this.Injector.InjectDependenciesInto(v)); return(verifier); }
/// <summary> /// Initializes a new instance of the ClientExpectedErrorComparer class. /// </summary> /// <param name="systemDataServicesVerifier">Resource Verifier for Microsoft.OData.Service</param> /// <param name="systemDataServicesClientVerifier">Resource Verifier for Microsoft.OData.Client</param> public ClientExpectedErrorComparer(IStringResourceVerifier systemDataServicesVerifier, IStringResourceVerifier systemDataServicesClientVerifier) { this.systemDataServicesVerifier = systemDataServicesVerifier; this.systemDataServicesClientVerifier = systemDataServicesClientVerifier; this.ShouldVerifyServerMessageInClientException = true; }
private IResponseVerifier BuildErrorResponseVerifier(ExpectedErrorMessage expectedMessage, IStringResourceVerifier resourceVerifier) { return new ErrorResponseVerifier(expectedMessage, resourceVerifier); }
/// <summary> /// Returns a composite verifier with all standard verifiers attached /// </summary> /// <param name="expectedStatusCode">The expected status code of the response</param> /// <param name="expectedMessage">The expected error message</param> /// <param name="resourceVerifier">The resource verifier for the error message</param> /// <returns>A composite verifier</returns> public IResponseVerifier GetErrorVerifier(HttpStatusCode expectedStatusCode, ExpectedErrorMessage expectedMessage, IStringResourceVerifier resourceVerifier) { ExceptionUtilities.CheckArgumentNotNull(expectedMessage, "expectedMessage"); ExceptionUtilities.CheckArgumentNotNull(resourceVerifier, "resourceVerifier"); ExceptionUtilities.CheckObjectNotNull(this.BuildErrorVerifierFunc, "Delegate for building standard verifier cannot be null"); ExceptionUtilities.CheckAllRequiredDependencies(this); var verifier = this.BuildErrorVerifierFunc(expectedStatusCode, expectedMessage, resourceVerifier); this.Injector.InjectDependenciesInto(verifier); verifier.Verifiers.ForEach(v => this.Injector.InjectDependenciesInto(v)); return verifier; }
/// <summary> /// Verifies the ExceptionMessage recursively /// </summary> /// <param name="expectedErrorMessage">Error Message to Verify</param> /// <param name="resourceVerifier">Resource Verifier to use</param> /// <param name="errorPayload">Error payload to verify</param> /// <param name="assert">assert call to make</param> public static void VerifyExceptionMessage(this ExpectedErrorMessage expectedErrorMessage, IStringResourceVerifier resourceVerifier, ODataErrorPayload errorPayload, Action <bool, string> assert) { ExceptionUtilities.CheckArgumentNotNull(expectedErrorMessage, "expectedErrorMessage"); ExceptionUtilities.CheckArgumentNotNull(resourceVerifier, "resourceVerifier"); ExceptionUtilities.CheckArgumentNotNull(errorPayload, "errorPayload"); ExceptionUtilities.CheckArgumentNotNull(assert, "assert"); // Verify messages are the same // TODO: Need to also verify the language and code expectedErrorMessage.VerifyMatch(resourceVerifier, errorPayload.Message, true); ExpectedErrorMessage expectedInnerError = expectedErrorMessage.InnerError; ODataInternalExceptionPayload innerError = errorPayload.InnerError; // Set it to null so comparison won't occur if (expectedErrorMessage.SkipInnerErrorVerification) { innerError = null; expectedInnerError = null; } while (innerError != null) { // TODO: better error message assert(expectedInnerError != null, "Did not expect inner error"); // Verify messages are the same expectedInnerError.VerifyMatch(resourceVerifier, innerError.Message, true); if (expectedInnerError.SkipInnerErrorVerification) { innerError = null; expectedInnerError = null; } else { // TODO: verify stack trace, type name, etc innerError = innerError.InternalException; expectedInnerError = expectedInnerError.InnerError; } } }