Skip to content

Commit

Permalink
Trying to get AppVeyor to be happy, and using local postgres on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
artiomchi committed Nov 19, 2023
1 parent 60af794 commit 40556c5
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 27 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ jobs:
with:
dotnet-version: '7.0'
- uses: actions/checkout@v3
- name: Enable Postgres
run: sc config postgresql-x64-14 start= demand
- name: Start Postgres
run: net start postgresql-x64-14
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
run: dotnet build --no-restore /p:POSTGRES_ONLY=true
- name: Test
env:
USE_LOCAL_SERVICE: 'true'
run: dotnet test --no-build --logger "trx;LogFileName=test-results.trx"
- name: Test Report
uses: dorny/test-reporter@v1
Expand Down
5 changes: 5 additions & 0 deletions appveyor.signed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ image: Visual Studio 2022
configuration: Release
skip_tags: true

services:
- mssql2019
- mysql
- postgresql15

environment:
skey_secret:
secure: tZ1CLa1H+KzjeZAks/d3fkM3mp7ymDd0hnSmmKa+qe19K1kW2Tt+hMt38tNFMpJIYaOBSAcQ7bwvvqFQwVFNXA==
Expand Down
5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ image: Visual Studio 2022
configuration: Debug
skip_tags: true

services:
- mssql2019
- mysql
- postgresql15

before_build:
- ps: dotnet --info
- ps: dotnet restore -v Minimal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public static class BuildEnvironment
{
public static bool IsAppVeyor => Environment.GetEnvironmentVariable("APPVEYOR") != null;
public static bool IsGitHub => Environment.GetEnvironmentVariable("GITHUB_ACTIONS") != null;
public static bool UseLocalService => IsAppVeyor || Environment.GetEnvironmentVariable("USE_LOCAL_SERVICE") != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ namespace FlexLabs.EntityFrameworkCore.Upsert.IntegrationTests
public abstract class DatabaseInitializerFixture : IAsyncLifetime
{
public IContainer TestContainer { get; }
public DbDriver DbDriver { get; }
public DbContextOptions<TestDbContext> DataContextOptions { get; private set; }

public DatabaseInitializerFixture(DbDriver dbDriver)
public DatabaseInitializerFixture()
{
DbDriver = dbDriver;
if (!BuildEnvironment.UseLocalService)
{
TestContainer = BuildContainer();
}
}

public DatabaseInitializerFixture(DbDriver dbDriver, IContainer testContainer)
: this(dbDriver)
{
TestContainer = testContainer;
}
public abstract DbDriver DbDriver { get; }
protected virtual IContainer BuildContainer() => null;

protected abstract void ConfigureContextOptions(DbContextOptionsBuilder<TestDbContext> builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ public class DbTests_InMemory : DbTestsBase, IClassFixture<DbTests_InMemory.Data
{
public sealed class DatabaseInitializer : DatabaseInitializerFixture
{
public DatabaseInitializer()
: base(DbDriver.InMemory)
{ }
public override DbDriver DbDriver => DbDriver.InMemory;

protected override void ConfigureContextOptions(DbContextOptionsBuilder<TestDbContext> builder)
=> builder.UseInMemoryDatabase("Upsert_TestDbContext_Tests");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ public class DbTests_MySql : DbTestsBase, IClassFixture<DbTests_MySql.DatabaseIn
{
public sealed class DatabaseInitializer : DatabaseInitializerFixture
{
public DatabaseInitializer()
: base(DbDriver.MySQL, new MySqlBuilder().Build())
{ }
public override DbDriver DbDriver => DbDriver.MySQL;

protected override IContainer BuildContainer()
=> new MySqlBuilder().Build();

protected override void ConfigureContextOptions(DbContextOptionsBuilder<TestDbContext> builder)
{
var connectionString = (TestContainer as IDatabaseContainer).GetConnectionString();
var connectionString = (TestContainer as IDatabaseContainer)?.GetConnectionString()
?? (BuildEnvironment.IsAppVeyor ? "Server=localhost;Port=3306;Database=testuser;Uid=root;Pwd=Password12!" : null);
builder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ public class DbTests_Postgres : DbTestsBase, IClassFixture<DbTests_Postgres.Data
{
public sealed class DatabaseInitializer : DatabaseInitializerFixture
{
public DatabaseInitializer()
: base(DbDriver.Postgres, new PostgreSqlBuilder().Build())
{ }
public override DbDriver DbDriver => DbDriver.Postgres;

protected override IContainer BuildContainer()
=> new PostgreSqlBuilder().Build();

protected override void ConfigureContextOptions(DbContextOptionsBuilder<TestDbContext> builder)
{
var connectionString = (TestContainer as IDatabaseContainer).GetConnectionString();
var connectionString = (TestContainer as IDatabaseContainer)?.GetConnectionString()
?? (BuildEnvironment.IsAppVeyor ? "Server=localhost;Port=5432;Database=testuser;Username=postgres;Password=Password12!" : null)
?? (BuildEnvironment.IsGitHub ? "Server=localhost;Port=5432;Database=testuser;Username=postgres;Password=root" : null);
builder.UseNpgsql(connectionString);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ public class DbTests_SqlServer : DbTestsBase, IClassFixture<DbTests_SqlServer.Da
{
public sealed class DatabaseInitializer : DatabaseInitializerFixture
{
public DatabaseInitializer()
: base(DbDriver.MSSQL, new MsSqlBuilder().Build())
{ }
public override DbDriver DbDriver => DbDriver.MSSQL;

protected override IContainer BuildContainer()
=> new MsSqlBuilder().Build();

protected override void ConfigureContextOptions(DbContextOptionsBuilder<TestDbContext> builder)
{
var connectionString = (TestContainer as IDatabaseContainer).GetConnectionString();
var connectionString = (TestContainer as IDatabaseContainer)?.GetConnectionString()
?? (BuildEnvironment.IsAppVeyor ? "Server=(local)\\SQL2017;Database=testuser;User Id=sa;Password=Password12!;Trust Server Certificate=true" : null)
?? (BuildEnvironment.IsGitHub ? "Server=(localdb)\\MSSqlLocalDB;Integrated Security=SSPI;Initial Catalog=FlexLabsUpsertTests;" : null);
builder.UseSqlServer(connectionString);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ public class DbTests_Sqlite : DbTestsBase, IClassFixture<DbTests_Sqlite.Database
{
public sealed class DatabaseInitializer : DatabaseInitializerFixture
{
public DatabaseInitializer()
: base(DbDriver.Sqlite)
{ }
public override DbDriver DbDriver => DbDriver.Sqlite;

protected override void ConfigureContextOptions(DbContextOptionsBuilder<TestDbContext> builder)
=> builder.UseSqlite("Data Source=testdb.db");
Expand Down

0 comments on commit 40556c5

Please sign in to comment.