Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move parsing tests of different components to dedicated files
- Loading branch information
Showing
4 changed files
with
225 additions
and
176 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
src/FluentSQL.Tests/Compilation/Parser/FromQueryParserTests.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,92 @@ | ||
using System.Linq; | ||
|
||
using FluentAssertions; | ||
|
||
using FluentSQL.Compilation.Parser; | ||
using FluentSQL.Querying; | ||
using FluentSQL.Querying.Statements.Extensions; | ||
using FluentSQL.Tests.Builders; | ||
using FluentSQL.Tests.Compilation.Parser.Builders; | ||
using FluentSQL.Tests.Examples; | ||
using FluentSQL.Tests.Examples.Builders; | ||
|
||
using Xunit; | ||
|
||
namespace FluentSQL.Tests.Compilation.Parser | ||
{ | ||
public class FromQueryParserTests | ||
{ | ||
public class When_parsing_without_an_alias : Specification<QueryParser> | ||
{ | ||
protected override QueryParser EstablishContext() | ||
{ | ||
ExampleModel model = new ExampleModelBuilder().Build(); | ||
|
||
QueryContext = | ||
model.Query<string>() | ||
.From(() => model.Customers) | ||
.QueryContext; | ||
|
||
return new QueryParserBuilder().Build(); | ||
} | ||
|
||
protected override void Because(QueryParser sut) | ||
{ | ||
RootNode = sut.Parse(QueryContext); | ||
} | ||
|
||
[Fact] | ||
public void It_should_add_the_from_clause() | ||
{ | ||
RootNode.ChildNodes.OfType<FromNode>().Should().ContainSingle(); | ||
} | ||
|
||
[Fact] | ||
public void It_should_have_no_alias() | ||
{ | ||
RootNode.ChildNodes.OfType<FromNode>().Single().Alias.Should().BeNull(); | ||
} | ||
|
||
private AstNode RootNode { get; set; } | ||
private QueryContext<NoParameters, string> QueryContext { get; set; } | ||
} | ||
|
||
public class When_parsing_with_an_alias : Specification<QueryParser> | ||
{ | ||
protected override QueryParser EstablishContext() | ||
{ | ||
Alias = new RandomStringBuilder().ThatStartsWithLetter.Build(); | ||
ExampleModel model = new ExampleModelBuilder().Build(); | ||
|
||
QueryContext = | ||
model.Query<string>() | ||
.From(() => model.Customers).As(Alias) | ||
.QueryContext; | ||
|
||
return new QueryParserBuilder().Build(); | ||
} | ||
|
||
protected override void Because(QueryParser sut) | ||
{ | ||
RootNode = sut.Parse(QueryContext); | ||
} | ||
|
||
[Fact] | ||
public void It_should_add_the_from_clause() | ||
{ | ||
RootNode.ChildNodes.OfType<FromNode>().Should().ContainSingle(); | ||
} | ||
|
||
[Fact] | ||
public void It_should_have_the_alias() | ||
{ | ||
RootNode.ChildNodes.OfType<FromNode>().Single().Alias.Should().Be(Alias); | ||
} | ||
|
||
private AstNode RootNode { get; set; } | ||
|
||
private string Alias { get; set; } | ||
private QueryContext<NoParameters, string> QueryContext { get; set; } | ||
} | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
src/FluentSQL.Tests/Compilation/Parser/UnionAllQueryParserTests.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,66 @@ | ||
using FluentAssertions; | ||
|
||
using FluentSQL.Compilation.Parser; | ||
using FluentSQL.Querying; | ||
using FluentSQL.Querying.Statements.Extensions; | ||
using FluentSQL.Tests.Builders; | ||
using FluentSQL.Tests.Compilation.Parser.Builders; | ||
using FluentSQL.Tests.Compilation.Parser.Extensions; | ||
using FluentSQL.Tests.Examples; | ||
using FluentSQL.Tests.Examples.Builders; | ||
|
||
using Xunit; | ||
|
||
namespace FluentSQL.Tests.Compilation.Parser | ||
{ | ||
public class UnionAllQueryParserTests | ||
{ | ||
public class When_parsing : Specification<QueryParser> | ||
{ | ||
protected override QueryParser EstablishContext() | ||
{ | ||
ExampleModel model = new ExampleModelBuilder().Build(); | ||
|
||
FirstAlias = new RandomStringBuilder().ThatStartsWithLetter.Build(); | ||
SecondAlias = new RandomStringBuilder().ThatStartsWithLetter.Build(); | ||
|
||
QueryComponent<NoParameters, string> first = | ||
model.Query<string>() | ||
.From(() => model.Customers).As(FirstAlias) | ||
.Select(() => model.Customers.Name); | ||
|
||
QueryComponent<NoParameters, string> second = | ||
model.Query<string>() | ||
.From(() => model.Invoices).As(SecondAlias) | ||
.Select(() => model.Invoices.InvoiceNumber); | ||
|
||
QueryContext = first.UnionAll(second).QueryContext; | ||
|
||
return new QueryParserBuilder().Build(); | ||
} | ||
|
||
protected override void Because(QueryParser sut) | ||
{ | ||
RootNode = sut.Parse(QueryContext); | ||
} | ||
|
||
[Fact] | ||
public void It_should_return_an_union_node() | ||
{ | ||
RootNode.Should().BeOfType<UnionAllNode>(); | ||
} | ||
|
||
[Fact] | ||
public void It_should_contain_both_queries() | ||
{ | ||
RootNode.As<UnionAllNode>().First.Should().Contain<FromNode>().Which.Should().HaveAlias(FirstAlias); | ||
RootNode.As<UnionAllNode>().Second.Should().Contain<FromNode>().Which.Should().HaveAlias(SecondAlias); | ||
} | ||
|
||
private AstNode RootNode { get; set; } | ||
private string FirstAlias { get; set; } | ||
private string SecondAlias { get; set; } | ||
private QueryContext<NoParameters, string> QueryContext { get; set; } | ||
} | ||
} | ||
} |
Oops, something went wrong.