Skip to content

Commit 5f8131a

Browse files
committed
Added more tests for PostgreSQL
1 parent 5224297 commit 5f8131a

File tree

7 files changed

+130
-13
lines changed

7 files changed

+130
-13
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace DataLayer.LargeDatabase
4+
{
5+
public class LargeDbContext : DbContext
6+
{
7+
public LargeDbContext(DbContextOptions<LargeDbContext> options)
8+
: base(options) { }
9+
10+
public DbSet<SharedEntity> Table001 => Set<SharedEntity>("Table1");
11+
12+
protected override void OnModelCreating(ModelBuilder modelBuilder)
13+
{
14+
for(int i = 0; i < 100; i++)
15+
modelBuilder.SharedTypeEntity<SharedEntity>($"Table{i:D3}");
16+
}
17+
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace DataLayer.LargeDatabase
6+
{
7+
public class SharedEntity
8+
{
9+
public int Id { get; set; }
10+
11+
public string Name { get; set; }
12+
}
13+
}

ReleaseNotes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Release notes
22

3+
## 5.1.0-preview002
4+
5+
- Updated to support both EF Core 5 and EF Core 6-rc.2 preview
6+
- Added PostgreSQL database helpers, including EnsureClean
7+
- Added the Seed Database feature back in at request of users
8+
- Removed obsolete methods: ...OptionsWithLogging (use ...OptionsWithLogTo), CreateEmptyViaWipe (use EncureClean)
9+
310
## 5.1.0-preview001
411

512
- Updated to support Net5 and Net6-rc.2 preview

Test/UnitTests/TestDataLayer/TestPostgreSqlHelpers.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,23 @@ public void TestEnsureCleanExistingDatabaseOk()
9898
context.Books.Count().ShouldEqual(4);
9999
}
100100

101-
102101
[Fact]
103102
public void TestEnsureCleanNoExistingDatabaseOk()
104103
{
105104
//SETUP
106105
var options = this.CreatePostgreSqlUniqueDatabaseOptions<BookContext>();
107106
using var context = new BookContext(options);
108107

109-
context.Database.EnsureDeleted();
108+
context.Database.EnsureDeleted();
110109

110+
//ATTEMPT
111111
using (new TimeThings(_output, "Time to EnsureClean"))
112112
{
113113
context.Database.EnsureClean();
114114
}
115115

116-
//ATTEMPT
117-
context.SeedDatabaseFourBooks();
118-
119116
//VERIFY
120-
context.Books.Count().ShouldEqual(4);
117+
context.Books.Count().ShouldEqual(0);
121118
}
122119

123120
[Fact]
@@ -127,6 +124,7 @@ public async Task TestEnsureCreatedAndEmptyPostgreSqlOk()
127124
var options = this.CreatePostgreSqlUniqueDatabaseOptions<BookContext>();
128125
using (var context = new BookContext(options))
129126
{
127+
context.Database.EnsureDeleted();
130128
context.Database.EnsureCreated();
131129
context.SeedDatabaseFourBooks();
132130
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/
2+
// Licensed under MIT license. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using DataLayer.BookApp.EfCode;
8+
using DataLayer.LargeDatabase;
9+
using Microsoft.EntityFrameworkCore;
10+
using Npgsql;
11+
using Test.Helpers;
12+
using TestSupport.Attributes;
13+
using TestSupport.EfHelpers;
14+
using Xunit;
15+
using Xunit.Abstractions;
16+
using Xunit.Extensions.AssertExtensions;
17+
18+
namespace Test.UnitTests.TestDataLayer
19+
{
20+
public class TestPostgreSqlLargeDatabasePerformance
21+
{
22+
private readonly ITestOutputHelper _output;
23+
24+
public TestPostgreSqlLargeDatabasePerformance(ITestOutputHelper output)
25+
{
26+
_output = output;
27+
}
28+
29+
[Fact]
30+
public void TestLargeDbEnsureDeletedEnsureCreatedOk()
31+
{
32+
//SETUP
33+
var options = this.CreatePostgreSqlUniqueDatabaseOptions<LargeDbContext>();
34+
using var context = new LargeDbContext(options);
35+
36+
context.Database.EnsureCreated();
37+
38+
//ATTEMPT
39+
using (new TimeThings(_output, "LargeDatabase to EnsureDeleted and EnsureCreated"))
40+
{
41+
context.Database.EnsureDeleted();
42+
context.Database.EnsureCreated();
43+
}
44+
45+
//VERIFY
46+
}
47+
48+
49+
[Fact]
50+
public void TestLargeDbEnsureCleanExistingDatabaseOk()
51+
{
52+
//SETUP
53+
var options = this.CreatePostgreSqlUniqueDatabaseOptions<LargeDbContext>();
54+
using var context = new LargeDbContext(options);
55+
56+
context.Database.EnsureCreated();
57+
58+
//ATTEMPT
59+
using (new TimeThings(_output, "LargeDatabase to EnsureClean"))
60+
{
61+
context.Database.EnsureClean();
62+
}
63+
64+
//VERIFY
65+
}
66+
67+
[Fact]
68+
public async Task TestLargeDbEnsureCreatedAndEmptyPostgreSqlOk()
69+
{
70+
//SETUP
71+
var options = this.CreatePostgreSqlUniqueDatabaseOptions<LargeDbContext>();
72+
using var context = new LargeDbContext(options);
73+
74+
context.Database.EnsureCreated();
75+
76+
//ATTEMPT
77+
using (new TimeThings(_output, "LargeDatabase to empty database"))
78+
{
79+
await context.EnsureCreatedAndEmptyPostgreSqlAsync();
80+
}
81+
82+
//VERIFY
83+
}
84+
}
85+
}

TestSupport/EfHelpers/Internal/NpgsqlDatabaseCleaner.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,16 @@
55

66
using System.Collections.Generic;
77
using System.Data.Common;
8-
using System.Diagnostics;
98
using System.Linq;
109
using System.Text;
1110
using Microsoft.EntityFrameworkCore;
12-
using Microsoft.EntityFrameworkCore.Diagnostics.Internal;
1311
using Microsoft.EntityFrameworkCore.Infrastructure;
14-
using Microsoft.EntityFrameworkCore.Internal;
1512
using Microsoft.EntityFrameworkCore.Scaffolding;
1613
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
1714
using Microsoft.EntityFrameworkCore.Storage;
1815
using Microsoft.Extensions.DependencyInjection;
1916
using Microsoft.Extensions.Logging;
2017
using Npgsql;
21-
using Npgsql.EntityFrameworkCore.PostgreSQL.Diagnostics.Internal;
22-
using Npgsql.EntityFrameworkCore.PostgreSQL.Scaffolding.Internal;
2318
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;
2419

2520
namespace TestSupport.EfHelpers.Internal

TestSupport/TestSupport.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
<PropertyGroup>
4545
<PackageId>EfCore.TestSupport</PackageId>
46-
<PackageVersion>5.1.0-preview001</PackageVersion>
46+
<PackageVersion>5.1.0-preview002</PackageVersion>
4747
<Version>5.1.0</Version>
4848
<AssemblyVersion>5.1.0.0</AssemblyVersion>
4949
<FileVersion>5.1.0.0</FileVersion>
@@ -52,7 +52,7 @@
5252
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
5353
<PackageReleaseNotes>
5454
- Updated to support both EF Core 5 and EF Core 6-rc.2 preview
55-
- Added PostgreSQL database helpers
55+
- Added PostgreSQL database helpers, including EnsureClean
5656
- Added the Seed Database feature back in at request of users
5757
- Removed obsolete methods: ...OptionsWithLogging (use ...OptionsWithLogTo), CreateEmptyViaWipe (use EncureClean)
5858
</PackageReleaseNotes>

0 commit comments

Comments
 (0)