Skip to content

Commit 338e017

Browse files
committed
Subatomix.Testing -> 4.0.0-pre.5
1 parent 5f07e72 commit 338e017

14 files changed

+78
-851
lines changed

Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
<PackageVersion Include="Microsoft.PowerShell.SDK" Version="[7.2.24, 7.3.0)" />
2222
<PackageVersion Include="Prequel" Version="1.1.0" />
2323
<PackageVersion Include="Subatomix.Build.Packaging.PowerShellModule" Version="1.1.1" />
24-
<PackageVersion Include="Subatomix.Testing" Version="3.2.0" />
24+
<PackageVersion Include="Subatomix.Testing" Version="4.0.0-pre.5" />
25+
<PackageVersion Include="Subatomix.Testing.SqlServerIntegration" Version="4.0.0-pre.5" />
2526
<PackageVersion Include="System.Management.Automation" Version="[7.2.0, 7.3.0)" />
2627
</ItemGroup>
2728

Lines changed: 16 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,42 @@
11
// Copyright Subatomix Research Inc.
22
// SPDX-License-Identifier: MIT
33

4-
using System.Net;
4+
using Subatomix.Testing.SqlServerIntegration;
55

66
namespace PSql.Deploy.Integration;
77

88
[SetUpFixture]
99
public static class IntegrationTestsSetup
1010
{
11-
private const string
12-
PasswordName = "MSSQL_SA_PASSWORD",
13-
ServerPipe = @"\\.\pipe\sql\query";
14-
15-
private const ushort
16-
ServerPort = 1433;
17-
18-
private static SqlServerContainer? _container;
19-
private static Target? _setupTarget;
20-
private static Target? _testTarget;
11+
private static TemporaryDatabase? _database;
12+
private static Target? _target;
2113

2214
internal static Target Target
23-
=> _testTarget ?? throw new InvalidOperationException("Target not initialized.");
15+
=> _target ?? throw OnSetUpNotExecuted();
2416

2517
[OneTimeSetUp]
26-
public static async Task SetUp()
18+
public static void SetUp()
2719
{
28-
var connectionString = new SqlConnectionStringBuilder { DataSource = "." };
29-
var credential = null as NetworkCredential;
30-
31-
var password = Environment
32-
.GetEnvironmentVariable(PasswordName)
33-
.NullIfEmpty();
34-
35-
if (password is not null)
36-
{
37-
// Scenario A: Environment variable MSSQL_SA_PASSWORD present.
38-
// => Assume that a local SQL Server default instance is running.
39-
// Use the given password to authenticate as SA.
40-
credential = new NetworkCredential("sa", password);
41-
}
42-
else if (IsLocalSqlServerListening())
43-
{
44-
// Scenario B: Process listening on port 1433 or named pipe.
45-
// => Assume that a local SQL Server default instance is running
46-
// and supports integrated authentication. Assume that the
47-
// current user has suffucient privileges to run tests.
48-
connectionString.IntegratedSecurity = true;
49-
}
50-
else
51-
{
52-
// Scenario C: No process listening on port 1433 or named pipe.
53-
// => Start an ephemeral SQL Server container on port 1433 using a
54-
// generated SA password.
55-
_container = new SqlServerContainer(ServerPort);
56-
credential = _container.Credential;
57-
}
58-
59-
connectionString.Encrypt = SqlConnectionEncryptOption.Optional;
60-
connectionString.ApplicationName = "PSql.Deploy.Tests";
20+
TestSqlServer.SetUp();
6121

62-
_setupTarget = new(connectionString.ToString(), credential);
63-
64-
connectionString.InitialCatalog = "PSqlDeployTest";
65-
66-
_testTarget = new(connectionString.ToString(), credential);
67-
68-
await CreateTestDatabaseAsync();
22+
_database = TestSqlServer.CreateTemporaryDatabase("PSqlDeployTest");
23+
_target = new(_database.ConnectionString, TestSqlServer.Credential);
6924
}
7025

7126

72-
private static bool IsLocalSqlServerListening()
73-
{
74-
return TcpPort.IsListening(ServerPort)
75-
|| OperatingSystem.IsWindows() && File.Exists(ServerPipe);
76-
}
77-
7827
[OneTimeTearDown]
79-
public static async Task TearDown()
80-
{
81-
try
82-
{
83-
await RemoveTestDatabaseAsync();
84-
}
85-
finally
86-
{
87-
_container?.Dispose();
88-
_container = null;
89-
}
90-
}
91-
92-
private static async Task CreateTestDatabaseAsync()
28+
public static void TearDown()
9329
{
94-
if (_setupTarget is null)
95-
return;
96-
97-
await using var connection = new SqlTestTargetConnection(_setupTarget);
30+
_database = null;
31+
_target = null;
9832

99-
await connection.OpenAsync(CancellationToken.None);
100-
await connection.RemoveDatabaseAsync("PSqlDeployTest");
101-
await connection.CreateDatabaseAsync("PSqlDeployTest");
33+
TestSqlServer.TearDown();
10234
}
10335

104-
private static async Task RemoveTestDatabaseAsync()
36+
private static Exception OnSetUpNotExecuted()
10537
{
106-
if (_setupTarget is null)
107-
return;
108-
109-
await using var connection = new SqlTestTargetConnection(_setupTarget);
110-
111-
await connection.OpenAsync(CancellationToken.None);
112-
await connection.RemoveDatabaseAsync("PSqlDeployTest");
38+
return new InvalidOperationException(
39+
nameof(IntegrationTestsSetup) + "." + nameof(SetUp) + " has not executed."
40+
);
11341
}
11442
}

PSql.Deploy.Engine.Tests/Integration/Support/ExternalProgram.cs

Lines changed: 0 additions & 103 deletions
This file was deleted.

PSql.Deploy.Engine.Tests/Integration/Support/SecureStringHelpers.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

PSql.Deploy.Engine.Tests/Integration/Support/SqlServerContainer.cs

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)