Skip to content

Commit

Permalink
General code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
weelink committed Jul 25, 2019
1 parent 17aee45 commit df7a18a
Show file tree
Hide file tree
Showing 59 changed files with 252 additions and 242 deletions.
2 changes: 1 addition & 1 deletion src/FluentSQL.Tests/Api/ExampleParameters.cs
Expand Up @@ -5,4 +5,4 @@ public class ExampleParameters
public int Limit { get; set; }
public string InvoiceNumber { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion src/FluentSQL.Tests/Api/SubqueryResult.cs
Expand Up @@ -4,4 +4,4 @@ public class SubqueryResult
{
public int InvoiceIdFromSubquery { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion src/FluentSQL.Tests/Api/UnionResult.cs
Expand Up @@ -5,4 +5,4 @@ public class UnionResult
public string CustomerName { get; set; }
public int TotalAmount { get; set; }
}
}
}
28 changes: 14 additions & 14 deletions src/FluentSQL.Tests/Builders/RandomStringBuilder.cs
Expand Up @@ -16,6 +16,20 @@ public RandomStringBuilder()
WithMaximumLength(Random.Next(2, 10));
}

public RandomStringBuilder ThatStartsWithLetter
{
get
{
StartsWithLetter = true;
return this;
}
}

private int MinimumLength { get; set; }
private int MaximumLength { get; set; }
private Random Random { get; }
private bool StartsWithLetter { get; set; }

protected override string OnBuild()
{
var stringBuilder = new StringBuilder();
Expand Down Expand Up @@ -52,19 +66,5 @@ public RandomStringBuilder WithMaximumLength(int maximumLength)
MaximumLength = maximumLength;
return this;
}

public RandomStringBuilder ThatStartsWithLetter
{
get
{
StartsWithLetter = true;
return this;
}
}

private int MinimumLength { get; set; }
private int MaximumLength { get; set; }
private Random Random { get; }
private bool StartsWithLetter { get; set; }
}
}
Expand Up @@ -7,6 +7,8 @@ namespace FluentSQL.Tests.Compilation.Builders
{
public class QueryCompilerBuilder : TestDataBuilder<QueryCompiler>
{
private Func<AstNode, string> Compiler { get; set; }

protected override void OnPreBuild()
{
if (Compiler == null)
Expand Down Expand Up @@ -35,23 +37,21 @@ public QueryCompilerBuilder ThatCompiles(Action<AstNode> compiler)
});
}

private Func<AstNode, string> Compiler { get; set; }

private class QueryCompilerStub : QueryCompiler
{
public QueryCompilerStub(QueryCompilerBuilder builder)
{
Builder = builder;
}

private QueryCompilerBuilder Builder { get; }

public override CompilationResult Compile(AstNode node)
{
string sql = Builder.Compiler(node);

return new CompilationResult(sql);
}

private QueryCompilerBuilder Builder { get; }
}
}
}
20 changes: 10 additions & 10 deletions src/FluentSQL.Tests/Compilation/Parser/FromQueryParserTests.cs
Expand Up @@ -35,6 +35,9 @@ protected override void Because(QueryParser sut)
RootNode = sut.Parse(QueryContext);
}

private AstNode RootNode { get; set; }
private QueryContext<NoParameters, string> QueryContext { get; set; }

[Fact]
public void It_should_add_the_from_clause()
{
Expand All @@ -46,9 +49,6 @@ 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>
Expand All @@ -71,22 +71,22 @@ protected override void Because(QueryParser sut)
RootNode = sut.Parse(QueryContext);
}

private AstNode RootNode { get; set; }

private string Alias { get; set; }
private QueryContext<NoParameters, string> QueryContext { get; set; }

[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; }
}
}
}
}
6 changes: 3 additions & 3 deletions src/FluentSQL.Tests/Compilation/Parser/QueryParserTests.cs
Expand Up @@ -26,14 +26,14 @@ protected override void Because(QueryParser sut)
RootNode = sut.Parse(QueryContext);
}

