diff --git a/README.md b/README.md index 79e10f9..c6448e1 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,11 @@ public void QueryDatabase(ILogger logger) } ``` +```csharp +var query = DocumentHelper.GetDocuments() + .Where(w => w.WhereInPath("path1", "path2")); +``` + ### ObjectQuery #### Prerequisites diff --git a/tests/XperienceCommunity.QueryExtensions.Tests/Documents/XperienceCommunityDocumentQueryExtensionsTests.cs b/tests/XperienceCommunity.QueryExtensions.Tests/Documents/XperienceCommunityDocumentQueryExtensionsTests.cs index 90230ad..ce4c16e 100644 --- a/tests/XperienceCommunity.QueryExtensions.Tests/Documents/XperienceCommunityDocumentQueryExtensionsTests.cs +++ b/tests/XperienceCommunity.QueryExtensions.Tests/Documents/XperienceCommunityDocumentQueryExtensionsTests.cs @@ -202,5 +202,61 @@ public void MultiDocumentQuery_If_Will_Execute_The_ElseAction_If_The_Condition_I action.ReceivedCalls().Should().BeEmpty(); elseAction.ReceivedCalls().Should().HaveCount(1); } + + [Test] + public void WhereCondition_WhereInPath_Will_Combine_Paths_With_An_Or() + { + var sut = new DocumentQuery(); + + var result = sut.Where(w => w.WhereInPath("path1", "path2")); + + result.WhereCondition.Should().Be("([NodeAliasPath] = @NodeAliasPath OR [NodeAliasPath] = @NodeAliasPath1)"); + result.Parameters.Should().HaveCount(2); + + var param1 = result.Parameters[0]; + var param2 = result.Parameters[1]; + + param1.Name.Should().Be("@NodeAliasPath"); + param1.Value.Should().Be("path1"); + + param2.Name.Should().Be("@NodeAliasPath1"); + param2.Value.Should().Be("path2"); + } + + [Test] + public void WhereCondition_WhereInPath_PathType_Children_Will_Combine_Paths_With_An_Or() + { + var sut = new DocumentQuery(); + + var result = sut.Where(w => w.WhereInPath("path1", PathTypeEnum.Children)); + + result.WhereCondition.Should().Be("[NodeAliasPath] LIKE @NodeAliasPath"); + result.Parameters.Should().HaveCount(1); + + var param1 = result.Parameters[0]; + + param1.Name.Should().Be("@NodeAliasPath"); + param1.Value.Should().Be("path1/%"); + } + + [Test] + public void WhereCondition_WhereInPath_PathType_Section_Will_Combine_Paths_With_An_Or() + { + var sut = new DocumentQuery(); + + var result = sut.Where(w => w.WhereInPath("path1", PathTypeEnum.Section)); + + result.WhereCondition.Should().Be("([NodeAliasPath] LIKE @NodeAliasPath OR [NodeAliasPath] = @NodeAliasPath1)"); + result.Parameters.Should().HaveCount(2); + + var param1 = result.Parameters[0]; + var param2 = result.Parameters[1]; + + param1.Name.Should().Be("@NodeAliasPath"); + param1.Value.Should().Be("path1/%"); + + param2.Name.Should().Be("@NodeAliasPath1"); + param2.Value.Should().Be("/path1"); + } } }