Skip to content

Commit a3b031b

Browse files
committed
Added test multiple schema PostgreSQL
1 parent b666fc8 commit a3b031b

File tree

8 files changed

+91
-88
lines changed

8 files changed

+91
-88
lines changed

DataLayer/LargeDatabase/LargeDbContext.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using System.Collections.Generic;
33
using System.Text;
44

5-
namespace DataLayer.LargeDatabase
5+
namespace DataLayer.MutipleSchema
66
{
7-
public class SharedEntity
7+
public class Class1
88
{
99
public int Id { get; set; }
1010

DataLayer/MutipleSchema/Class2.cs

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.MutipleSchema
6+
{
7+
public class Class2
8+
{
9+
public int Id { get; set; }
10+
11+
public string Name { get; set; }
12+
}
13+
}

DataLayer/MutipleSchema/Class3.cs

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.MutipleSchema
6+
{
7+
public class Class3
8+
{
9+
public int Id { get; set; }
10+
11+
public string Name { get; set; }
12+
}
13+
}

DataLayer/MutipleSchema/Class4.cs

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.MutipleSchema
6+
{
7+
public class Class4
8+
{
9+
public int Id { get; set; }
10+
11+
public string Name { get; set; }
12+
}
13+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+

2+
using Microsoft.EntityFrameworkCore;
3+
4+
namespace DataLayer.MutipleSchema
5+
{
6+
public class ManySchemaDbContext : DbContext
7+
{
8+
public ManySchemaDbContext(DbContextOptions<ManySchemaDbContext> options)
9+
: base(options) { }
10+
11+
public DbSet<Class1> Class1s { get; set; }
12+
public DbSet<Class2> Class2s { get; set; }
13+
public DbSet<Class3> Class3s { get; set; }
14+
public DbSet<Class4> Class4s { get; set; }
15+
16+
protected override void OnModelCreating(ModelBuilder modelBuilder)
17+
{
18+
modelBuilder.Entity<Class2>().ToTable("Class2s", schema: "Schema2");
19+
modelBuilder.Entity<Class3>().ToTable("Class3s", schema: "Schema3");
20+
modelBuilder.Entity<Class4>().ToTable("Class4s", schema: "Schema4");
21+
}
22+
23+
}
24+
}

Test/UnitTests/TestDataLayer/TestEnsureCleanPostgreSql.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using DataLayer.BookApp.EfCode;
88
using DataLayer.Database1;
99
using DataLayer.Database2;
10+
using DataLayer.MutipleSchema;
1011
using Microsoft.EntityFrameworkCore;
1112
using Npgsql;
1213
using Test.Helpers;
@@ -167,6 +168,31 @@ public void TestDatabase1SchemaChangeToDatabase2Ok()
167168
}
168169
}
169170

171+
[Fact]
172+
public void TestMutipleSchemaCleared()
173+
{
174+
//SETUP
175+
var options = this.CreatePostgreSqlUniqueMethodOptions<ManySchemaDbContext>();
176+
using var context = new ManySchemaDbContext(options);
177+
context.Database.EnsureCreated();
178+
context.AddRange(new Class1(), new Class2(), new Class3(), new Class4());
179+
context.SaveChanges();
180+
181+
//ATTEMPT
182+
context.Database.EnsureClean();
183+
184+
//VERIFY
185+
context.ChangeTracker.Clear();
186+
187+
context.Class1s.Any().ShouldBeFalse();
188+
context.Class2s.Any().ShouldBeFalse();
189+
context.Class3s.Any().ShouldBeFalse();
190+
context.Class4s.Any().ShouldBeFalse();
191+
192+
context.AddRange(new Class1(), new Class2(), new Class3(), new Class4());
193+
context.SaveChanges();
194+
}
195+
170196
[Fact]
171197
public void TestEnsureCleanNotSetSchema()
172198
{

Test/UnitTests/TestDataLayer/TestPostgreSqlLargeDatabasePerformance.cs

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

0 commit comments

Comments
 (0)