public void QueryEntityNavigationWithImplicitKeys() { // this test is to baseline the WCF Data Service behavior that is not modified to support implicit keys Dictionary <string, bool> testCases = new Dictionary <string, bool>() { { "Login('1')/SentMessages(FromUsername='******',MessageId=-10)", false /*expect error*/ }, { "Login('1')/SentMessages(MessageId=-10)", true /*expect error*/ }, { "Login('1')/SentMessages(-10)", true /*expect error*/ }, }; var contextWrapper = this.CreateContext(); foreach (var testCase in testCases) { try { var message = contextWrapper.Execute <Message>(new Uri(this.ServiceUri.OriginalString.TrimEnd('/') + "/" + testCase.Key)).Single(); Assert.False(testCase.Value); Assert.Equal(-10, message.MessageId); } catch (DataServiceQueryException ex) { Assert.True(testCase.Value); Assert.Equal(400, ex.Response.StatusCode); StringResourceUtil.VerifyDataServicesString(ClientExceptionUtil.ExtractServerErrorMessage(ex), "BadRequest_KeyCountMismatch", "Microsoft.Test.OData.Services.AstoriaDefaultService.Message"); //InnerException for DataServiceClientException must be set with the exception response from the server. ODataErrorException oDataErrorException = ex.InnerException.InnerException as ODataErrorException; Assert.True(oDataErrorException != null, "InnerException for DataServiceClientException has not been set."); Assert.Equal("An error was read from the payload. See the 'Error' property for more details.", oDataErrorException.Message); } } }
public void QueryEntityNavigationWithImplicitKeys( string endpoint, bool expectSuccess, /* only used on success */ int messageId, /* only used on error */ string errorStringIdentifier) { // this test is to baseline the WCF Data Service behavior that is not modified to support implicit keys var contextWrapper = this.CreateContext(); if (expectSuccess) { var message = contextWrapper.Execute <Message>(new Uri(this.ServiceUri.OriginalString.TrimEnd('/') + "/" + endpoint)).Single(); Assert.Equal(messageId, message.MessageId); } else { try { var message = contextWrapper.Execute <Message>(new Uri(this.ServiceUri.OriginalString.TrimEnd('/') + "/" + endpoint)).Single(); Assert.False(true, "This statement should not have executed because the request should have thrown an exception."); } catch (DataServiceQueryException ex) { Assert.Equal(400, ex.Response.StatusCode); StringResourceUtil.VerifyODataLibString(ClientExceptionUtil.ExtractServerErrorMessage(ex), errorStringIdentifier, true, "Microsoft.Test.OData.Services.AstoriaDefaultService.Message"); //InnerException for DataServiceClientException must be set with the exception response from the server. ODataErrorException oDataErrorException = ex.InnerException.InnerException as ODataErrorException; Assert.True(oDataErrorException != null, "InnerException for DataServiceClientException has not been set."); Assert.Equal("An error was read from the payload. See the 'Error' property for more details.", oDataErrorException.Message); } } }
public void QueryEntityNavigationWithImplicitKeys() { // this test is to baseline the WCF Data Service behavior that is not modified to support implicit keys Dictionary <string, bool> testCases = new Dictionary <string, bool>() { { "Login('1')/SentMessages(FromUsername='******',MessageId=-10)", false /*expect error*/ }, { "Login('1')/SentMessages(MessageId=-10)", true /*expect error*/ }, { "Login('1')/SentMessages(-10)", true /*expect error*/ }, }; var contextWrapper = this.CreateContext(); foreach (var testCase in testCases) { try { var message = contextWrapper.Execute <Message>(new Uri(this.ServiceUri.OriginalString.TrimEnd('/') + "/" + testCase.Key)).Single(); Assert.IsFalse(testCase.Value); Assert.AreEqual(-10, message.MessageId); } catch (DataServiceQueryException ex) { Assert.IsTrue(testCase.Value); Assert.AreEqual(400, ex.Response.StatusCode); StringResourceUtil.VerifyDataServicesString(ClientExceptionUtil.ExtractServerErrorMessage(ex), "BadRequest_KeyCountMismatch", "Microsoft.Test.OData.Services.AstoriaDefaultService.Message"); } } }
private void VerifyErrorString(DataServiceContext context, string errorUrl, string errorString, params object[] arguments) { try { context.Execute <Computer>(new Uri(this.ServiceUri.OriginalString + errorUrl)); Assert.Fail("Expected Exception not thrown for " + errorUrl); } catch (DataServiceQueryException ex) { Assert.IsNotNull(ex.InnerException, "No inner exception found"); Assert.IsInstanceOfType(ex.InnerException, typeof(DataServiceClientException), "Unexpected inner exception type"); StringResourceUtil.VerifyDataServicesString(ClientExceptionUtil.ExtractServerErrorMessage(ex), errorString, arguments); } }
private void VerifyErrorString(DataServiceContext context, string errorUrl, string errorString, params object[] arguments) { try { context.Execute <Computer>(new Uri(this.ServiceUri.OriginalString + errorUrl)); Assert.True(false, "Expected Exception not thrown for " + errorUrl); } catch (DataServiceQueryException ex) { Assert.NotNull(ex.InnerException); Assert.IsType <DataServiceClientException>(ex.InnerException); StringResourceUtil.VerifyDataServicesString(ClientExceptionUtil.ExtractServerErrorMessage(ex), errorString, arguments); } }
public void ClientWithKeyAsSegmentSendsRequestsToServerWithoutKeyAsSegment() { try { var contextWrapper = this.CreateWrappedContext <InMemoryEntities>(); contextWrapper.UrlKeyDelimiter = DataServiceUrlKeyDelimiter.Slash; contextWrapper.Context.Orders.Where(c => c.OrderID == 0).ToArray(); Assert.True(false, "Expected DataServiceException was not thrown."); } catch (DataServiceQueryException ex) { Assert.NotNull(ex.InnerException); Assert.IsType <DataServiceClientException>(ex.InnerException); StringResourceUtil.VerifyDataServicesString(ClientExceptionUtil.ExtractServerErrorMessage(ex), "RequestUriProcessor_CannotQueryCollections", "Orders"); } }
public void ClientWithKeyAsSegmentSendsRequestsToServerWithoutKeyAsSegment() { try { var contextWrapper = this.CreateWrappedContext <DefaultContainer>(); contextWrapper.UrlConventions = DataServiceUrlConventions.KeyAsSegment; contextWrapper.Context.Customer.Where(c => c.CustomerId == 0).ToArray(); Assert.Fail("Expected DataServiceException was not thrown."); } catch (DataServiceQueryException ex) { Assert.IsNotNull(ex.InnerException, "No inner exception found"); Assert.IsInstanceOfType(ex.InnerException, typeof(DataServiceClientException), "Unexpected inner exception type"); StringResourceUtil.VerifyDataServicesString(ClientExceptionUtil.ExtractServerErrorMessage(ex), "RequestUriProcessor_CannotQueryCollections", "Customer"); } }
public void ModifyQueryOptions() { var context = this.CreateWrappedContext <DefaultContainer>(); var personQuery = context.CreateQuery <Person>("Person"); try { personQuery.Execute(); Assert.Fail("ModifyingQueryOptionsShouldFail"); } catch (DataServiceQueryException ex) { Assert.IsNotNull(ex.InnerException, "No inner exception found"); Assert.IsInstanceOfType(ex.InnerException, typeof(DataServiceClientException), "Unexpected inner exception type"); StringResourceUtil.VerifyDataServicesString(ClientExceptionUtil.ExtractServerErrorMessage(ex), "AstoriaRequestMessage_CannotChangeQueryString"); } }
public void BatchRequestBaseUriDifferentBetweenBatchAndRequest() { var context = this.CreateWrappedContext <DefaultContainer>(); //Setup queries DataServiceRequest[] reqs = new DataServiceRequest[] { context.CreateQuery <Customer>("BatchRequest3"), }; var response = context.ExecuteBatch(reqs); Assert.IsNotNull(response); Assert.IsTrue(response.IsBatchResponse); foreach (QueryOperationResponse item in response) { Assert.IsNotNull(item.Error); Assert.IsInstanceOfType(item.Error, typeof(DataServiceClientException), "Unexpected inner exception type"); var ex = item.Error as DataServiceClientException; StringResourceUtil.VerifyDataServicesString(ClientExceptionUtil.ExtractServerErrorMessage(item), "DataServiceOperationContext_CannotModifyServiceUriInsideBatch"); } }
public void BasesDontMatchFail() { var context = this.CreateWrappedContext <DefaultContainer>(); DataServiceQuery customQuery = context.CreateQuery <Customer>("BasesDontMatchFail"); //Path should remap to the customers set var expectedServiceUrl = "http://potato:9090/FailMeService/"; var expectedRequestUrl = "http://potato:9090/DontFailMeService/Customer"; try { customQuery.Execute(); Assert.Fail("Different service bases between service uri and request uri should fail"); } catch (DataServiceQueryException ex) { Assert.IsNotNull(ex.InnerException, "No inner exception found"); Assert.IsInstanceOfType(ex.InnerException, typeof(DataServiceClientException), "Unexpected inner exception type"); StringResourceUtil.VerifyODataLibString(ClientExceptionUtil.ExtractServerErrorMessage(ex), "UriQueryPathParser_RequestUriDoesNotHaveTheCorrectBaseUri", true, expectedRequestUrl, expectedServiceUrl); } }