-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'custom-compiler' into develop
- Loading branch information
Showing
12 changed files
with
1,096 additions
and
59 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
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,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using FluentAssertions; | ||
using SqlKata.Compilers; | ||
using PetaPoco.Providers; | ||
|
||
namespace PetaPoco.SqlKata.Tests | ||
{ | ||
public class DefaultCompilersTests | ||
{ | ||
[Theory] | ||
[InlineData(CompilerType.MySql, typeof(MySqlCompiler))] | ||
[InlineData(CompilerType.Firebird, typeof(FirebirdCompiler))] | ||
public void Get_Should_Work_For_Known_Types(CompilerType compilerType, Type compiler) | ||
{ | ||
var output = DefaultCompilers.Get(compilerType); | ||
output.Should().BeOfType(compiler); | ||
} | ||
|
||
[Fact] | ||
public void Get_For_Custom_Should_Throw() | ||
{ | ||
Action act = () => DefaultCompilers.Get(CompilerType.Custom); | ||
act.Should().Throw<ArgumentException>(); | ||
} | ||
|
||
public class MyDatabaseProvider : OracleDatabaseProvider | ||
{ } | ||
|
||
[Fact] | ||
public void Adding_And_Removing_Custom_Works() | ||
{ | ||
var provider = new MyDatabaseProvider(); | ||
DefaultCompilers.TryGetCustom(provider.GetType(), out var compiler).Should().BeFalse(); | ||
|
||
DefaultCompilers.RegisterFor<MyDatabaseProvider>(new PercentCompiler()); | ||
|
||
DefaultCompilers.TryGetCustom(provider, out compiler).Should().BeTrue(); | ||
compiler.Should().BeOfType<PercentCompiler>(); | ||
|
||
DefaultCompilers.RegisterFor<MyDatabaseProvider>(null); | ||
DefaultCompilers.TryGetCustom(provider.GetType(), out compiler).Should().BeFalse(); | ||
} | ||
} | ||
} |
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
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,19 @@ | ||
using SqlKata.Compilers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PetaPoco.SqlKata.Tests | ||
{ | ||
public class PercentCompiler : Compiler | ||
{ | ||
public PercentCompiler() | ||
{ | ||
OpeningIdentifier = ClosingIdentifier = "%%"; | ||
} | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.