Added more UI logic. Added a manga pipeline test.
This commit is contained in:
@@ -40,7 +40,8 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="Shouldly" Version="4.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
|
||||
53
MangaReader.Tests/Pipeline/MangaPipelineTests.cs
Normal file
53
MangaReader.Tests/Pipeline/MangaPipelineTests.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using MangaReader.Core.Data;
|
||||
using MangaReader.Core.Metadata;
|
||||
using MangaReader.Core.Pipeline;
|
||||
using MangaReader.Tests.Utilities;
|
||||
|
||||
namespace MangaReader.Tests.Pipeline;
|
||||
|
||||
public class MangaPipelineTests(TestDbContextFactory factory) : IClassFixture<TestDbContextFactory>
|
||||
{
|
||||
[Fact]
|
||||
public async Task RunAsync_SavesMangaTitlesChaptersGenres()
|
||||
{
|
||||
using MangaContext context = factory.CreateContext();
|
||||
var pipeline = new MangaPipeline(context);
|
||||
|
||||
var sourceManga = new SourceManga
|
||||
{
|
||||
Title = "Fullmetal Alchemist",
|
||||
AlternateTitles =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Title = "Hagane no Renkinjutsushi",
|
||||
Language = SourceMangaLanguage.Romanji
|
||||
}
|
||||
],
|
||||
Genres = ["Action", "Adventure"],
|
||||
Chapters =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Number = 1,
|
||||
Title = "The Two Alchemists",
|
||||
Volume = 1,
|
||||
Url = string.Empty
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
MangaPipelineRequest request = new()
|
||||
{
|
||||
SourceName = "MySource",
|
||||
SourceManga = sourceManga
|
||||
};
|
||||
|
||||
await pipeline.RunAsync(request);
|
||||
|
||||
Assert.Single(context.Mangas);
|
||||
Assert.Single(context.MangaTitles);
|
||||
Assert.Equal(2, context.Genres.Count());
|
||||
Assert.Single(context.MangaChapters);
|
||||
}
|
||||
}
|
||||
36
MangaReader.Tests/Utilities/TestDbContextFactory.cs
Normal file
36
MangaReader.Tests/Utilities/TestDbContextFactory.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using MangaReader.Core.Data;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MangaReader.Tests.Utilities;
|
||||
|
||||
public class TestDbContextFactory : IDisposable
|
||||
{
|
||||
private readonly SqliteConnection _connection;
|
||||
private readonly DbContextOptions<MangaContext> _options;
|
||||
|
||||
public TestDbContextFactory()
|
||||
{
|
||||
_connection = new SqliteConnection("DataSource=:memory:");
|
||||
_connection.Open();
|
||||
|
||||
_options = new DbContextOptionsBuilder<MangaContext>()
|
||||
.UseSqlite(_connection)
|
||||
.EnableSensitiveDataLogging() // Optional: helps with debugging
|
||||
.Options;
|
||||
|
||||
using MangaContext context = new(_options);
|
||||
context.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public MangaContext CreateContext()
|
||||
{
|
||||
return new MangaContext(_options);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_connection.Close();
|
||||
_connection.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user