Skip to content

Commit c8f7c29

Browse files
authored
Refactor and improve integration test fixtures. (#360)
* Refactored the fixtures for integration tests. * Updated connection string for EF6. * Update connection string. * Update connection string. * Updated connection retry count. * Few updates. * Update sqllocaldb script. * Update script. * Minor improvements.
1 parent 13e71bb commit c8f7c29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+660
-526
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ RUN /bin/bash -c 'ls -la /wait; chmod +x /wait; ls -la /wait'
1010
RUN dotnet tool install dotnet-reportgenerator-globaltool --version 5.1.23 --tool-path /tools
1111

1212
CMD /wait && \
13-
dotnet build ci.slnf --configuration release && \
14-
dotnet test -f net7.0 ci.slnf --configuration release --no-build --no-restore --collect:"xplat code coverage" && \
13+
dotnet build ci.slnf --configuration Release && \
14+
dotnet test -f net7.0 ci.slnf --configuration Release --no-build --no-restore --collect:"xplat code coverage" && \
1515
tools/reportgenerator -reports:Specification*/**/coverage.cobertura.xml -targetdir:/var/temp/TestResults -assemblyfilters:"-*Tests*;"

Specification.EntityFramework6/tests/Ardalis.Specification.EntityFramework6.IntegrationTests/Ardalis.Specification.EntityFramework6.IntegrationTests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
1212
<PackageReference Include="Moq" Version="4.18.4" />
1313
<PackageReference Include="FluentAssertions" Version="6.11.0" />
1414
<PackageReference Include="MartinCostello.SqlLocalDb" Version="3.2.0" />
15+
<PackageReference Include="EntityFramework" Version="6.4.4" />
1516
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
1617
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
1718
<PackageReference Include="xunit" Version="2.5.0" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Xunit;
2+
3+
namespace Ardalis.Specification.EntityFramework6.IntegrationTests.Fixture.Collections;
4+
5+
[CollectionDefinition("ReadCollection")]
6+
public class ReadCollection : ICollectionFixture<DatabaseFixture>
7+
{
8+
public ReadCollection()
9+
{
10+
11+
}
12+
}

Specification.EntityFramework6/tests/Ardalis.Specification.EntityFramework6.IntegrationTests/Fixture/Configurations/AddressConfiguration.cs

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

Specification.EntityFramework6/tests/Ardalis.Specification.EntityFramework6.IntegrationTests/Fixture/Configurations/CompanyConfiguration.cs

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

Specification.EntityFramework6/tests/Ardalis.Specification.EntityFramework6.IntegrationTests/Fixture/Configurations/CountryConfiguration.cs

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

Specification.EntityFramework6/tests/Ardalis.Specification.EntityFramework6.IntegrationTests/Fixture/Configurations/ProductConfiguration.cs

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

Specification.EntityFramework6/tests/Ardalis.Specification.EntityFramework6.IntegrationTests/Fixture/Configurations/StoreConfiguration.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Ardalis.Specification.UnitTests.Fixture.Entities.Seeds;
2+
using MartinCostello.SqlLocalDb;
3+
using System;
4+
5+
namespace Ardalis.Specification.EntityFramework6.IntegrationTests.Fixture;
6+
7+
public class DatabaseFixture : IDisposable
8+
{
9+
public string ConnectionString { get; }
10+
11+
public DatabaseFixture()
12+
{
13+
var databaseName = $"SpecificationTestsDB_{Guid.NewGuid().ToString().Replace('-', '_')}";
14+
15+
using (var localDB = new SqlLocalDbApi())
16+
{
17+
ConnectionString = localDB.IsLocalDBInstalled()
18+
? $"Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog={databaseName};Integrated Security=SSPI;MultipleActiveResultSets=True;Connection Timeout=300"
19+
: $"Data Source=databaseEF;Initial Catalog={databaseName};PersistSecurityInfo=True;User ID=sa;Password=P@ssW0rd!;";
20+
}
21+
22+
Console.WriteLine($"Connection string: {ConnectionString}");
23+
24+
using var dbContext = new TestDbContext(ConnectionString);
25+
dbContext.Database.Delete();
26+
dbContext.Database.Create();
27+
28+
dbContext.Countries.AddRange(CountrySeed.Get());
29+
dbContext.Companies.AddRange(CompanySeed.Get());
30+
dbContext.Stores.AddRange(StoreSeed.Get());
31+
dbContext.Addresses.AddRange(AddressSeed.Get());
32+
dbContext.Products.AddRange(ProductSeed.Get());
33+
34+
dbContext.SaveChanges();
35+
}
36+
37+
public void Dispose()
38+
{
39+
using var dbContext = new TestDbContext(ConnectionString);
40+
dbContext.Database.Delete();
41+
GC.SuppressFinalize(this);
42+
}
43+
}

Specification.EntityFramework6/tests/Ardalis.Specification.EntityFramework6.IntegrationTests/Fixture/DbInitializer.cs

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

0 commit comments

Comments
 (0)