/// <summary> /// Compares the ClientExpectedException to the provided exception and verifies the exception is correct /// </summary> /// <param name="expectedClientException">Expected Client Exception</param> /// <param name="exception">Actual Exception</param> public void Compare(ExpectedClientErrorBaseline expectedClientException, Exception exception) { ExceptionUtilities.CheckAllRequiredDependencies(this); if (expectedClientException == null) { string exceptionMessage = null; if (exception != null) { exceptionMessage = exception.ToString(); } this.Assert.IsNull(exception, "Expected to not recieve an exception:" + exceptionMessage); return; } this.Assert.IsNotNull(exception, "Expected Exception to not be null"); this.Assert.AreEqual(expectedClientException.ExpectedExceptionType, exception.GetType(), string.Format(CultureInfo.InvariantCulture, "ExceptionType is not equal, receieved the following exception: {0}", exception.ToString())); if (expectedClientException.HasServerSpecificExpectedMessage) { if (this.ShouldVerifyServerMessageInClientException) { this.Assert.IsNotNull(exception.InnerException, "Expected Inner Exception to contain ODataError"); byte[] byteArrPayload = HttpUtilities.DefaultEncoding.GetBytes(exception.InnerException.Message); ODataErrorPayload errorPayload = this.ProtocolFormatStrategySelector.DeserializeAndCast<ODataErrorPayload>(null, MimeTypes.ApplicationXml, byteArrPayload); expectedClientException.ExpectedExceptionMessage.VerifyMatch(this.systemDataServicesVerifier, errorPayload.Message, true); } } else { expectedClientException.ExpectedExceptionMessage.VerifyMatch(this.systemDataServicesClientVerifier, exception.Message, true); } }
internal static CodeExpression BuildClientExpectedErrorExpression(ExpectedClientErrorBaseline clientExpectedErrorExpression) { if (clientExpectedErrorExpression == null) { return Code.Null(); } CodeExpression expectedExceptionMessageExpression = BuildExpectedErrorMessage(clientExpectedErrorExpression.ExpectedExceptionMessage); return Code.New( Code.TypeRef(typeof(ExpectedClientErrorBaseline)), Code.TypeOf(Code.TypeRef(clientExpectedErrorExpression.ExpectedExceptionType)), Code.Primitive(clientExpectedErrorExpression.HasServerSpecificExpectedMessage), expectedExceptionMessageExpression); }
public static void ExecuteUriAndCompareSync <TResult>(this IClientQueryResultComparer linqToAstoriaResultComparer, IQueryable <TResult> query, string uriString, QueryValue expectedValue, DataServiceContext dataContext, ExpectedClientErrorBaseline clientExpectedError) { SyncHelpers.ExecuteActionAndWait(c => linqToAstoriaResultComparer.ExecuteUriAndCompare <TResult>(c, false, query, uriString, expectedValue, dataContext, clientExpectedError)); }
public static void ExecuteUriAndCompare <TResult>(this IClientQueryResultComparer linqToAstoriaResultComparer, IAsyncContinuation continuation, IQueryable <TResult> query, string uriString, QueryValue expectedValue, DataServiceContext dataContext, ExpectedClientErrorBaseline clientExpectedError) { linqToAstoriaResultComparer.ExecuteUriAndCompare <TResult>(continuation, true, query, uriString, expectedValue, dataContext, clientExpectedError); }
public static void ExecuteUriAndCompareSync <TResult>(this IClientQueryResultComparer linqToAstoriaResultComparer, IQueryable <TResult> query, string uriString, QueryValue expectedValue, DataServiceContext dataContext, ExpectedClientErrorBaseline clientExpectedError) { #if !SILVERLIGHT SyncHelpers.ExecuteActionAndWait(c => linqToAstoriaResultComparer.ExecuteUriAndCompare <TResult>(c, false, query, uriString, expectedValue, dataContext, clientExpectedError)); #else throw new TaupoInvalidOperationException("Cannot execute in Silverlight"); #endif }
public void Compare(ExpectedClientErrorBaseline expectedClientException, Exception exception) { throw new NotImplementedException(); }
/// <summary> /// Returns the error expected for the Query /// </summary> /// <param name="expression">The expression.</param> /// <param name="usesClientQueryable">Whether the client uri is build from a Client Linq expression or not</param> /// <param name="clientMaxProtocolVersion">Client Max Protocol Version</param> /// <param name="maxProtocolVersion">Max Protocol version of the server</param> /// <returns> a versioning error at the Client level</returns> public ExpectedClientErrorBaseline CalculateExpectedClientVersionError(QueryExpression expression, bool usesClientQueryable, DataServiceProtocolVersion clientMaxProtocolVersion, DataServiceProtocolVersion maxProtocolVersion) { ExceptionUtilities.CheckArgumentNotNull(expression, "expression"); ExceptionUtilities.CheckAllRequiredDependencies(this); DataServiceProtocolVersion expectedDataServiceVersion = DataServiceProtocolVersion.Unspecified; DataServiceProtocolVersion minRequiredRequestVersion = DataServiceProtocolVersion.Unspecified; ExpectedErrorMessage errorInformation; // If the Client Queryable interface is not used to build the expression that is run then no error can happen at this stage // There can only be a protocol error from the server if there is no client error var serverExpression = this.ClientSideProjectionReplacer.ReplaceClientSideProjections(expression); ODataUri odataUri = this.QueryToODataUriConverter.ComputeUri(serverExpression); // Predict what the Client will generate for the data service version, if we are not using client.linq its unspecified otherwise calculate it if (usesClientQueryable) { ExpectedClientErrorBaseline expectedErrorIfTooLow; minRequiredRequestVersion = this.CalculateExpectedClientMinRequestVersion(odataUri, out expectedErrorIfTooLow); if (minRequiredRequestVersion > clientMaxProtocolVersion) { if (expectedErrorIfTooLow == null) { errorInformation = new ExpectedErrorMessage("Context_RequestVersionIsBiggerThanProtocolVersion", minRequiredRequestVersion.ConvertToHeaderFormat(), clientMaxProtocolVersion.ConvertToHeaderFormat()); expectedErrorIfTooLow = new ExpectedClientErrorBaseline(typeof(InvalidOperationException), false, errorInformation); } return expectedErrorIfTooLow; } EntitySet expectedEntitySet = null; if (odataUri.TryGetExpectedEntitySet(out expectedEntitySet)) { DataServiceProtocolVersion entitySetVersion = expectedEntitySet.CalculateEntitySetProtocolVersion(MimeTypes.ApplicationAtomXml, VersionCalculationType.Request, maxProtocolVersion, clientMaxProtocolVersion); // Client will create a DSV based on the following pieces, metadata of the query based on sets it goes through, uri contructs (select, count, inlinecount, etc) // and headers (like DataServiceResponsePreference). In order to mimic this client behavior I will get the metadata version and a version // from the minrequestVersion and take the max. MinRequest deals with Uri and headers, metadata the metadata. expectedDataServiceVersion = VersionHelper.GetMaximumVersion(minRequiredRequestVersion, entitySetVersion); } } ODataRequest request = new ODataRequest(this.ODataUriToStringConverter) { Uri = odataUri, Verb = HttpVerb.Get, Headers = { { HttpHeaders.DataServiceVersion, expectedDataServiceVersion.ConvertToHeaderFormat() }, { HttpHeaders.MaxDataServiceVersion, clientMaxProtocolVersion.ConvertToHeaderFormat() }, { HttpHeaders.Accept, MimeTypes.ApplicationAtomXml } } }; if (this.ODataRequestVersionResourceErrorCalculator.TryCalculateError(request, maxProtocolVersion, out errorInformation)) { return new ExpectedClientErrorBaseline(typeof(DSClient.DataServiceQueryException), true, errorInformation); } return null; }
private DataServiceProtocolVersion CalculateExpectedClientMinRequestVersion(ODataUri odataUri, out ExpectedClientErrorBaseline errorIfTooLow) { ExceptionUtilities.CheckArgumentNotNull(odataUri, "odataUri"); DataServiceProtocolVersion expectedVersion = DataServiceProtocolVersion.V4; errorIfTooLow = null; // Uri specific processing if (odataUri.HasAnyOrAllInFilter()) { expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, DataServiceProtocolVersion.V4); string anyOrAll = string.Empty; if (odataUri.Filter.Contains("/any(")) { anyOrAll = "Any"; } else { anyOrAll = "All"; } var errorInformation = new ExpectedErrorMessage("ALinq_MethodNotSupportedForMaxDataServiceVersionLessThanX", anyOrAll, expectedVersion.ConvertToHeaderFormat()); errorIfTooLow = new ExpectedClientErrorBaseline(typeof(NotSupportedException), false, errorInformation); } if (odataUri.HasSignificantTypeSegmentInPath()) { // TODO: this seems like it should be inferred from the query, not the uri expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, DataServiceProtocolVersion.V4); var errorInformation = new ExpectedErrorMessage("ALinq_MethodNotSupportedForMaxDataServiceVersionLessThanX", "OfType", expectedVersion.ConvertToHeaderFormat()); errorIfTooLow = new ExpectedClientErrorBaseline(typeof(NotSupportedException), false, errorInformation); } else if (odataUri.HasTypeSegmentInExpandOrSelect()) { // TODO: this seems like it should be inferred from the query, not the uri expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, DataServiceProtocolVersion.V4); var errorInformation = new ExpectedErrorMessage("ALinq_TypeAsNotSupportedForMaxDataServiceVersionLessThan3"); errorIfTooLow = new ExpectedClientErrorBaseline(typeof(NotSupportedException), false, errorInformation); } return expectedVersion; }