Skip to content

Commit

Permalink
Add cleanup service tests for word alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Dec 18, 2024
1 parent 5a4a2f9 commit 780c79b
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
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);
}
}
}
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);
}
}
}

0 comments on commit 780c79b

Please sign in to comment.