From 99438110102f523bf5da67f4ccbb16940286690f Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Mon, 23 Sep 2024 16:48:46 -0400 Subject: [PATCH] Fix namespace typo; add corpus service tests --- .../Contracts/CorpusConfigDto.cs | 2 +- .../Serval.DataFiles/Contracts/CorpusDto.cs | 2 +- .../Contracts/CorpusFileConfigDto.cs | 2 +- .../Contracts/CorpusFileDto.cs | 2 +- .../Controllers/CorporaController.cs | 2 +- .../src/Serval.DataFiles/Models/Corpus.cs | 2 +- .../src/Serval.DataFiles/Models/CorpusFile.cs | 2 +- .../Services/CorpusService.cs | 2 +- .../Services/ICorpusService.cs | 2 +- src/Serval/src/Serval.DataFiles/Usings.cs | 3 - .../Models/ParallelCorpusSubcorpus.cs | 2 +- .../Services/CorpusServiceTests.cs | 57 +++++++++++++++++++ 12 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 src/Serval/test/Serval.DataFiles.Tests/Services/CorpusServiceTests.cs diff --git a/src/Serval/src/Serval.DataFiles/Contracts/CorpusConfigDto.cs b/src/Serval/src/Serval.DataFiles/Contracts/CorpusConfigDto.cs index a4f68b51..cb744e41 100644 --- a/src/Serval/src/Serval.DataFiles/Contracts/CorpusConfigDto.cs +++ b/src/Serval/src/Serval.DataFiles/Contracts/CorpusConfigDto.cs @@ -1,4 +1,4 @@ -namespace Serval.Corpora.Contracts; +namespace Serval.DataFiles.Contracts; public record CorpusConfigDto { diff --git a/src/Serval/src/Serval.DataFiles/Contracts/CorpusDto.cs b/src/Serval/src/Serval.DataFiles/Contracts/CorpusDto.cs index 198cda6b..b7446fa3 100644 --- a/src/Serval/src/Serval.DataFiles/Contracts/CorpusDto.cs +++ b/src/Serval/src/Serval.DataFiles/Contracts/CorpusDto.cs @@ -1,4 +1,4 @@ -namespace Serval.Corpora.Contracts; +namespace Serval.DataFiles.Contracts; public record CorpusDto { diff --git a/src/Serval/src/Serval.DataFiles/Contracts/CorpusFileConfigDto.cs b/src/Serval/src/Serval.DataFiles/Contracts/CorpusFileConfigDto.cs index 9671057b..746a9686 100644 --- a/src/Serval/src/Serval.DataFiles/Contracts/CorpusFileConfigDto.cs +++ b/src/Serval/src/Serval.DataFiles/Contracts/CorpusFileConfigDto.cs @@ -1,4 +1,4 @@ -namespace Serval.Corpora.Contracts; +namespace Serval.DataFiles.Contracts; public record CorpusFileConfigDto { diff --git a/src/Serval/src/Serval.DataFiles/Contracts/CorpusFileDto.cs b/src/Serval/src/Serval.DataFiles/Contracts/CorpusFileDto.cs index 5e9a5ded..d2d175be 100644 --- a/src/Serval/src/Serval.DataFiles/Contracts/CorpusFileDto.cs +++ b/src/Serval/src/Serval.DataFiles/Contracts/CorpusFileDto.cs @@ -1,4 +1,4 @@ -namespace Serval.Corpora.Contracts; +namespace Serval.DataFiles.Contracts; public record CorpusFileDto { diff --git a/src/Serval/src/Serval.DataFiles/Controllers/CorporaController.cs b/src/Serval/src/Serval.DataFiles/Controllers/CorporaController.cs index 56a8d691..29bf041e 100644 --- a/src/Serval/src/Serval.DataFiles/Controllers/CorporaController.cs +++ b/src/Serval/src/Serval.DataFiles/Controllers/CorporaController.cs @@ -1,4 +1,4 @@ -namespace Serval.Corpora.Controllers; +namespace Serval.DataFiles.Controllers; [ApiVersion("1.0")] [Route("api/v{version:apiVersion}/corpora")] diff --git a/src/Serval/src/Serval.DataFiles/Models/Corpus.cs b/src/Serval/src/Serval.DataFiles/Models/Corpus.cs index 49ff113d..8a4fca70 100644 --- a/src/Serval/src/Serval.DataFiles/Models/Corpus.cs +++ b/src/Serval/src/Serval.DataFiles/Models/Corpus.cs @@ -1,4 +1,4 @@ -namespace Serval.Corpora.Models; +namespace Serval.DataFiles.Models; public record Corpus : IOwnedEntity { diff --git a/src/Serval/src/Serval.DataFiles/Models/CorpusFile.cs b/src/Serval/src/Serval.DataFiles/Models/CorpusFile.cs index 98d3b7ff..a4311e39 100644 --- a/src/Serval/src/Serval.DataFiles/Models/CorpusFile.cs +++ b/src/Serval/src/Serval.DataFiles/Models/CorpusFile.cs @@ -1,4 +1,4 @@ -namespace Serval.Corpora.Contracts; +namespace Serval.DataFiles.Models; public record CorpusFile { diff --git a/src/Serval/src/Serval.DataFiles/Services/CorpusService.cs b/src/Serval/src/Serval.DataFiles/Services/CorpusService.cs index f1f80d01..f5b8e4b6 100644 --- a/src/Serval/src/Serval.DataFiles/Services/CorpusService.cs +++ b/src/Serval/src/Serval.DataFiles/Services/CorpusService.cs @@ -1,4 +1,4 @@ -namespace Serval.Corpora.Services; +namespace Serval.DataFiles.Services; public class CorpusService(IRepository corpora) : OwnedEntityServiceBase(corpora), ICorpusService { diff --git a/src/Serval/src/Serval.DataFiles/Services/ICorpusService.cs b/src/Serval/src/Serval.DataFiles/Services/ICorpusService.cs index d76b25b6..a4f0e242 100644 --- a/src/Serval/src/Serval.DataFiles/Services/ICorpusService.cs +++ b/src/Serval/src/Serval.DataFiles/Services/ICorpusService.cs @@ -1,4 +1,4 @@ -namespace Serval.Corpora.Services; +namespace Serval.DataFiles.Services; public interface ICorpusService { diff --git a/src/Serval/src/Serval.DataFiles/Usings.cs b/src/Serval/src/Serval.DataFiles/Usings.cs index 0054bbee..0d81ccb1 100644 --- a/src/Serval/src/Serval.DataFiles/Usings.cs +++ b/src/Serval/src/Serval.DataFiles/Usings.cs @@ -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; diff --git a/src/Serval/src/Serval.Translation/Models/ParallelCorpusSubcorpus.cs b/src/Serval/src/Serval.Translation/Models/ParallelCorpusSubcorpus.cs index 281100a6..2173619f 100644 --- a/src/Serval/src/Serval.Translation/Models/ParallelCorpusSubcorpus.cs +++ b/src/Serval/src/Serval.Translation/Models/ParallelCorpusSubcorpus.cs @@ -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; } diff --git a/src/Serval/test/Serval.DataFiles.Tests/Services/CorpusServiceTests.cs b/src/Serval/test/Serval.DataFiles.Tests/Services/CorpusServiceTests.cs new file mode 100644 index 00000000..22cdd14e --- /dev/null +++ b/src/Serval/test/Serval.DataFiles.Tests/Services/CorpusServiceTests.cs @@ -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() { 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()); + Corpus corpus = await env.Service.GetAsync(CorpusId); + Assert.That(corpus.Files, Has.Count.EqualTo(0)); + } + + private class TestEnvironment + { + public TestEnvironment() + { + Corpora = new MemoryRepository(); + Service = new CorpusService(Corpora); + } + + public MemoryRepository Corpora { get; } + + public CorpusService Service { get; } + } +}