-
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.
refactor tests around supported query annotations
- Loading branch information
1 parent
6b8d862
commit c3142a8
Showing
34 changed files
with
637 additions
and
723 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
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
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
File renamed without changes.
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,59 @@ | ||
using dotenv.net; | ||
using Microsoft.Data.Sqlite; | ||
using System; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace SqlcGenCsharpTests | ||
{ | ||
public static class EndToEndCommon | ||
{ | ||
private const string EnvFile = ".env"; | ||
private const string SchemaFile = "sqlite.schema.sql"; | ||
|
||
public const string PostgresConnectionStringEnv = "POSTGRES_CONNECTION_STRING"; | ||
public const string MySqlConnectionStringEnv = "MYSQL_CONNECTION_STRING"; | ||
public const string SqliteConnectionStringEnv = "SQLITE_CONNECTION_STRING"; | ||
|
||
public static void SetUp() | ||
{ | ||
if (File.Exists(EnvFile)) | ||
DotEnv.Load(options: new DotEnvOptions(envFilePaths: new[] { EnvFile })); | ||
RemoveExistingSqliteDb(); | ||
if (File.Exists(SchemaFile)) | ||
InitSqliteDb(); | ||
} | ||
|
||
public static void TearDown() | ||
{ | ||
RemoveExistingSqliteDb(); | ||
} | ||
|
||
private static void RemoveExistingSqliteDb() | ||
{ | ||
var connectionString = Environment.GetEnvironmentVariable(SqliteConnectionStringEnv); | ||
if (connectionString == null) return; | ||
|
||
var dbFilename = SqliteFilenameRegex.Match(connectionString).Groups[1].Value; | ||
Console.WriteLine($"Removing sqlite db from {dbFilename}"); | ||
if (File.Exists(dbFilename)) | ||
File.Delete(dbFilename); | ||
} | ||
private static void InitSqliteDb() | ||
{ | ||
var schemaSql = File.ReadAllText(SchemaFile); | ||
var connectionString = Environment.GetEnvironmentVariable(EndToEndCommon.SqliteConnectionStringEnv); | ||
using (var connection = new SqliteConnection(connectionString)) | ||
{ | ||
connection.Open(); | ||
using (var command = connection.CreateCommand()) | ||
{ | ||
command.CommandText = schemaSql; | ||
command.ExecuteNonQuery(); | ||
} | ||
} | ||
} | ||
|
||
private static readonly Regex SqliteFilenameRegex = new Regex(@"Data Source=([\w\.\/\-]+\.db);", RegexOptions.Compiled); | ||
} | ||
} |
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,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>.netstandard2.0</TargetFramework> | ||
<RootNamespace>SqlcGenCsharpTests</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="../.env"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="../examples/config/sqlite/schema.sql"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
<TargetPath>sqlite.schema.sql</TargetPath> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="dotenv.net" Version="3.2.1" /> | ||
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.0"/> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0"/> | ||
</ItemGroup> | ||
|
||
</Project> |
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,29 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace SqlcGenCsharpTests | ||
{ | ||
public interface IOneTester | ||
{ | ||
Task TestOne(); | ||
} | ||
|
||
public interface IManyTester | ||
{ | ||
Task TestMany(); | ||
} | ||
|
||
public interface IExecTester | ||
{ | ||
Task TestExec(); | ||
} | ||
|
||
public interface IExecRowsTester | ||
{ | ||
Task TestExecRows(); | ||
} | ||
|
||
public interface ICopyFromTester | ||
{ | ||
Task TestCopyFrom(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,57 +1,20 @@ | ||
using dotenv.net; | ||
using Microsoft.Data.Sqlite; | ||
using NUnit.Framework; | ||
using System; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace SqlcGenCsharpTests; | ||
|
||
[SetUpFixture] | ||
public partial class GlobalSetup | ||
namespace SqlcGenCsharpTests | ||
{ | ||
private const string EnvFile = ".env"; | ||
private const string SchemaFile = "sqlite.schema.sql"; | ||
|
||
public const string PostgresConnectionStringEnv = "POSTGRES_CONNECTION_STRING"; | ||
public const string MySqlConnectionStringEnv = "MYSQL_CONNECTION_STRING"; | ||
public const string SqliteConnectionStringEnv = "SQLITE_CONNECTION_STRING"; | ||
|
||
[OneTimeSetUp] | ||
public void LoadEnvFile() | ||
[SetUpFixture] | ||
public class GlobalSetup | ||
{ | ||
if (File.Exists(EnvFile)) | ||
DotEnv.Load(options: new DotEnvOptions(envFilePaths: [EnvFile])); | ||
RemoveExistingDb(); | ||
if (File.Exists(SchemaFile)) | ||
InitSqliteDb(); | ||
[OneTimeSetUp] | ||
public void SetUp() | ||
{ | ||
EndToEndCommon.SetUp(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
public void TearDown() | ||
{ | ||
EndToEndCommon.TearDown(); | ||
} | ||
} | ||
|
||
private static void RemoveExistingDb() | ||
{ | ||
var connectionString = Environment.GetEnvironmentVariable(SqliteConnectionStringEnv)!; | ||
var dbFilename = SqliteFilenameRegex().Match(connectionString).Groups[1].Value; | ||
if (File.Exists(dbFilename)) | ||
File.Delete(dbFilename); | ||
} | ||
private static void InitSqliteDb() | ||
{ | ||
var schemaSql = File.ReadAllText(SchemaFile); | ||
var connectionString = Environment.GetEnvironmentVariable(GlobalSetup.SqliteConnectionStringEnv); | ||
using var connection = new SqliteConnection(connectionString); | ||
connection.Open(); | ||
|
||
using var command = connection.CreateCommand(); | ||
command.CommandText = schemaSql; | ||
command.ExecuteNonQuery(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
public void TearDown() | ||
{ | ||
RemoveExistingDb(); | ||
} | ||
|
||
[GeneratedRegex("Data Source=((/|\\w)+.db);")] | ||
private static partial Regex SqliteFilenameRegex(); | ||
} |
Oops, something went wrong.