private AstNode RootNode { get; set; }
private QueryContext<NoParameters, string> QueryContext { get; set; }

[Fact]
public void It_should_create_an_empty_node()
{
RootNode.Should().BeEmpty();
}

private AstNode RootNode { get; set; }
private QueryContext<NoParameters, string> QueryContext { get; set; }
}
}
}
24 changes: 12 additions & 12 deletions src/FluentSQL.Tests/Compilation/Parser/UnionAllQueryParserTests.cs
Expand Up @@ -29,7 +29,7 @@ protected override QueryParser EstablishContext()
.From(() => model.Customers).As(FirstAlias)
.Select(() => model.Customers.Name);

QueryComponent<NoParameters, string> second =
QueryComponent<NoParameters, string> second =
model.Query<string>()
.From(() => model.Invoices).As(SecondAlias)
.Select(() => model.Invoices.InvoiceNumber);
Expand All @@ -43,24 +43,24 @@ protected override void Because(QueryParser sut)
{
RootNode = sut.Parse(QueryContext);
}

[Fact]
public void It_should_return_an_union_node()
{
RootNode.Should().BeOfType<UnionAllNode>();
}


private AstNode RootNode { get; set; }
private string FirstAlias { get; set; }
private string SecondAlias { get; set; }
private QueryContext<NoParameters, string> QueryContext { get; set; }

[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; }
[Fact]
public void It_should_return_an_union_node()
{
RootNode.Should().BeOfType<UnionAllNode>();
}
}
}
}
26 changes: 13 additions & 13 deletions src/FluentSQL.Tests/Compilation/Parser/UnionQueryParserTests.cs
Expand Up @@ -29,7 +29,7 @@ protected override QueryParser EstablishContext()
.From(() => model.Customers).As(FirstAlias)
.Select(() => model.Customers.Name);

QueryComponent<NoParameters, string> second =
QueryComponent<NoParameters, string> second =
model.Query<string>()
.From(() => model.Invoices).As(SecondAlias)
.Select(() => model.Invoices.InvoiceNumber);
Expand All @@ -43,24 +43,24 @@ protected override void Because(QueryParser sut)
{
RootNode = sut.Parse(QueryContext);
}

[Fact]
public void It_should_return_an_union_node()
{
RootNode.Should().BeOfType<UnionNode>();
}


private AstNode RootNode { get; set; }
private string FirstAlias { get; set; }
private string SecondAlias { get; set; }
private QueryContext<NoParameters, string> QueryContext { get; set; }

