Skip to content

Commit

Permalink
Fix namespace typo; add corpus service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Sep 23, 2024
1 parent 8b4df4a commit 9943811
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Corpora.Contracts;
namespace Serval.DataFiles.Contracts;

public record CorpusConfigDto
{
Expand Down
2 changes: 1 addition & 1 deletion src/Serval/src/Serval.DataFiles/Contracts/CorpusDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Corpora.Contracts;
namespace Serval.DataFiles.Contracts;

public record CorpusDto
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Corpora.Contracts;
namespace Serval.DataFiles.Contracts;

public record CorpusFileConfigDto
{
Expand Down
2 changes: 1 addition & 1 deletion src/Serval/src/Serval.DataFiles/Contracts/CorpusFileDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Corpora.Contracts;
namespace Serval.DataFiles.Contracts;

public record CorpusFileDto
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Corpora.Controllers;
namespace Serval.DataFiles.Controllers;

[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/corpora")]
Expand Down
2 changes: 1 addition & 1 deletion src/Serval/src/Serval.DataFiles/Models/Corpus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Corpora.Models;
namespace Serval.DataFiles.Models;

public record Corpus : IOwnedEntity
{
Expand Down
2 changes: 1 addition & 1 deletion src/Serval/src/Serval.DataFiles/Models/CorpusFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Corpora.Contracts;
namespace Serval.DataFiles.Models;

public record CorpusFile
{
Expand Down
2 changes: 1 addition & 1 deletion src/Serval/src/Serval.DataFiles/Services/CorpusService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Corpora.Services;
namespace Serval.DataFiles.Services;

public class CorpusService(IRepository<Corpus> corpora) : OwnedEntityServiceBase<Corpus>(corpora), ICorpusService
{
Expand Down
2 changes: 1 addition & 1 deletion src/Serval/src/Serval.DataFiles/Services/ICorpusService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Corpora.Services;
namespace Serval.DataFiles.Services;

public interface ICorpusService
{
Expand Down
3 changes: 0 additions & 3 deletions src/Serval/src/Serval.DataFiles/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Options;
global using NSwag.Annotations;
global using Serval.Corpora.Contracts;
global using Serval.Corpora.Models;
global using Serval.Corpora.Services;
global using Serval.DataFiles.Consumers;
global using Serval.DataFiles.Contracts;
global using Serval.DataFiles.Models;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Serval.Translation.Models;

public record ParallelCorpusSubcorpus
public record ParallelCorpusSubcorpus //TODO Better name? Monolingual corpus?
{
public required string Id { get; set; }
public string? Name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Serval.DataFiles.Services;

[TestFixture]
public class CorpusServiceTests
{
private const string CorpusId = "c00000000000000000000001";

private static readonly DataFile DefaultDataFile =
new()
{
Id = "df0000000000000000000001",
Owner = "owner1",
Name = "file1",
Filename = "file1.txt",
Format = FileFormat.Text
};
private static readonly Corpus DefaultCorpus =
new()
{
Id = CorpusId,
Owner = "owner1",
Name = "corpus1",
Language = "en",
Files = new List<CorpusFile>() { new() { File = DefaultDataFile } }
};

[Test]
public async Task CreateAsync()
{
var env = new TestEnvironment();
Corpus corpus = await env.Service.CreateAsync(DefaultCorpus);
Assert.That(corpus.Name, Is.EqualTo((await env.Service.GetAsync(CorpusId)).Name));
}

[Test]
public async Task UpdateAsync()
{
var env = new TestEnvironment();
await env.Service.CreateAsync(DefaultCorpus);
await env.Service.UpdateAsync(CorpusId, new List<CorpusFile>());
Corpus corpus = await env.Service.GetAsync(CorpusId);
Assert.That(corpus.Files, Has.Count.EqualTo(0));
}

private class TestEnvironment
{
public TestEnvironment()
{
Corpora = new MemoryRepository<Corpus>();
Service = new CorpusService(Corpora);
}

public MemoryRepository<Corpus> Corpora { get; }

public CorpusService Service { get; }
}
}

0 comments on commit 9943811

Please sign in to comment.