mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 19:11:10 +00:00
Normalizes tag and genre names and migrates existing values
This commit is contained in:
1 parent
8a5cb9116e
commit
eaca69bf2a
19 files changed
+4089
-58
No files matched your search
+38
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.DataAccess.Common.Interceptors;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.IntegrationTests.Common.Interceptors;
|
||||
|
||||
/// <summary>
|
||||
/// Contains integration tests for the <see cref="SqliteSharedReferenceNormalizationInterceptor"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SqliteSharedReferenceNormalizationInterceptorTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(" Horror ", "horror")] // ASCII letters
|
||||
[InlineData(" ÉLECTRO ", "électro")] // non-ASCII Latin letters
|
||||
[InlineData("ЖАНР", "жанр")] // non-Latin letters
|
||||
public async Task ConnectionOpenedAsync_WhenTheConnectionIsOpened_ShouldRegisterTheInvariantNormalizationFunction(string name, string expectedName)
|
||||
{
|
||||
// Arrange
|
||||
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite("Data Source=:memory:").Options);
|
||||
|
||||
// Act
|
||||
await context.Database.OpenConnectionAsync();
|
||||
SqliteConnection connection = (SqliteConnection)context.Database.GetDbConnection();
|
||||
await using SqliteCommand command = connection.CreateCommand();
|
||||
command.CommandText = $"SELECT {SqliteSharedReferenceNormalizationInterceptor.NORMALIZE_FUNCTION_NAME}($name);";
|
||||
command.Parameters.AddWithValue("$name", name);
|
||||
object? result = await command.ExecuteScalarAsync();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedName, result);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -212,10 +212,10 @@ public class AddTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
|
||||
|
||||
// Genres and tags checks.
|
||||
Assert.Equal(
|
||||
metadata.Genres!.Select(genre => genre.Name).OrderBy(name => name),
|
||||
metadata.Genres!.Select(genre => genre.Name!.ToLowerInvariant()).OrderBy(name => name),
|
||||
trackResponse.Metadata.Genres!.Select(genre => genre.Name).OrderBy(name => name));
|
||||
Assert.Equal(
|
||||
metadata.Tags!.Select(tag => tag.Name).OrderBy(name => name),
|
||||
metadata.Tags!.Select(tag => tag.Name!.ToLowerInvariant()).OrderBy(name => name),
|
||||
trackResponse.Metadata.Tags!.Select(tag => tag.Name).OrderBy(name => name));
|
||||
|
||||
// Moods, ISRCs, contributors and ratings checks.
|
||||
|
||||
+4
-4
@@ -133,14 +133,14 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
// genres checks
|
||||
Assert.Equal(bookRequest.Metadata.Genres!.Count, bookResponse.Metadata.Genres!.Count);
|
||||
Assert.Equal(
|
||||
bookRequest.Metadata.Genres.Select(genre => genre.Name).OrderBy(x => x),
|
||||
bookResponse.Metadata.Genres.Select(genre => genre.Name).OrderBy(x => x));
|
||||
bookRequest.Metadata.Genres.Select(genre => genre.Name!.ToLowerInvariant()).OrderBy(name => name),
|
||||
bookResponse.Metadata.Genres.Select(genre => genre.Name).OrderBy(name => name));
|
||||
|
||||
// tags checks
|
||||
Assert.Equal(bookRequest.Metadata.Tags!.Count, bookResponse.Metadata.Tags!.Count);
|
||||
Assert.Equal(
|
||||
bookRequest.Metadata.Tags.Select(tag => tag.Name).OrderBy(x => x),
|
||||
bookResponse.Metadata.Tags.Select(tag => tag.Name).OrderBy(x => x));
|
||||
bookRequest.Metadata.Tags.Select(tag => tag.Name!.ToLowerInvariant()).OrderBy(name => name),
|
||||
bookResponse.Metadata.Tags.Select(tag => tag.Name).OrderBy(name => name));
|
||||
|
||||
// book specific properties
|
||||
Assert.Equal(bookRequest.Format, bookResponse.Format);
|
||||
|
||||
+2
-2
@@ -461,8 +461,8 @@ public class GetBooksEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
BookEntity book = _bookEntityFixture.Create(libraryId: libraryId, title: title, path: $"/books/{Guid.NewGuid()}.epub", includeMetadata: false);
|
||||
book.Tags = [_tagEntityFixture.Create(name: $"Tag-{Guid.NewGuid()}")];
|
||||
book.Genres = [_genreEntityFixture.Create(name: $"Genre-{Guid.NewGuid()}")];
|
||||
book.Tags = [_tagEntityFixture.Create(name: $"tag-{Guid.NewGuid()}")];
|
||||
book.Genres = [_genreEntityFixture.Create(name: $"genre-{Guid.NewGuid()}")];
|
||||
book.ISBNs = [_isbnEntityFixture.Create(value: "9780395272237", format: IsbnFormat.Isbn13)];
|
||||
book.Ratings = [_bookRatingEntityFixture.Create(value: 4.5M, maxValue: 5, source: BookRatingSource.Goodreads, voteCount: 100)];
|
||||
dbContext.Books.Add(book);
|
||||
|
||||
Reference in new issue
Block a user