[Fact]
public void It_should_contain_both_queries()
{
RootNode.As<UnionNode>().First.Should().Contain<FromNode>().Which.Should().HaveAlias(FirstAlias);
RootNode.As<UnionNode>().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; }
[Fact]
public void It_should_return_an_union_node()
{
RootNode.Should().BeOfType<UnionNode>();
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/FluentSQL.Tests/Databases/Builders/DatabaseBuilder.cs
Expand Up @@ -6,6 +6,8 @@ namespace FluentSQL.Tests.Databases.Builders
{
public class DatabaseBuilder : TestDataBuilder<Database>
{
private QueryCompiler QueryCompiler { get; set; }

protected override void OnPreBuild()
{
if (QueryCompiler == null)
Expand All @@ -25,8 +27,6 @@ public DatabaseBuilder Using(QueryCompiler queryCompiler)
return this;
}

private QueryCompiler QueryCompiler { get; set; }

private class DatabaseStub : Database
{
public DatabaseStub(DatabaseBuilder builder)
Expand Down
4 changes: 2 additions & 2 deletions src/FluentSQL.Tests/Examples/Builders/ExampleModelBuilder.cs
Expand Up @@ -5,6 +5,8 @@ namespace FluentSQL.Tests.Examples.Builders
{
public class ExampleModelBuilder : TestDataBuilder<ExampleModel>
{
private Database Database { get; set; }

protected override void OnPreBuild()
{
if (Database == null)
Expand All @@ -23,7 +25,5 @@ public ExampleModelBuilder WithDatabase(Database database)
Database = database;
return this;
}

private Database Database { get; set; }
}
}
6 changes: 3 additions & 3 deletions src/FluentSQL.Tests/Examples/Customers.cs
Expand Up @@ -4,12 +4,12 @@ namespace FluentSQL.Tests.Examples
{
public class Customers : Table
{
public readonly Column<int> Id = new Column<int>("id");
public readonly Column<string> Name = new Column<string>("name");

public Customers()
: base("dbo", "customers")
{
}

public readonly Column<int> Id = new Column<int>("id");
public readonly Column<string> Name = new Column<string>("name");
}
}
9 changes: 5 additions & 4 deletions src/FluentSQL.Tests/Examples/ExampleModel.cs
Expand Up @@ -5,13 +5,14 @@ namespace FluentSQL.Tests.Examples
{
public class ExampleModel : PersistenceModel
{
public readonly Customers Customers = new Customers();
public readonly InvoiceLines InvoiceLines = new InvoiceLines();

public readonly Invoices Invoices = new Invoices();

public ExampleModel(Database database)
: base(database)
{
}

public readonly Invoices Invoices = new Invoices();
public readonly InvoiceLines InvoiceLines = new InvoiceLines();
public readonly Customers Customers = new Customers();
}
}
8 changes: 4 additions & 4 deletions src/FluentSQL.Tests/Examples/InvoiceLines.cs
Expand Up @@ -6,13 +6,13 @@ namespace FluentSQL.Tests.Examples
{
public class InvoiceLines : Table
{
public readonly Column<Guid> Id = new Column<Guid>("id");
public readonly Column<int> InvoiceId = new Column<int>("invoice_id");
public readonly Column<decimal> Price = new Column<decimal>("price");

public InvoiceLines()
: base("dbo", "invoice_lines")
{
}

public readonly Column<Guid> Id = new Column<Guid>("id");
public readonly Column<decimal> Price = new Column<decimal>("price");
public readonly Column<int> InvoiceId = new Column<int>("invoice_id");
}
}
11 changes: 6 additions & 5 deletions src/FluentSQL.Tests/Examples/Invoices.cs
Expand Up @@ -6,14 +6,15 @@ namespace FluentSQL.Tests.Examples
{
public class Invoices : Table
{
public readonly Column<int> CustomerId = new Column<int>("customer_id");

public readonly Column<int> Id = new Column<int>("id");
public readonly Column<DateTimeOffset> InvoiceDate = new Column<DateTimeOffset>("invoice_date");
public readonly Column<string> InvoiceNumber = new Column<string>("invoice_number");

public Invoices()
: base("dbo", "invoices")
{
}

public readonly Column<int> Id = new Column<int>("id");
public readonly Column<string> InvoiceNumber = new Column<string>("invoice_number");
public readonly Column<DateTimeOffset> InvoiceDate = new Column<DateTimeOffset>("invoice_date");
public readonly Column<int> CustomerId = new Column<int>("customer_id");
}
}
5 changes: 3 additions & 2 deletions src/FluentSQL.Tests/Querying/QueryComponentTests.cs
@@ -1,4 +1,5 @@
using FluentAssertions;

using FluentSQL.Querying;
using FluentSQL.Querying.Extensions;
using FluentSQL.Querying.Statements.Extensions;
Expand Down Expand Up @@ -29,13 +30,13 @@ protected override void Because(QueryComponent<NoParameters, string> sut)
Query = sut.Compile();
}

private Query<string> Query { get; set; }

[Fact]
public void It_should_create_the_query()
{
Query.Should().NotBeNull();
}

private Query<string> Query { get; set; }
}
}
}

0 comments on commit df7a18a

Please sign in to comment.