Adds the music library persistence model, its repositories, and the scanning migration

This commit is contained in:
BinaryAlley committed 2026-10-08 20:48:00 +03:00
1 parent 4f0526faa4
commit 00376c8313
63 files changed
+8679 -203

No files matched your search

@@ -70,11 +70,11 @@ public class AlbumConfigurationTests : IDisposable
IProperty originalTitleProperty = entityType.GetProperty(nameof(AlbumEntity.OriginalTitle));
IProperty descriptionProperty = entityType.GetProperty(nameof(AlbumEntity.Description));
IProperty releaseCountryProperty = entityType.GetProperty(nameof(AlbumEntity.ReleaseCountry));
IProperty releaseTypeProperty = entityType.GetProperty(nameof(AlbumEntity.ReleaseType));
IProperty releaseTypeProperty = entityType.FindNavigation(nameof(AlbumEntity.ReleaseTypes))!.TargetEntityType.GetProperty(nameof(AlbumReleaseTypeEntity.ReleaseType));
IProperty releaseStatusProperty = entityType.GetProperty(nameof(AlbumEntity.ReleaseStatus));
IProperty mediaFormatProperty = entityType.GetProperty(nameof(AlbumEntity.MediaFormat));
IProperty barcodeProperty = entityType.GetProperty(nameof(AlbumEntity.Barcode));
IProperty catalogNumberProperty = entityType.GetProperty(nameof(AlbumEntity.CatalogNumber));
IProperty catalogNumberProperty = entityType.FindNavigation(nameof(AlbumEntity.CatalogNumbers))!.TargetEntityType.GetProperty(nameof(AlbumCatalogNumberEntity.CatalogNumber));
IProperty languageCodeProperty = entityType.GetProperty(nameof(AlbumEntity.LanguageCode));
// Assert
@@ -87,7 +87,7 @@ public class AlbumConfigurationTests : IDisposable
Assert.Equal(typeof(ReleaseCountry?), releaseCountryProperty.ClrType);
Assert.Equal("TEXT", releaseCountryProperty.GetColumnType());
Assert.Equal(2, releaseCountryProperty.GetMaxLength());
Assert.Equal(typeof(MusicReleaseType?), releaseTypeProperty.ClrType);
Assert.Equal(typeof(MusicReleaseType), releaseTypeProperty.ClrType);
Assert.Equal("TEXT", releaseTypeProperty.GetColumnType());
Assert.Equal(50, releaseTypeProperty.GetMaxLength());
Assert.Equal(typeof(MusicReleaseStatus?), releaseStatusProperty.ClrType);
@@ -1,4 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
@@ -0,0 +1,163 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.DataAccess.UnitTests.Common.Configuration;
/// <summary>
/// Contains unit tests for the <see cref="MusicLibraryScanItemMetadataConfiguration"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class MusicLibraryScanItemMetadataConfigurationTests : IDisposable
{
private readonly LuminaDbContext _context;
/// <summary>
/// Initializes a new instance of the <see cref="MusicLibraryScanItemMetadataConfigurationTests"/> class.
/// </summary>
public MusicLibraryScanItemMetadataConfigurationTests()
{
_context = new LuminaDbContext(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite("Data Source=:memory:").Options);
}
[Fact]
public void Configure_WhenApplied_ShouldSetTableNameAndKey()
{
// Arrange
IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!;
// Act
string? tableName = entityType.GetTableName();
IReadOnlyList<IProperty> keyProperties = entityType.FindPrimaryKey()!.Properties;
// Assert
Assert.Equal("MusicLibraryScanItemMetadata", tableName);
Assert.Equal(["Id"], keyProperties.Select(property => property.Name));
}
[Fact]
public void Configure_WhenApplied_ShouldNotGenerateTheIdValue()
{
// Arrange
IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!;
// Act
IProperty idProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.Id));
// Assert
Assert.Equal(ValueGenerated.Never, idProperty.ValueGenerated);
}
[Fact]
public void Configure_WhenApplied_ShouldConfigureRequiredScalarProperties()
{
// Arrange
IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!;
// Act
IProperty libraryScanIdProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.LibraryScanId));
IProperty libraryIdProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.LibraryId));
IProperty pathProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.Path));
// Assert
Assert.False(libraryScanIdProperty.IsNullable);
Assert.False(libraryIdProperty.IsNullable);
Assert.False(pathProperty.IsNullable);
Assert.Equal(2048, pathProperty.GetMaxLength());
}
[Fact]
public void Configure_WhenApplied_ShouldConfigureOptionalScalarProperties()
{
// Arrange
IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!;
// Act
IProperty artistNameProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ArtistName));
IProperty releaseTypeProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReleaseType));
IProperty releaseYearProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReleaseYear));
IProperty releaseNameProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReleaseName));
IProperty trackTitleProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.TrackTitle));
IProperty audioCodecProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.AudioCodec));
IProperty workTitleProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.WorkTitle));
IProperty acoustIdProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.AcoustId));
// Assert
Assert.True(artistNameProperty.IsNullable);
Assert.Equal(255, artistNameProperty.GetMaxLength());
Assert.True(releaseTypeProperty.IsNullable);
Assert.Equal(typeof(MusicReleaseType?), releaseTypeProperty.ClrType);
Assert.Equal("TEXT", releaseTypeProperty.GetColumnType());
Assert.Equal(50, releaseTypeProperty.GetMaxLength());
Assert.True(releaseYearProperty.IsNullable);
Assert.Equal(255, releaseNameProperty.GetMaxLength());
Assert.Equal(255, trackTitleProperty.GetMaxLength());
Assert.Equal(50, audioCodecProperty.GetMaxLength());
Assert.Equal(255, workTitleProperty.GetMaxLength());
Assert.Equal(64, acoustIdProperty.GetMaxLength());
}
[Fact]
public void Configure_WhenApplied_ShouldConfigureReplayGainDecimalPrecision()
{
// Arrange
IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!;
// Act
IProperty trackGainProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReplayGainTrackGain));
IProperty trackPeakProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReplayGainTrackPeak));
IProperty albumGainProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReplayGainAlbumGain));
IProperty albumPeakProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReplayGainAlbumPeak));
// Assert
Assert.Equal("decimal(8,2)", trackGainProperty.GetColumnType());
Assert.Equal("decimal(8,6)", trackPeakProperty.GetColumnType());
Assert.Equal("decimal(8,2)", albumGainProperty.GetColumnType());
Assert.Equal("decimal(8,6)", albumPeakProperty.GetColumnType());
}
[Fact]
public void Configure_WhenApplied_ShouldConfigureMoodsAsPrimitiveCollection()
{
// Arrange
IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!;
// Act
IProperty moodsProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.Moods));
// Assert
Assert.True(moodsProperty.IsPrimitiveCollection);
}
[Fact]
public void Configure_WhenApplied_ShouldConfigureUniqueScanIdPathIndex()
{
// Arrange
IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!;
// Act
List<IIndex> indexes = [.. entityType.GetIndexes()];
// Assert
IIndex uniqueIndex = Assert.Single(indexes, index => index.IsUnique);
Assert.Equal(
[nameof(MusicLibraryScanItemMetadataEntity.LibraryScanId), nameof(MusicLibraryScanItemMetadataEntity.Path)],
uniqueIndex.Properties.Select(property => property.Name));
}
/// <summary>
/// Disposes the database context.
/// </summary>
public void Dispose()
{
_context.Dispose();
}
}
@@ -72,7 +72,7 @@ public class TrackConfigurationTests : IDisposable
IProperty scriptProperty = entityType.GetProperty(nameof(TrackEntity.Script));
IProperty keyProperty = entityType.GetProperty(nameof(TrackEntity.Key));
IProperty audioCodecProperty = entityType.GetProperty(nameof(TrackEntity.AudioCodec));
IProperty workProperty = entityType.GetProperty(nameof(TrackEntity.Work));
IProperty workProperty = entityType.GetProperty(nameof(TrackEntity.WorkTitle));
// Assert
Assert.False(pathProperty.IsNullable);
@@ -118,9 +118,11 @@ public class TrackConfigurationTests : IDisposable
List<IEntityType> ownedTypes = [.. _context.Model.GetEntityTypes().Where(ownedType => ownedType.IsOwned() && ownedType.FindOwnership()?.PrincipalEntityType.Name == entityType.Name)];
// Assert
Assert.Equal(3, ownedTypes.Count);
Assert.Equal(5, ownedTypes.Count);
Assert.Contains(ownedTypes, ownedType => ownedType.ClrType == typeof(TrackMoodEntity) && ownedType.GetTableName() == "TrackMoods");
Assert.Contains(ownedTypes, ownedType => ownedType.ClrType == typeof(TrackIsrcEntity) && ownedType.GetTableName() == "TrackIsrcs");
Assert.Contains(ownedTypes, ownedType => ownedType.ClrType == typeof(TrackWorkLanguageEntity) && ownedType.GetTableName() == "TrackWorkLanguages");
Assert.Contains(ownedTypes, ownedType => ownedType.ClrType == typeof(TrackWorkIswcEntity) && ownedType.GetTableName() == "TrackWorkIswcs");
Assert.Contains(ownedTypes, ownedType => ownedType.ClrType == typeof(AudioRatingEntity) && ownedType.GetTableName() == "TrackRatings");
}