-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgraded packages and introduced Testcontainers for the integration t…
…ests. (#64) * Updated packages. * Added .vs folder to .gitignore * Introduced Testcontainers to execute the integration tests.
- Loading branch information
Showing
25 changed files
with
546 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ _ReSharper*/ | |
.DS_Store | ||
|
||
packages/ | ||
|
||
.vs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...re.Migrations.MySql.Tests/AppAny.Quartz.EntityFrameworkCore.Migrations.MySql.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> | ||
<PackageReference Include="MySql.Data" Version="8.3.0" /> | ||
<PackageReference Include="Quartz" Version="3.8.1" /> | ||
<PackageReference Include="Quartz.Serialization.Json" Version="3.8.1" /> | ||
<PackageReference Include="Testcontainers" Version="3.7.0" /> | ||
<PackageReference Include="Testcontainers.MySql" Version="3.7.0" /> | ||
<PackageReference Include="xunit" Version="2.7.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0'" Label="Packages"> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.16"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'" Label="Packages"> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\AppAny.Quartz.EntityFrameworkCore.Migrations.MySql\AppAny.Quartz.EntityFrameworkCore.Migrations.MySql.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |
38 changes: 38 additions & 0 deletions
38
tests/AppAny.Quartz.EntityFrameworkCore.Migrations.MySql.Tests/DatabaseFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace AppAny.Quartz.EntityFrameworkCore.Migrations.MySql.Tests | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Testcontainers.MySql; | ||
|
||
public class DatabaseFixture : IAsyncLifetime | ||
{ | ||
private readonly MySqlContainer container; | ||
|
||
public DatabaseFixture() | ||
{ | ||
int port = Random.Shared.Next(3400, 3499); | ||
|
||
this.container ??= new MySqlBuilder() | ||
.WithPortBinding(port, MySqlBuilder.MySqlPort) | ||
.Build(); | ||
} | ||
|
||
public string ConnectionString => this.container.GetConnectionString(); | ||
|
||
public string ContainerId => $"{this.container.Id}"; | ||
|
||
public static string Database => MySqlBuilder.DefaultDatabase; | ||
|
||
/// <inheritdoc /> | ||
public Task InitializeAsync() | ||
{ | ||
return this.container.StartAsync(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public Task DisposeAsync() | ||
{ | ||
return this.container.DisposeAsync().AsTask(); | ||
} | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
....Tests/MySQL/MySqlIntegrationDbContext.cs → ....MySql.Tests/MySqlIntegrationDbContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...z.EntityFrameworkCore.Migrations.MySql.Tests/MySqlIntegrationDbContextIntegrationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace AppAny.Quartz.EntityFrameworkCore.Migrations.MySql.Tests | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using global::Quartz; | ||
using Microsoft.EntityFrameworkCore; | ||
using Xunit; | ||
|
||
public class MySqlIntegrationDbContextIntegrationTests : IClassFixture<DatabaseFixture>, IDisposable | ||
{ | ||
private readonly MySqlIntegrationDbContext _dbContext; | ||
private readonly string _connectionString; | ||
|
||
public MySqlIntegrationDbContextIntegrationTests(DatabaseFixture fixture) | ||
{ | ||
this._connectionString = fixture.ConnectionString; | ||
|
||
var options = new DbContextOptionsBuilder<MySqlIntegrationDbContext>() | ||
.UseMySql( | ||
this._connectionString, | ||
ServerVersion.AutoDetect(fixture.ConnectionString)) | ||
.Options; | ||
|
||
this._dbContext = new MySqlIntegrationDbContext(options); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldBuildScheduler() | ||
{ | ||
// Arrange | ||
await this._dbContext.Database.EnsureCreatedAsync(); | ||
await this._dbContext.Database.MigrateAsync(); | ||
|
||
// Act | ||
var scheduler = await SchedulerBuilder.Create() | ||
.UseDefaultThreadPool(x => x.MaxConcurrency = 5) | ||
.UsePersistentStore( | ||
x => | ||
{ | ||
x.PerformSchemaValidation = true; | ||
x.UseMySql(this._connectionString); | ||
x.UseNewtonsoftJsonSerializer(); | ||
}) | ||
.BuildScheduler(); | ||
|
||
var exception = await Record.ExceptionAsync(async () => await scheduler.Start()); | ||
|
||
// Assert | ||
Assert.Null(exception); | ||
Assert.True(scheduler.IsStarted); | ||
|
||
await scheduler.Shutdown(); | ||
Assert.True(scheduler.IsShutdown); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
//this._dbContext.Database.EnsureDeleted(); | ||
this._dbContext.Dispose(); | ||
} | ||
} | ||
} |
Oops, something went wrong.