mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 07:01:10 +00:00
Replaces MVC with FastEndpoints in Lumina.Presentation.Api
This commit is contained in:
1 parent
b1a20716df
commit
c7b8bc2f1c
519 files changed
+15329
-8539
No files matched your search
+2
-14
@@ -1,6 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
@@ -23,16 +21,6 @@ namespace Lumina.DataAccess.UnitTests.Common.DependencyInjection;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DataAccessLayerServicesTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DataAccessLayerServicesTests"/> class.
|
||||
/// </summary>
|
||||
public DataAccessLayerServicesTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddDataAccessLayerServices_WhenBasePathExists_ShouldAddServices()
|
||||
{
|
||||
@@ -83,4 +71,4 @@ public class DataAccessLayerServicesTests
|
||||
IBookRepository? repository = serviceProvider.GetService<IBookRepository>();
|
||||
repository.Should().NotBeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
-25
@@ -2,9 +2,9 @@
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Models.Common;
|
||||
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.DataAccess.Core.Repositories.Books;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Books.Fixtures;
|
||||
@@ -44,7 +44,7 @@ public class BookRepositoryTests
|
||||
public async Task InsertAsync_WhenBookDoesNotExist_ShouldAddBookToContextAndReturnCreated()
|
||||
{
|
||||
// Arrange
|
||||
BookModel bookModel = _bookModelFixture.CreateBookModel();
|
||||
BookEntity bookModel = _bookModelFixture.CreateBookModel();
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
@@ -54,7 +54,7 @@ public class BookRepositoryTests
|
||||
result.Value.Should().Be(Result.Created);
|
||||
|
||||
// Check if the book was added to the context's ChangeTracker
|
||||
EntityEntry<BookModel>? addedBook = _mockContext.ChangeTracker.Entries<BookModel>()
|
||||
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
|
||||
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
|
||||
addedBook.Should().NotBeNull();
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class BookRepositoryTests
|
||||
public async Task InsertAsync_WhenBookAlreadyExists_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
BookModel bookModel = _bookModelFixture.CreateBookModel();
|
||||
BookEntity bookModel = _bookModelFixture.CreateBookModel();
|
||||
|
||||
_mockContext.Books.Add(bookModel);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
@@ -74,18 +74,18 @@ public class BookRepositoryTests
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(Errors.WrittenContent.BookAlreadyExists);
|
||||
_mockContext.ChangeTracker.Entries<BookModel>().Should().HaveCount(1); // Only the existing book should be in the context}
|
||||
_mockContext.ChangeTracker.Entries<BookEntity>().Should().HaveCount(1); // Only the existing book should be in the context}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InsertAsync_WhenExistingTagsFound_ShouldReplaceTagsWithExistingOnes()
|
||||
{
|
||||
// Arrange
|
||||
TagModel existingTag = new("Existing");
|
||||
_mockContext.Set<TagModel>().Add(existingTag);
|
||||
TagEntity existingTag = new("Existing");
|
||||
_mockContext.Set<TagEntity>().Add(existingTag);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
BookModel bookModel = _bookModelFixture.CreateBookModel();
|
||||
BookEntity bookModel = _bookModelFixture.CreateBookModel();
|
||||
bookModel.Tags = [new("Existing"), new("New")];
|
||||
|
||||
// Act
|
||||
@@ -95,10 +95,10 @@ public class BookRepositoryTests
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().Be(Result.Created);
|
||||
|
||||
EntityEntry<BookModel>? addedBook = _mockContext.ChangeTracker.Entries<BookModel>()
|
||||
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
|
||||
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
|
||||
addedBook.Should().NotBeNull();
|
||||
BookModel addedBookEntity = addedBook!.Entity;
|
||||
BookEntity addedBookEntity = addedBook!.Entity;
|
||||
addedBookEntity.Tags.Should().HaveCount(2);
|
||||
addedBookEntity.Tags.Should().Contain(t => t.Name == "Existing" && t == existingTag);
|
||||
addedBookEntity.Tags.Should().Contain(t => t.Name == "New" && t != existingTag);
|
||||
@@ -108,11 +108,11 @@ public class BookRepositoryTests
|
||||
public async Task InsertAsync_WhenExistingGenresFound_ShouldReplaceGenresWithExistingOnes()
|
||||
{
|
||||
// Arrange
|
||||
GenreModel existingGenre = new("Existing");
|
||||
_mockContext.Set<GenreModel>().Add(existingGenre);
|
||||
GenreEntity existingGenre = new("Existing");
|
||||
_mockContext.Set<GenreEntity>().Add(existingGenre);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
BookModel bookModel = _bookModelFixture.CreateBookModel();
|
||||
BookEntity bookModel = _bookModelFixture.CreateBookModel();
|
||||
bookModel.Genres = [new("Existing"), new("New")];
|
||||
|
||||
// Act
|
||||
@@ -122,10 +122,10 @@ public class BookRepositoryTests
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().Be(Result.Created);
|
||||
|
||||
EntityEntry<BookModel>? addedBook = _mockContext.ChangeTracker.Entries<BookModel>()
|
||||
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
|
||||
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
|
||||
addedBook.Should().NotBeNull();
|
||||
BookModel addedBookEntity = addedBook!.Entity;
|
||||
BookEntity addedBookEntity = addedBook!.Entity;
|
||||
addedBookEntity.Genres.Should().HaveCount(2);
|
||||
addedBookEntity.Genres.Should().Contain(g => g.Name == "Existing" && g == existingGenre);
|
||||
addedBookEntity.Genres.Should().Contain(g => g.Name == "New" && g != existingGenre);
|
||||
@@ -135,7 +135,7 @@ public class BookRepositoryTests
|
||||
public async Task GetAllAsync_WhenCalled_ShouldReturnAllBooks()
|
||||
{
|
||||
// Arrange
|
||||
List<BookModel> books =
|
||||
List<BookEntity> books =
|
||||
[
|
||||
_bookModelFixture.CreateBookModel(),
|
||||
_bookModelFixture.CreateBookModel(),
|
||||
@@ -145,7 +145,7 @@ public class BookRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<BookModel>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
@@ -158,7 +158,7 @@ public class BookRepositoryTests
|
||||
public async Task GetAllAsync_WhenNoBooksExist_ShouldReturnEmptyList()
|
||||
{
|
||||
// Act
|
||||
ErrorOr<IEnumerable<BookModel>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
@@ -170,21 +170,21 @@ public class BookRepositoryTests
|
||||
public async Task GetAllAsync_WhenCalled_ShouldIncludeRelatedEntities()
|
||||
{
|
||||
// Arrange
|
||||
BookModel book = _bookModelFixture.CreateBookModel();
|
||||
book.Tags = [new TagModel("Tag1"), new TagModel("Tag2")];
|
||||
book.Genres = [new GenreModel("Genre1"), new GenreModel("Genre2")];
|
||||
book.ISBNs = [new IsbnModel("1234567890", IsbnFormat.Isbn10), new IsbnModel("1234567890123", IsbnFormat.Isbn13)];
|
||||
BookEntity book = _bookModelFixture.CreateBookModel();
|
||||
book.Tags = [new TagEntity("Tag1"), new TagEntity("Tag2")];
|
||||
book.Genres = [new GenreEntity("Genre1"), new GenreEntity("Genre2")];
|
||||
book.ISBNs = [new IsbnEntity("1234567890", IsbnFormat.Isbn10), new IsbnEntity("1234567890123", IsbnFormat.Isbn13)];
|
||||
_mockContext.Books.Add(book);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<BookModel>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Should().HaveCount(1);
|
||||
BookModel retrievedBook = result.Value.First();
|
||||
BookEntity retrievedBook = result.Value.First();
|
||||
retrievedBook.Tags.Should().HaveCount(2);
|
||||
retrievedBook.Genres.Should().HaveCount(2);
|
||||
retrievedBook.ISBNs.Should().HaveCount(2);
|
||||
|
||||
+24
-24
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Models.Common;
|
||||
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.DataAccess.UnitTests.Common.Setup;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -14,7 +14,7 @@ using System.Linq;
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Books.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BookModel"/> class.
|
||||
/// Fixture class for the <see cref="BookEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookModelFixture
|
||||
@@ -39,12 +39,12 @@ public class BookModelFixture
|
||||
/// Creates a random valid BookModel.
|
||||
/// </summary>
|
||||
/// <returns>The created BookModel.</returns>
|
||||
public BookModel CreateBookModel()
|
||||
public BookEntity CreateBookModel()
|
||||
{
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
return new Faker<BookModel>()
|
||||
return new Faker<BookEntity>()
|
||||
.RuleFor(x => x.Id, f => f.Random.Guid())
|
||||
.RuleFor(x => x.Title, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
@@ -61,8 +61,8 @@ public class BookModelFixture
|
||||
.RuleFor(x => x.OriginalLanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(x => x.OriginalLanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.OriginalLanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.Tags, f => new HashSet<TagModel>(CreateTags(f.Random.Number(1, 5))))
|
||||
.RuleFor(x => x.Genres, f => new HashSet<GenreModel>(CreateGenres(f.Random.Number(1, 5))))
|
||||
.RuleFor(x => x.Tags, f => new HashSet<TagEntity>(CreateTags(f.Random.Number(1, 5))))
|
||||
.RuleFor(x => x.Genres, f => new HashSet<GenreEntity>(CreateGenres(f.Random.Number(1, 5))))
|
||||
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
|
||||
.RuleFor(x => x.PageCount, _random.Next(100, 300))
|
||||
.RuleFor(x => x.Format, f => f.PickRandom<BookFormat>().ToString())
|
||||
@@ -84,17 +84,17 @@ public class BookModelFixture
|
||||
.Generate();
|
||||
}
|
||||
|
||||
private List<TagModel> CreateTags(int count)
|
||||
private static List<TagEntity> CreateTags(int count)
|
||||
{
|
||||
return new Faker<TagModel>()
|
||||
.CustomInstantiator(f => new TagModel(f.Random.String2(f.Random.Number(1, 50))))
|
||||
return new Faker<TagEntity>()
|
||||
.CustomInstantiator(f => new TagEntity(f.Random.String2(f.Random.Number(1, 50))))
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
private List<GenreModel> CreateGenres(int count)
|
||||
private static List<GenreEntity> CreateGenres(int count)
|
||||
{
|
||||
return new Faker<GenreModel>()
|
||||
.CustomInstantiator(f => new GenreModel(f.Random.String2(f.Random.Number(1, 50))))
|
||||
return new Faker<GenreEntity>()
|
||||
.CustomInstantiator(f => new GenreEntity(f.Random.String2(f.Random.Number(1, 50))))
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
@@ -138,14 +138,14 @@ public class BookModelFixture
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private List<IsbnModel> CreateIsbns(int count)
|
||||
private static List<IsbnEntity> CreateIsbns(int count)
|
||||
{
|
||||
return new Faker<IsbnModel>()
|
||||
.CustomInstantiator(f => new IsbnModel(CreateIsbn(f), f.PickRandom<IsbnFormat>()))
|
||||
return new Faker<IsbnEntity>()
|
||||
.CustomInstantiator(f => new IsbnEntity(CreateIsbn(f), f.PickRandom<IsbnFormat>()))
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
private string CreateIsbn(Faker f)
|
||||
private static string CreateIsbn(Faker f)
|
||||
{
|
||||
bool isIsbn13 = f.Random.Bool();
|
||||
if (isIsbn13)
|
||||
@@ -175,10 +175,10 @@ public class BookModelFixture
|
||||
}
|
||||
}
|
||||
|
||||
private List<BookRatingModel> CreateBookRatings(int count)
|
||||
private static List<BookRatingEntity> CreateBookRatings(int count)
|
||||
{
|
||||
return new Faker<BookRatingModel>()
|
||||
.CustomInstantiator(f => new BookRatingModel(
|
||||
return new Faker<BookRatingEntity>()
|
||||
.CustomInstantiator(f => new BookRatingEntity(
|
||||
f.Random.Decimal(1, 5),
|
||||
5,
|
||||
f.PickRandom<BookRatingSource>(),
|
||||
@@ -189,10 +189,10 @@ public class BookModelFixture
|
||||
|
||||
private void ConfigureCustomTypes()
|
||||
{
|
||||
_fixture.Register(() => new TagModel(_fixture.Create<string>()));
|
||||
_fixture.Register(() => new GenreModel(_fixture.Create<string>()));
|
||||
_fixture.Register(() => new IsbnModel(_fixture.Create<string>(), _fixture.Create<IsbnFormat>()));
|
||||
_fixture.Register(() => new BookRatingModel(
|
||||
_fixture.Register(() => new TagEntity(_fixture.Create<string>()));
|
||||
_fixture.Register(() => new GenreEntity(_fixture.Create<string>()));
|
||||
_fixture.Register(() => new IsbnEntity(_fixture.Create<string>(), _fixture.Create<IsbnFormat>()));
|
||||
_fixture.Register(() => new BookRatingEntity(
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<BookRatingSource>(),
|
||||
|
||||
@@ -13,15 +13,21 @@
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
|
||||
<PackageReference Include="Bogus" Version="35.6.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
||||
<PackageReference Include="EntityFrameworkCore.Testing.NSubstitute" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in new issue
Block a user