public void ValidateQuery_Throws_WithNullQueryOptions() { // Arrange QueryableAttribute attribute = new QueryableAttribute(); // Act & Assert Assert.ThrowsArgumentNull(() => attribute.ValidateQuery(new HttpRequestMessage(), null), "queryOptions"); }
public void ValidateQuery_Throws_With_Null_Request() { // Arrange QueryableAttribute attribute = new QueryableAttribute(); // Act & Assert Assert.ThrowsArgumentNull(() => attribute.ValidateQuery(null), "request"); }
public void ValidateQuery_Accepts_All_Supported_QueryNames(string queryName) { // Arrange QueryableAttribute attribute = new QueryableAttribute(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/?" + queryName); // Act & Assert attribute.ValidateQuery(request); }
public void ValidateQuery_Throws_With_Null_Request() { // Arrange QueryableAttribute attribute = new QueryableAttribute(); var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel(); var options = new ODataQueryOptions(new ODataQueryContext(model, typeof(System.Web.Http.OData.Builder.TestModels.Customer), "Customers"), new HttpRequestMessage()); // Act & Assert Assert.ThrowsArgumentNull(() => attribute.ValidateQuery(null, options), "request"); }
public void OrderByAllowedPropertiesWithSpaces(string allowedProperties) { QueryableAttribute attribute = new QueryableAttribute(); attribute.AllowedOrderByProperties = allowedProperties; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Customers/?$orderby=Id,Name"); ODataQueryOptions queryOptions = new ODataQueryOptions(ValidationTestHelper.CreateCustomerContext(), request); Assert.DoesNotThrow(() => attribute.ValidateQuery(request, queryOptions)); }
public void ValidateQuery_Accepts_All_Supported_QueryNames(string queryName) { // Arrange QueryableAttribute attribute = new QueryableAttribute(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/?" + queryName + "=x"); var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel(); var options = new ODataQueryOptions(new ODataQueryContext(model, typeof(System.Web.Http.OData.Builder.TestModels.Customer), "Customers"), request); // Act & Assert attribute.ValidateQuery(request, options); }
public void OrderByDisllowedPropertiesWithSpaces(string allowedProperties) { QueryableAttribute attribute = new QueryableAttribute(); attribute.AllowedOrderByProperties = allowedProperties; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Customers/?$orderby=Id,Name"); ODataQueryOptions queryOptions = new ODataQueryOptions(ValidationTestHelper.CreateCustomerContext(), request); Assert.Throws <ODataException>(() => attribute.ValidateQuery(request, queryOptions), "Order by 'Name' is not allowed. To allow it, set the 'AllowedOrderByProperties' property on QueryableAttribute or QueryValidationSettings."); }
public void ValidateQuery_Sends_BadRequest_For_Unrecognized_QueryNames() { // Arrange QueryableAttribute attribute = new QueryableAttribute(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/?$xxx"); // Act & Assert HttpResponseException responseException = Assert.Throws <HttpResponseException>( () => attribute.ValidateQuery(request)); Assert.Equal(HttpStatusCode.BadRequest, responseException.Response.StatusCode); }
public void ValidateQuery_Sends_BadRequest_For_Unrecognized_QueryNames() { // Arrange QueryableAttribute attribute = new QueryableAttribute(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/?$xxx"); var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel(); var options = new ODataQueryOptions(new ODataQueryContext(model, typeof(System.Web.Http.OData.Builder.TestModels.Customer), "Customers"), request); // Act & Assert HttpResponseException responseException = Assert.Throws <HttpResponseException>( () => attribute.ValidateQuery(request, options)); Assert.Equal(HttpStatusCode.BadRequest, responseException.Response.StatusCode); }
public void ValidateQuery_Throws_With_Null_Request() { // Arrange QueryableAttribute attribute = new QueryableAttribute(); // Act & Assert Assert.ThrowsArgumentNull(() => attribute.ValidateQuery(null), "request"); }
public void ValidateQuery_Sends_BadRequest_For_Unrecognized_QueryNames() { // Arrange QueryableAttribute attribute = new QueryableAttribute(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/?$xxx"); var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel(); var options = new ODataQueryOptions(new ODataQueryContext(model, typeof(System.Web.Http.OData.Builder.TestModels.Customer), "Customers"), request); // Act & Assert HttpResponseException responseException = Assert.Throws<HttpResponseException>( () => attribute.ValidateQuery(request, options)); Assert.Equal(HttpStatusCode.BadRequest, responseException.Response.StatusCode); }
public void ValidateQuery_Accepts_All_Supported_QueryNames(string queryName) { // Arrange QueryableAttribute attribute = new QueryableAttribute(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/?" + queryName + "=x"); var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel(); var options = new ODataQueryOptions(new ODataQueryContext(model, typeof(System.Web.Http.OData.Builder.TestModels.Customer), "Customers"), request); // Act & Assert attribute.ValidateQuery(request, options); }
public void ValidateQuery_Throws_WithNullQueryOptions() { // Arrange QueryableAttribute attribute = new QueryableAttribute(); // Act & Assert Assert.ThrowsArgumentNull(() => attribute.ValidateQuery(new HttpRequestMessage(), null), "queryOptions"); }
public void ValidateQuery_Throws_With_Null_Request() { // Arrange QueryableAttribute attribute = new QueryableAttribute(); var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel(); var options = new ODataQueryOptions(new ODataQueryContext(model, typeof(System.Web.Http.OData.Builder.TestModels.Customer), "Customers"), new HttpRequestMessage()); // Act & Assert Assert.ThrowsArgumentNull(() => attribute.ValidateQuery(null, options), "request"); }
public void OrderByAllowedPropertiesWithSpaces(string allowedProperties) { QueryableAttribute attribute = new QueryableAttribute(); attribute.AllowedOrderByProperties = allowedProperties; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Customers/?$orderby=Id,Name"); ODataQueryOptions queryOptions = new ODataQueryOptions(ValidationTestHelper.CreateCustomerContext(), request); Assert.DoesNotThrow(() => attribute.ValidateQuery(request, queryOptions)); }
public void ValidateQuery_Accepts_All_Supported_QueryNames(string queryName) { // Arrange QueryableAttribute attribute = new QueryableAttribute(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/?" + queryName); // Act & Assert attribute.ValidateQuery(request); }
public void ValidateQuery_Sends_BadRequest_For_Unrecognized_QueryNames() { // Arrange QueryableAttribute attribute = new QueryableAttribute(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/?$xxx"); // Act & Assert HttpResponseException responseException = Assert.Throws<HttpResponseException>( () => attribute.ValidateQuery(request)); Assert.Equal(HttpStatusCode.BadRequest, responseException.Response.StatusCode); }
public void OrderByDisllowedPropertiesWithSpaces(string allowedProperties) { QueryableAttribute attribute = new QueryableAttribute(); attribute.AllowedOrderByProperties = allowedProperties; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Customers/?$orderby=Id,Name"); ODataQueryOptions queryOptions = new ODataQueryOptions(ValidationTestHelper.CreateCustomerContext(), request); Assert.Throws<ODataException>(() => attribute.ValidateQuery(request, queryOptions), "Order by 'Name' is not allowed. To allow it, set the 'AllowedOrderByProperties' property on QueryableAttribute or QueryValidationSettings."); }