-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed an issue where From clause parsing did not work.
- Loading branch information
Showing
2 changed files
with
119 additions
and
3 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
89 changes: 89 additions & 0 deletions
89
test/QueryBuilderByLinq.Test/Analysis/JoinTableInfoParserTest.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,89 @@ | ||
using Carbunql; | ||
using QueryBuilderByLinq.Analysis; | ||
using Xunit.Abstractions; | ||
using static QueryBuilderByLinq.Sql; | ||
|
||
namespace QueryBuilderByLinq.Test.Analysis; | ||
|
||
public class JoinTableInfoParserTest | ||
{ | ||
private readonly QueryCommandMonitor Monitor; | ||
|
||
public JoinTableInfoParserTest(ITestOutputHelper output) | ||
{ | ||
Monitor = new QueryCommandMonitor(output); | ||
Output = output; | ||
} | ||
|
||
private ITestOutputHelper Output { get; set; } | ||
|
||
[Fact] | ||
public void NoRelationTest() | ||
{ | ||
var query = from a in FromTable<sale>() | ||
select a; | ||
|
||
Monitor.Log(query); | ||
|
||
var joins = JoinTableInfoParser.Parse(query.Expression); | ||
|
||
Assert.Empty(joins); | ||
} | ||
|
||
[Fact] | ||
public void InnerJoinTest() | ||
{ | ||
var query = from s in FromTable<sale>() | ||
from a in InnerJoinTable<article>(x => s.article_id == x.article_id) | ||
select a; | ||
|
||
Monitor.Log(query); | ||
|
||
var from = FromTableInfoParser.Parse(query.Expression); | ||
Assert.Equal("sale", from?.ToSelectable().ToText()); | ||
Assert.Equal("s", from?.Alias); | ||
|
||
var joins = JoinTableInfoParser.Parse(query.Expression); | ||
|
||
Assert.Empty(joins); | ||
} | ||
|
||
[Fact] | ||
public void LeftJoinTest() | ||
{ | ||
var query = from s in FromTable<sale>() | ||
from a in LeftJoinTable<article>(x => s.article_id == x.article_id) | ||
select a; | ||
|
||
Monitor.Log(query); | ||
|
||
var from = FromTableInfoParser.Parse(query.Expression); | ||
Assert.Equal("sale", from?.ToSelectable().ToText()); | ||
Assert.Equal("s", from?.Alias); | ||
|
||
var joins = JoinTableInfoParser.Parse(query.Expression); | ||
|
||
Assert.Empty(joins); | ||
} | ||
|
||
[Fact] | ||
public void CrossJoinTest() | ||
{ | ||
var query = from s in FromTable<sale>() | ||
from a in CrossJoinTable<article>() | ||
select a; | ||
|
||
Monitor.Log(query); | ||
|
||
var from = FromTableInfoParser.Parse(query.Expression); | ||
Assert.Equal("sale", from?.ToSelectable().ToText()); | ||
Assert.Equal("s", from?.Alias); | ||
|
||
var joins = JoinTableInfoParser.Parse(query.Expression); | ||
|
||
Assert.Empty(joins); | ||
} | ||
|
||
public record struct sale(int sales_id, int article_id, int quantity); | ||
public record struct article(int article_id, string article_name, int price); | ||
} |