Skip to content

Commit b878221

Browse files
committed
Switch postgress and mongo tests to Squadron
1 parent b227d6f commit b878221

File tree

4 files changed

+37
-57
lines changed

4 files changed

+37
-57
lines changed
Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,37 @@
11
using System;
2-
using Docker.Testify;
2+
using System.Threading.Tasks;
33
using MongoDB.Bson;
4-
using MongoDB.Driver;
4+
using Squadron;
55
using Xunit;
66

77
namespace WorkflowCore.Tests.MongoDB
88
{
9-
public class MongoDockerSetup : DockerSetup
9+
public class MongoDockerSetup : IAsyncLifetime
1010
{
11+
private readonly MongoResource _mongoResource;
1112
public static string ConnectionString { get; set; }
1213

13-
public override string ImageName => "mongo";
14-
public override int InternalPort => 27017;
15-
16-
public override void PublishConnectionInfo()
14+
public MongoDockerSetup()
1715
{
18-
ConnectionString = $"mongodb://localhost:{ExternalPort}";
16+
_mongoResource = new MongoResource();
1917
}
20-
21-
public override bool TestReady()
18+
19+
public async Task InitializeAsync()
2220
{
23-
try
24-
{
25-
var client = new MongoClient($"mongodb://localhost:{ExternalPort}");
26-
client.ListDatabases();
27-
28-
var command = new BsonDocument { { "setParameter", 1 }, { "notablescan", 1 } };
29-
client.GetDatabase("admin").RunCommand<BsonDocument>(command);
30-
31-
return true;
32-
}
33-
catch
34-
{
35-
return false;
36-
}
21+
await _mongoResource.InitializeAsync();
22+
var command = new BsonDocument { { "setParameter", 1 }, { "notablescan", 1 } };
23+
_mongoResource.Client.GetDatabase("admin").RunCommand<BsonDocument>(command);
24+
ConnectionString = _mongoResource.ConnectionString;
25+
}
3726

27+
public Task DisposeAsync()
28+
{
29+
return _mongoResource.DisposeAsync();
3830
}
3931
}
4032

4133
[CollectionDefinition("Mongo collection")]
4234
public class MongoCollection : ICollectionFixture<MongoDockerSetup>
4335
{
4436
}
45-
4637
}

test/WorkflowCore.Tests.MongoDB/WorkflowCore.Tests.MongoDB.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
2525
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.0" />
2626
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
27-
<PackageReference Include="xunit" Version="2.3.1" />
28-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
27+
<PackageReference Include="Squadron.Mongo" Version="0.17.0" />
28+
<PackageReference Include="xunit" Version="2.4.1" />
29+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
2930
<PackageReference Include="MongoDB.Driver" Version="2.10.0" />
3031
</ItemGroup>
3132

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,36 @@
11
using System;
2-
using System.Collections.Generic;
3-
using Docker.Testify;
4-
using Npgsql;
2+
using System.Threading.Tasks;
3+
using Squadron;
54
using Xunit;
65

76
namespace WorkflowCore.Tests.PostgreSQL
87
{
9-
public class PostgresDockerSetup : DockerSetup
8+
public class PostgresDockerSetup : IAsyncLifetime
109
{
10+
private readonly PostgreSqlResource _postgreSqlResource;
1111
public static string ConnectionString { get; set; }
1212
public static string ScenarioConnectionString { get; set; }
1313

14-
public override string ImageName => "postgres";
15-
public override int InternalPort => 5432;
16-
17-
private const string PostgresHostAuthMethod = "trust";
18-
public override IList<string> EnvironmentVariables => new List<string> {
19-
$"POSTGRES_HOST_AUTH_METHOD={PostgresHostAuthMethod}"
20-
};
21-
public override void PublishConnectionInfo()
14+
public PostgresDockerSetup()
2215
{
23-
ConnectionString = $"Server=127.0.0.1;Port={ExternalPort};Database=workflow;User Id=postgres;";
24-
ScenarioConnectionString = $"Server=127.0.0.1;Port={ExternalPort};Database=workflow-scenarios;User Id=postgres;";
16+
_postgreSqlResource = new PostgreSqlResource();
2517
}
26-
27-
public override bool TestReady()
18+
19+
public async Task InitializeAsync()
2820
{
29-
try
30-
{
31-
var connection = new NpgsqlConnection($"Server=127.0.0.1;Port={ExternalPort};Database=postgres;User Id=postgres;");
32-
connection.Open();
33-
connection.Close();
34-
return true;
35-
}
36-
catch
37-
{
38-
return false;
39-
}
21+
await _postgreSqlResource.InitializeAsync();
22+
ConnectionString = _postgreSqlResource.ConnectionString;
23+
ScenarioConnectionString = _postgreSqlResource.ConnectionString;
24+
}
4025

26+
public Task DisposeAsync()
27+
{
28+
return _postgreSqlResource.DisposeAsync();
4129
}
4230
}
4331

4432
[CollectionDefinition("Postgres collection")]
4533
public class PostgresCollection : ICollectionFixture<PostgresDockerSetup>
4634
{
4735
}
48-
4936
}

test/WorkflowCore.Tests.PostgreSQL/WorkflowCore.Tests.PostgreSQL.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121

2222
<ItemGroup>
2323
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
24-
<PackageReference Include="xunit" Version="2.3.1" />
25-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
24+
<PackageReference Include="xunit" Version="2.4.1" />
25+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
26+
<PackageReference Include="Squadron.PostgreSql" Version="0.17.0" />
2627
</ItemGroup>
2728

2829
</Project>

0 commit comments

Comments
 (0)