-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support facet on IEnumerable property
- Add methods for supporting facet for IEnumerable property - Add unit tests for feature
- Loading branch information
1 parent
a1f1f13
commit c5780a1
Showing
4 changed files
with
134 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
APIs/src/Testing/EpiServer.ContentGraph.UnitTests/ExtensionTests/FacetExtensionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using EPiServer.ContentGraph.Api.Querying; | ||
using EpiServer.ContentGraph.UnitTests.QueryTypeObjects; | ||
using Xunit; | ||
using EPiServer.ContentGraph.Extensions; | ||
|
||
namespace EpiServer.ContentGraph.UnitTests.ExtensionTests | ||
{ | ||
[CollectionDefinition("Facet extension tests")] | ||
public class FacetExtensionTests | ||
{ | ||
TypeQueryBuilder<RequestTypeObject> typeQueryBuilder; | ||
public FacetExtensionTests() | ||
{ | ||
typeQueryBuilder = new TypeQueryBuilder<RequestTypeObject>(); | ||
} | ||
|
||
[Fact] | ||
public void generate_facet_filter_with_extension() | ||
{ | ||
const string expectedFields = "items{Property1}"; | ||
const string expectedFacet = "facets{Property1(filters: [\"test\"]){name count}}"; | ||
const string expectedFullQuery = $"RequestTypeObject{{{expectedFields} {expectedFacet}}}"; | ||
|
||
typeQueryBuilder.Field(x => x.Property1); | ||
typeQueryBuilder.Facet(x => x.Property1.FacetFilters("test")); | ||
|
||
var query = typeQueryBuilder.ToQuery().GetQuery(); | ||
|
||
Assert.NotNull(query); | ||
Assert.Contains(expectedFacet, query.Query); | ||
Assert.Equal(query.Query, expectedFullQuery); | ||
} | ||
[Fact] | ||
public void generate_facet_limit_with_extension() | ||
{ | ||
const string expectedFields = "items{Property1}"; | ||
const string expectedFacet = "facets{Property1(limit: 10){name count}}"; | ||
const string expectedFullQuery = $"RequestTypeObject{{{expectedFields} {expectedFacet}}}"; | ||
|
||
typeQueryBuilder.Field(x => x.Property1); | ||
typeQueryBuilder.Facet(x => x.Property1.FacetLimit(10)); | ||
|
||
var query = typeQueryBuilder.ToQuery().GetQuery(); | ||
|
||
Assert.NotNull(query); | ||
Assert.Contains(expectedFacet, query.Query); | ||
Assert.Equal(query.Query, expectedFullQuery); | ||
} | ||
[Fact] | ||
public void generate_facet_with_IEnumerable() | ||
{ | ||
const string expectedFields = "items{Property1}"; | ||
const string expectedFacet = "facets{Nesteds{NestedProperty{name count}}}"; | ||
const string expectedFullQuery = $"RequestTypeObject{{{expectedFields} {expectedFacet}}}"; | ||
|
||
typeQueryBuilder.Field(x => x.Property1); | ||
typeQueryBuilder.Facet(x => x.Nesteds, f=> f.NestedProperty); | ||
|
||
var query = typeQueryBuilder.ToQuery().GetQuery(); | ||
|
||
Assert.NotNull(query); | ||
Assert.Contains(expectedFacet, query.Query); | ||
Assert.Equal(query.Query, expectedFullQuery); | ||
} | ||
[Fact] | ||
public void generate_facet_limit_with_IEnumerable() | ||
{ | ||
const string expectedFields = "items{Property1}"; | ||
const string expectedFacet = "facets{Nesteds{NestedProperty(limit: 10){name count}}}"; | ||
const string expectedFullQuery = $"RequestTypeObject{{{expectedFields} {expectedFacet}}}"; | ||
|
||
typeQueryBuilder.Field(x => x.Property1); | ||
typeQueryBuilder.Facet(x => x.Nesteds, f => f.NestedProperty.FacetLimit(10)); | ||
|
||
var query = typeQueryBuilder.ToQuery().GetQuery(); | ||
|
||
Assert.NotNull(query); | ||
Assert.Contains(expectedFacet, query.Query); | ||
Assert.Equal(query.Query, expectedFullQuery); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters