From c31743691b112a197e5c233b1d34eae01ca4e1b3 Mon Sep 17 00:00:00 2001 From: Faraz Ahmed Date: Mon, 7 May 2018 15:12:06 -0400 Subject: [PATCH 1/4] added changes for fix and fixed tests --- .../Services/QueryComposer.cs | 2 +- test/UnitTests/Services/QueryComposerTests.cs | 29 ++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/JsonApiDotNetCore/Services/QueryComposer.cs b/src/JsonApiDotNetCore/Services/QueryComposer.cs index 8fbf16339b..9747f6d47d 100644 --- a/src/JsonApiDotNetCore/Services/QueryComposer.cs +++ b/src/JsonApiDotNetCore/Services/QueryComposer.cs @@ -31,7 +31,7 @@ public string Compose(IJsonApiContext jsonApiContext) private string ComposeSingleFilter(FilterQuery query) { var result = "&filter"; - result += QueryConstants.OPEN_BRACKET + query.Attribute + QueryConstants.CLOSE_BRACKET + query.Operation + query.Value; + result += QueryConstants.OPEN_BRACKET + query.Attribute + QueryConstants.CLOSE_BRACKET + "=" + query.Operation + ":" + query.Value; return result; } } diff --git a/test/UnitTests/Services/QueryComposerTests.cs b/test/UnitTests/Services/QueryComposerTests.cs index e1bd892756..cf54d10a5a 100644 --- a/test/UnitTests/Services/QueryComposerTests.cs +++ b/test/UnitTests/Services/QueryComposerTests.cs @@ -17,10 +17,10 @@ public QueryComposerTests() } [Fact] - public void Can_Compose_FilterStringForUrl() + public void Can_ComposeEqual_FilterStringForUrl() { // arrange - var filter = new FilterQuery("attribute", "value", "="); + var filter = new FilterQuery("attribute", "value", "eq"); var querySet = new QuerySet(); List filters = new List(); filters.Add(filter); @@ -34,7 +34,28 @@ public void Can_Compose_FilterStringForUrl() // act var filterString = queryComposer.Compose(_jsonApiContext.Object); // assert - Assert.Equal("&filter[attribute]=value", filterString); + Assert.Equal("&filter[attribute]=eq:value", filterString); + } + + [Fact] + public void Can_ComposeLessThan_FilterStringForUrl() + { + // arrange + var filter = new FilterQuery("attribute", "value", "le"); + var querySet = new QuerySet(); + List filters = new List(); + filters.Add(filter); + querySet.Filters = filters; + + _jsonApiContext + .Setup(m => m.QuerySet) + .Returns(querySet); + + var queryComposer = new QueryComposer(); + // act + var filterString = queryComposer.Compose(_jsonApiContext.Object); + // assert + Assert.Equal("&filter[attribute]=le:value", filterString); } [Fact] @@ -54,4 +75,4 @@ public void NoFilter_Compose_EmptyStringReturned() Assert.Equal("", filterString); } } -} \ No newline at end of file +} From d98952c3019ff5be1373efd9ae82fbff05f38d70 Mon Sep 17 00:00:00 2001 From: Faraz Ahmed Date: Mon, 7 May 2018 15:20:17 -0400 Subject: [PATCH 2/4] fixes #277 From 7614b500ae87fc77f629d485d19bb483e5215ec1 Mon Sep 17 00:00:00 2001 From: Jared Nance Date: Mon, 7 May 2018 15:08:18 -0500 Subject: [PATCH 3/4] bump package version --- src/JsonApiDotNetCore/JsonApiDotNetCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj index ccebe08784..53649bb7e7 100755 --- a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj +++ b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj @@ -1,6 +1,6 @@  - 2.2.2 + 2.2.3 $(NetStandardVersion) JsonApiDotNetCore JsonApiDotNetCore From 11b3ccd3d785843a5ae516575592271b9baf3c3c Mon Sep 17 00:00:00 2001 From: Faraz Ahmed Date: Mon, 7 May 2018 16:12:27 -0400 Subject: [PATCH 4/4] validation fix --- src/JsonApiDotNetCore/Services/QueryComposer.cs | 3 ++- test/UnitTests/Services/QueryComposerTests.cs | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/JsonApiDotNetCore/Services/QueryComposer.cs b/src/JsonApiDotNetCore/Services/QueryComposer.cs index 9747f6d47d..8e0819a438 100644 --- a/src/JsonApiDotNetCore/Services/QueryComposer.cs +++ b/src/JsonApiDotNetCore/Services/QueryComposer.cs @@ -31,7 +31,8 @@ public string Compose(IJsonApiContext jsonApiContext) private string ComposeSingleFilter(FilterQuery query) { var result = "&filter"; - result += QueryConstants.OPEN_BRACKET + query.Attribute + QueryConstants.CLOSE_BRACKET + "=" + query.Operation + ":" + query.Value; + var operation = string.IsNullOrWhiteSpace(query.Operation) ? query.Operation : query.Operation + ":"; + result += QueryConstants.OPEN_BRACKET + query.Attribute + QueryConstants.CLOSE_BRACKET + "=" + operation + query.Value; return result; } } diff --git a/test/UnitTests/Services/QueryComposerTests.cs b/test/UnitTests/Services/QueryComposerTests.cs index cf54d10a5a..91df486212 100644 --- a/test/UnitTests/Services/QueryComposerTests.cs +++ b/test/UnitTests/Services/QueryComposerTests.cs @@ -42,9 +42,11 @@ public void Can_ComposeLessThan_FilterStringForUrl() { // arrange var filter = new FilterQuery("attribute", "value", "le"); + var filter2 = new FilterQuery("attribute2", "value2", ""); var querySet = new QuerySet(); List filters = new List(); filters.Add(filter); + filters.Add(filter2); querySet.Filters = filters; _jsonApiContext @@ -55,7 +57,7 @@ public void Can_ComposeLessThan_FilterStringForUrl() // act var filterString = queryComposer.Compose(_jsonApiContext.Object); // assert - Assert.Equal("&filter[attribute]=le:value", filterString); + Assert.Equal("&filter[attribute]=le:value&filter[attribute2]=value2", filterString); } [Fact]