Skip to content

Commit 79d332d

Browse files
authored
Add new test fixtures for EF6 provider. (#519)
* Add initial test fixture for EF6. * Add fixture models and DbContext. * Fix configuration.
1 parent f01a5d3 commit 79d332d

20 files changed

+281
-14
lines changed

Directory.Packages.props

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<PackageVersion Include="BenchmarkDotNet" Version="0.15.0" />
2929
<PackageVersion Include="MartinCostello.SqlLocalDb" Version="4.0.0" />
3030
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.5" />
31-
<PackageVersion Include="Respawn" Version="6.2.1" />
3231
<PackageVersion Include="Testcontainers.MsSql" Version="4.5.0" />
3332
<PackageVersion Include="Polyfill" Version="7.33.0" />
3433
<PackageVersion Include="FluentAssertions" Version="7.2.0" />
@@ -38,6 +37,14 @@
3837
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
3938
</ItemGroup>
4039

40+
<ItemGroup Label="Test projects dependencies NET FX" Condition=" '$(TargetFramework)' == 'net472' ">
41+
<PackageVersion Include="Respawn" Version="4.0.0" />
42+
</ItemGroup>
43+
44+
<ItemGroup Label="Test projects dependencies NET 9" Condition=" '$(TargetFramework)' == 'net9.0' ">
45+
<PackageVersion Include="Respawn" Version="6.2.1" />
46+
</ItemGroup>
47+
4148
<ItemGroup Label="Sample projects dependencies">
4249
<PackageVersion Include="AutoMapper" Version="14.0.0" />
4350
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.5" />

tests/Ardalis.Specification.EntityFramework6.Tests/Ardalis.Specification.EntityFramework6.Tests.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="MartinCostello.SqlLocalDb"/>
11-
<PackageReference Include="EntityFramework"/>
12-
<PackageReference Include="System.Data.DataSetExtensions"/>
13-
<PackageReference Include="Testcontainers.MsSql"/>
14-
<PackageReference Include="Microsoft.CSharp"/>
10+
<PackageReference Include="MartinCostello.SqlLocalDb" />
11+
<PackageReference Include="EntityFramework" />
12+
<PackageReference Include="Respawn" />
13+
<PackageReference Include="System.Data.DataSetExtensions" />
14+
<PackageReference Include="Testcontainers.MsSql" />
15+
<PackageReference Include="Microsoft.CSharp" />
1516
<PackageReference Include="Polyfill">
1617
<PrivateAssets>all</PrivateAssets>
1718
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.ComponentModel.DataAnnotations.Schema;
2+
3+
namespace Tests.FixtureNew;
4+
5+
public record Address
6+
{
7+
public int Id { get; set; }
8+
public string? Street { get; set; }
9+
10+
public Store Store { get; set; } = default!;
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.ComponentModel.DataAnnotations.Schema;
2+
3+
namespace Tests.FixtureNew;
4+
5+
public record Company
6+
{
7+
public int Id { get; set; }
8+
public required string Name { get; set; }
9+
10+
public int CountryId { get; set; }
11+
public Country Country { get; set; } = default!;
12+
13+
public List<Store> Stores { get; set; } = [];
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Tests.FixtureNew;
2+
3+
public record Country
4+
{
5+
public int Id { get; set; }
6+
public int No { get; set; }
7+
public string? Name { get; set; }
8+
public bool IsDeleted { get; set; }
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Tests.FixtureNew;
2+
3+
public record Product
4+
{
5+
public int Id { get; set; }
6+
public string? Name { get; set; }
7+
8+
public int StoreId { get; set; }
9+
public Store Store { get; set; } = default!;
10+
11+
public List<ProductImage>? Images { get; set; }
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Tests.FixtureNew;
2+
3+
public record ProductImage
4+
{
5+
public int Id { get; set; }
6+
public string? ImageUrl { get; set; }
7+
public int ProductId { get; set; }
8+
public Product Product { get; set; } = default!;
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Tests.FixtureNew;
2+
3+
public record Store
4+
{
5+
public int Id { get; set; }
6+
public string? Name { get; set; }
7+
public string? City { get; set; }
8+
9+
public int CompanyId { get; set; }
10+
public Company Company { get; set; } = default!;
11+
12+
public Address Address { get; set; } = default!;
13+
14+
public List<Product> Products { get; set; } = [];
15+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.Collections;
2+
3+
namespace Tests.FixtureNew;
4+
5+
public class IntegrationTest : IAsyncLifetime
6+
{
7+
protected TestDbContext DbContext { get; private set; } = default!;
8+
private readonly TestFactory _testFactory;
9+
10+
public IntegrationTest(TestFactory testFactory)
11+
{
12+
_testFactory = testFactory;
13+
}
14+
15+
public Task InitializeAsync()
16+
{
17+
DbContext = new TestDbContext(_testFactory.ConnectionString);
18+
return Task.CompletedTask;
19+
}
20+
21+
public async Task DisposeAsync()
22+
{
23+
DbContext.Dispose();
24+
await _testFactory.ResetDatabase();
25+
}
26+
27+
public async Task SeedAsync<TEntity>(TEntity entity) where TEntity : class
28+
{
29+
using var dbContext = new TestDbContext(_testFactory.ConnectionString);
30+
dbContext.Set<TEntity>().Add(entity);
31+
await dbContext.SaveChangesAsync();
32+
}
33+
34+
public async Task SeedRangeAsync<TEntity>(TEntity[] entities) where TEntity : class
35+
{
36+
using var dbContext = new TestDbContext(_testFactory.ConnectionString);
37+
dbContext.Set<TEntity>().AddRange(entities);
38+
await dbContext.SaveChangesAsync();
39+
}
40+
41+
public async Task SeedRangeAsync(IEnumerable entities)
42+
{
43+
using var dbContext = new TestDbContext(_testFactory.ConnectionString);
44+
foreach (var entity in entities)
45+
{
46+
dbContext.Set(entity.GetType()).Add(entity);
47+
}
48+
await dbContext.SaveChangesAsync();
49+
}
50+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Tests.FixtureNew;
2+
3+
public class Repository<T>(TestDbContext context) : RepositoryBase<T>(context) where T : class
4+
{
5+
}

0 commit comments

Comments
 (0)