forked from OrchardCMS/OrchardCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix graphql where clause when database schema is configured (OrchardC…
…MS#16364) Co-authored-by: mdameer <[email protected]> Co-authored-by: Hisham Bin Ateya <[email protected]> Co-authored-by: Tony Han <[email protected]>
- Loading branch information
1 parent
5207b37
commit 52dca20
Showing
2 changed files
with
83 additions
and
2 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
81 changes: 81 additions & 0 deletions
81
test/OrchardCore.Tests/Apis/GraphQL/Queries/PredicateQueryTests.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,81 @@ | ||
using OrchardCore.ContentManagement.GraphQL.Queries; | ||
using OrchardCore.ContentManagement.GraphQL.Queries.Predicates; | ||
using YesSql.Indexes; | ||
|
||
namespace OrchardCore.Tests.Apis.GraphQL; | ||
|
||
public class PredicateQueryTests | ||
{ | ||
private YesSql.IConfiguration _configuration; | ||
|
||
public PredicateQueryTests() | ||
{ | ||
_configuration = new Configuration() | ||
.UseSqlServer("Fake database connection string for testing;", "TenantSchema") | ||
.SetTablePrefix("Tenant1"); | ||
} | ||
|
||
[Fact] | ||
public void ShouldReturnQuotedColumnNameWhenAliasNotExists() | ||
{ | ||
// Arrange | ||
var predicateQuery = new PredicateQuery(_configuration, []); | ||
|
||
// Act | ||
var columnName = predicateQuery.GetColumnName("ListItemIndex.Value"); | ||
|
||
// Assert | ||
Assert.Equal("[ListItemIndex.Value]", columnName); | ||
} | ||
|
||
[Fact] | ||
public void ShouldReturnQuotedAliasColumnNameWhenAliasExists() | ||
{ | ||
// Arrange | ||
var predicateQuery = new PredicateQuery(_configuration, []); | ||
predicateQuery.CreateAlias("ListItemIndexPath.ValuePath", "ListItemIndexAlias.ValueAlias"); | ||
|
||
// Act | ||
var columnName = predicateQuery.GetColumnName("ListItemIndexPath.ValuePath"); | ||
|
||
// Assert | ||
Assert.Equal("[ListItemIndexAlias.ValueAlias]", columnName); | ||
} | ||
|
||
[Fact] | ||
public void ShouldReturnQuotedTableAliasAndColumnNameWhenProviderExists() | ||
{ | ||
// Arrange | ||
var predicateQuery = new PredicateQuery(_configuration, [new IndexPropertyProvider<ListItemIndex>()]); | ||
|
||
predicateQuery.CreateAlias("ListItemIndexPath", nameof(ListItemIndex)); | ||
predicateQuery.CreateTableAlias(nameof(ListItemIndex), "ListItemIndexAlias"); | ||
|
||
// Act | ||
var columnName = predicateQuery.GetColumnName("ListItemIndexPath.Value"); | ||
|
||
// Assert | ||
Assert.Equal("[ListItemIndexAlias].[Value]", columnName); | ||
} | ||
|
||
[Fact] | ||
public void ShouldReturnQuotedTableAliasAndPathWhenProviderNotExists() | ||
{ | ||
// Arrange | ||
var predicateQuery = new PredicateQuery(_configuration, []); | ||
|
||
predicateQuery.CreateAlias("ListItemIndexPath", nameof(ListItemIndex)); | ||
predicateQuery.CreateTableAlias(nameof(ListItemIndex), "ListItemIndexAlias"); | ||
|
||
// Act | ||
var columnName = predicateQuery.GetColumnName("ListItemIndexPath.Value"); | ||
|
||
// Assert | ||
Assert.Equal("[ListItemIndexAlias].[Value]", columnName); | ||
} | ||
|
||
public class ListItemIndex : MapIndex | ||
{ | ||
public string Value { get; set; } | ||
} | ||
} |