Skip to content

Commit

Permalink
Version 6.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JonPSmith committed Feb 7, 2024
1 parent 9c023f2 commit d36f8bc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
7 changes: 7 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release notes

## 6.0.2

- Fixed error in FasterPostgreSqlEnsureClean - needed password injected

## 6.0.1

- Microsoft.Data.SqlClient vulnerable update

## 6.0.0

Expand Down
2 changes: 1 addition & 1 deletion Test/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"ConnectionStrings": {
"UnitTestConnection": "Server=(localdb)\\mssqllocaldb;Database=EfCore.TestSupport-Test;Trusted_Connection=True;MultipleActiveResultSets=true",
"PostgreSqlConnection": "host=127.0.0.1;Database=Test-Test;Username=postgres;Password=LetMeIn",
"PostgreSqlConnection": "Host=127.0.0.1;Port=5432;Database=Test-Test;Username=postgres;Password=LetMeIn",
"BookOrderConnection": "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=EfCore.TestSupport-Test_ComparerBooksAndOrders;Integrated Security=True;MultipleActiveResultSets=True"
},
"MyInt": 1,
Expand Down
12 changes: 11 additions & 1 deletion TestSupport/EfHelpers/CleanDatabaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.Configuration;
using Npgsql;
using TestSupport.EfHelpers.Internal;
using TestSupport.Helpers;

namespace TestSupport.EfHelpers
{
Expand All @@ -28,8 +32,14 @@ public static void EnsureClean(this DatabaseFacade databaseFacade, bool setUpSch
databaseFacade.CreateExecutionStrategy()
.Execute(databaseFacade, database => new SqlServerDatabaseCleaner(databaseFacade).Clean(database, setUpSchema));
else if (databaseFacade.IsNpgsql())
{
//PostgreSQL
databaseFacade.FasterPostgreSqlEnsureClean(setUpSchema);

//The databaseFacade doesn't have the Password, so we need to get it from the connection string in the appsettings.json file
var config = AppSettings.GetConfiguration(Assembly.GetCallingAssembly());
var password = new NpgsqlConnectionStringBuilder(config.GetConnectionString(AppSettings.PostgreSqlConnectionString)).Password;
databaseFacade.FasterPostgreSqlEnsureClean(password, setUpSchema);
}
else
throw new InvalidOperationException("The EnsureClean method only works with SQL Server or PostgreSQL databases.");
}
Expand Down
15 changes: 12 additions & 3 deletions TestSupport/EfHelpers/Internal/PostgreSqlDropSchemaEnsureClean.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.EntityFrameworkCore;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Npgsql;
using TestSupport.Helpers;

namespace TestSupport.EfHelpers.Internal
{
Expand All @@ -12,10 +14,16 @@ internal static class PostgreSqlDropSchemaEnsureClean
/// The SQL in this method was provided by Shay Rojansky, github @roji
/// </summary>
/// <param name="databaseFacade"></param>
/// <param name="password"></param>
/// <param name="setUpSchema"></param>
public static void FasterPostgreSqlEnsureClean(this DatabaseFacade databaseFacade, bool setUpSchema = true)
public static void FasterPostgreSqlEnsureClean(this DatabaseFacade databaseFacade, string password, bool setUpSchema = true)
{
var connectionString = databaseFacade.GetDbConnection().ConnectionString;
var builder = new NpgsqlConnectionStringBuilder(databaseFacade.GetDbConnection().ConnectionString)
{
Password = password
};
var connectionString = builder.ToString();

if (connectionString.DatabaseExists())
{
using var conn = new NpgsqlConnection(connectionString);
Expand All @@ -24,6 +32,7 @@ public static void FasterPostgreSqlEnsureClean(this DatabaseFacade databaseFacad
var dropPublicSchemaCommand = new NpgsqlCommand
{
Connection = conn,

CommandText = @"
DO $$
DECLARE
Expand Down
10 changes: 5 additions & 5 deletions TestSupport/TestSupport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@

<PropertyGroup>
<PackageId>EfCore.TestSupport</PackageId>
<PackageVersion>6.0.1</PackageVersion>
<Version>6.0.1</Version>
<AssemblyVersion>6.0.1.0</AssemblyVersion>
<FileVersion>6.0.1.0</FileVersion>
<PackageVersion>6.0.2</PackageVersion>
<Version>6.0.2</Version>
<AssemblyVersion>6.0.2.0</AssemblyVersion>
<FileVersion>6.0.2.0</FileVersion>
<Authors>Jon P Smith</Authors>
<Description>Useful tools when unit testing applications that use Entity Framework Core. See readme file on github.</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>
- Microsoft.Data.SqlClient vulnerable update
- Fixed error in FasterPostgreSqlEnsureClean - needed password injected
</PackageReleaseNotes>
<Copyright>Copyright (c) 2020 Jon P Smith. Licenced under MIT licence</Copyright>
<PackageTags>Entity Framework Core, xUnit</PackageTags>
Expand Down

0 comments on commit d36f8bc

Please sign in to comment.