-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cleanup service tests for word alignment
- Loading branch information
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/Serval/test/Serval.WordAlignment.Tests/Services/BuildCleanupServiceTests.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,56 @@ | ||
namespace Serval.WordAlignment.Services; | ||
|
||
[TestFixture] | ||
public class BuildCleanupServiceTests | ||
{ | ||
[Test] | ||
public async Task CleanupAsync() | ||
{ | ||
TestEnvironment env = new(); | ||
Assert.That(env.Builds.Count, Is.EqualTo(2)); | ||
await env.CheckBuildsAsync(); | ||
Assert.That(env.Builds.Count, Is.EqualTo(1)); | ||
Assert.That((await env.Builds.GetAllAsync())[0].Id, Is.EqualTo("build2")); | ||
} | ||
|
||
private class TestEnvironment | ||
{ | ||
public MemoryRepository<Build> Builds { get; } | ||
|
||
public TestEnvironment() | ||
{ | ||
Builds = new MemoryRepository<Build>(); | ||
Builds.Add( | ||
new Build | ||
{ | ||
Id = "build1", | ||
EngineRef = "engine1", | ||
IsInitialized = false, | ||
DateCreated = DateTime.UtcNow.Subtract(TimeSpan.FromHours(10)) | ||
} | ||
); | ||
Builds.Add( | ||
new Build | ||
{ | ||
Id = "build2", | ||
EngineRef = "engine2", | ||
IsInitialized = true, | ||
DateCreated = DateTime.UtcNow.Subtract(TimeSpan.FromHours(10)) | ||
} | ||
); | ||
|
||
Service = new BuildCleanupService( | ||
Substitute.For<IServiceProvider>(), | ||
Substitute.For<ILogger<BuildCleanupService>>(), | ||
TimeSpan.Zero | ||
); | ||
} | ||
|
||
public BuildCleanupService Service { get; } | ||
|
||
public async Task CheckBuildsAsync() | ||
{ | ||
await Service.CheckEntitiesAsync(Builds, CancellationToken.None); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/Serval/test/Serval.WordAlignment.Tests/Services/EngineCleanupServiceTests.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,64 @@ | ||
namespace Serval.WordAlignment.Services; | ||
|
||
[TestFixture] | ||
public class EngineCleanupServiceTests | ||
{ | ||
[Test] | ||
public async Task CleanupAsync() | ||
{ | ||
TestEnvironment env = new(); | ||
Assert.That(env.Engines.Count, Is.EqualTo(2)); | ||
await env.CheckEnginesAsync(); | ||
Assert.That(env.Engines.Count, Is.EqualTo(1)); | ||
Assert.That((await env.Engines.GetAllAsync())[0].Id, Is.EqualTo("engine2")); | ||
} | ||
|
||
private class TestEnvironment | ||
{ | ||
public MemoryRepository<Engine> Engines { get; } | ||
|
||
public TestEnvironment() | ||
{ | ||
Engines = new MemoryRepository<Engine>(); | ||
Engines.Add( | ||
new Engine | ||
{ | ||
Id = "engine1", | ||
SourceLanguage = "en", | ||
TargetLanguage = "es", | ||
Type = "Nmt", | ||
Owner = "client1", | ||
IsInitialized = false, | ||
DateCreated = DateTime.UtcNow.Subtract(TimeSpan.FromHours(10)), | ||
ParallelCorpora = [] | ||
} | ||
); | ||
Engines.Add( | ||
new Engine | ||
{ | ||
Id = "engine2", | ||
SourceLanguage = "en", | ||
TargetLanguage = "es", | ||
Type = "Nmt", | ||
Owner = "client1", | ||
IsInitialized = true, | ||
DateCreated = DateTime.UtcNow.Subtract(TimeSpan.FromHours(10)), | ||
ParallelCorpora = [] | ||
} | ||
); | ||
|
||
Service = new EngineCleanupService( | ||
Substitute.For<IServiceProvider>(), | ||
Substitute.For<ILogger<EngineCleanupService>>(), | ||
TimeSpan.Zero | ||
); | ||
} | ||
|
||
public EngineCleanupService Service { get; } | ||
|
||
public async Task CheckEnginesAsync() | ||
{ | ||
await Service.CheckEntitiesAsync(Engines, CancellationToken.None); | ||
} | ||
} | ||
} |