mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 21:11:10 +00:00
Implements directory browser dialog, part 1: file system treeview
This commit is contained in:
1 parent
4a53348013
commit
4e4ecbbfca
318 files changed
+6012
-1184
No files matched your search
+3
-1
@@ -11,6 +11,8 @@ using Lumina.DataAccess.Core.UoW;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Common.DependencyInjection;
|
||||
@@ -41,7 +43,7 @@ public class DataAccessLayerServicesTests
|
||||
{
|
||||
// Arrange
|
||||
var services = new ServiceCollection();
|
||||
var basePath = Path.GetTempPath(); // Use a real existing path
|
||||
var basePath = Path.GetTempPath(); // use a real existing path
|
||||
|
||||
// Act
|
||||
DataAccessLayerServices.AddDataAccessLayerServices(services);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture.Kernel;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
|
||||
+1
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture.Kernel;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
|
||||
+39
-35
@@ -2,15 +2,19 @@
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Models.Books;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
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;
|
||||
using Lumina.Domain.Common.Enums;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Books;
|
||||
@@ -24,7 +28,7 @@ public class BookRepositoryTests
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly LuminaDbContext _mockContext;
|
||||
private readonly BookRepository _sut;
|
||||
private readonly BookDtoFixture _bookDtoFixture;
|
||||
private readonly BookModelFixture _bookModelFixture;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
@@ -35,7 +39,7 @@ public class BookRepositoryTests
|
||||
{
|
||||
_mockContext = Create.MockedDbContextFor<LuminaDbContext>();
|
||||
_sut = new BookRepository(_mockContext);
|
||||
_bookDtoFixture = new BookDtoFixture();
|
||||
_bookModelFixture = new BookModelFixture();
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -44,18 +48,18 @@ public class BookRepositoryTests
|
||||
public async Task InsertAsync_WhenBookDoesNotExist_ShouldAddBookToContextAndReturnCreated()
|
||||
{
|
||||
// Arrange
|
||||
var bookDto = _bookDtoFixture.CreateBookDto();
|
||||
var bookModel = _bookModelFixture.CreateBookModel();
|
||||
|
||||
// Act
|
||||
var result = await _sut.InsertAsync(bookDto, CancellationToken.None);
|
||||
var result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().Be(Result.Created);
|
||||
|
||||
// Check if the book was added to the context's ChangeTracker
|
||||
var addedBook = _mockContext.ChangeTracker.Entries<BookDto>()
|
||||
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookDto.Id);
|
||||
var addedBook = _mockContext.ChangeTracker.Entries<BookModel>()
|
||||
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
|
||||
addedBook.Should().NotBeNull();
|
||||
}
|
||||
|
||||
@@ -63,40 +67,40 @@ public class BookRepositoryTests
|
||||
public async Task InsertAsync_WhenBookAlreadyExists_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
var bookDto = _bookDtoFixture.CreateBookDto();
|
||||
var bookModel = _bookModelFixture.CreateBookModel();
|
||||
|
||||
_mockContext.Books.Add(bookDto);
|
||||
_mockContext.Books.Add(bookModel);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
var result = await _sut.InsertAsync(bookDto, CancellationToken.None);
|
||||
var result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(Errors.WrittenContent.BookAlreadyExists);
|
||||
_mockContext.ChangeTracker.Entries<BookDto>().Should().HaveCount(1); // Only the existing book should be in the context}
|
||||
_mockContext.ChangeTracker.Entries<BookModel>().Should().HaveCount(1); // Only the existing book should be in the context}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InsertAsync_WhenExistingTagsFound_ShouldReplaceTagsWithExistingOnes()
|
||||
{
|
||||
// Arrange
|
||||
var existingTag = new TagDto("Existing");
|
||||
_mockContext.Set<TagDto>().Add(existingTag);
|
||||
var existingTag = new TagModel("Existing");
|
||||
_mockContext.Set<TagModel>().Add(existingTag);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
var bookDto = _bookDtoFixture.CreateBookDto();
|
||||
bookDto.Tags = [new("Existing"), new("New")];
|
||||
var bookModel = _bookModelFixture.CreateBookModel();
|
||||
bookModel.Tags = [new("Existing"), new("New")];
|
||||
|
||||
// Act
|
||||
var result = await _sut.InsertAsync(bookDto, CancellationToken.None);
|
||||
var result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().Be(Result.Created);
|
||||
|
||||
var addedBook = _mockContext.ChangeTracker.Entries<BookDto>()
|
||||
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookDto.Id);
|
||||
var addedBook = _mockContext.ChangeTracker.Entries<BookModel>()
|
||||
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
|
||||
addedBook.Should().NotBeNull();
|
||||
var addedBookEntity = addedBook!.Entity;
|
||||
addedBookEntity.Tags.Should().HaveCount(2);
|
||||
@@ -108,22 +112,22 @@ public class BookRepositoryTests
|
||||
public async Task InsertAsync_WhenExistingGenresFound_ShouldReplaceGenresWithExistingOnes()
|
||||
{
|
||||
// Arrange
|
||||
var existingGenre = new GenreDto("Existing");
|
||||
_mockContext.Set<GenreDto>().Add(existingGenre);
|
||||
var existingGenre = new GenreModel("Existing");
|
||||
_mockContext.Set<GenreModel>().Add(existingGenre);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
var bookDto = _bookDtoFixture.CreateBookDto();
|
||||
bookDto.Genres = [new("Existing"), new("New")];
|
||||
var bookModel = _bookModelFixture.CreateBookModel();
|
||||
bookModel.Genres = [new("Existing"), new("New")];
|
||||
|
||||
// Act
|
||||
var result = await _sut.InsertAsync(bookDto, CancellationToken.None);
|
||||
var result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().Be(Result.Created);
|
||||
|
||||
var addedBook = _mockContext.ChangeTracker.Entries<BookDto>()
|
||||
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookDto.Id);
|
||||
var addedBook = _mockContext.ChangeTracker.Entries<BookModel>()
|
||||
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
|
||||
addedBook.Should().NotBeNull();
|
||||
var addedBookEntity = addedBook!.Entity;
|
||||
addedBookEntity.Genres.Should().HaveCount(2);
|
||||
@@ -135,11 +139,11 @@ public class BookRepositoryTests
|
||||
public async Task GetAllAsync_WhenCalled_ShouldReturnAllBooks()
|
||||
{
|
||||
// Arrange
|
||||
var books = new List<BookDto>
|
||||
var books = new List<BookModel>
|
||||
{
|
||||
_bookDtoFixture.CreateBookDto(),
|
||||
_bookDtoFixture.CreateBookDto(),
|
||||
_bookDtoFixture.CreateBookDto()
|
||||
_bookModelFixture.CreateBookModel(),
|
||||
_bookModelFixture.CreateBookModel(),
|
||||
_bookModelFixture.CreateBookModel()
|
||||
};
|
||||
_mockContext.Books.AddRange(books);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
@@ -170,10 +174,10 @@ public class BookRepositoryTests
|
||||
public async Task GetAllAsync_WhenCalled_ShouldIncludeRelatedEntities()
|
||||
{
|
||||
// Arrange
|
||||
var book = _bookDtoFixture.CreateBookDto();
|
||||
book.Tags = [new TagDto("Tag1"), new TagDto("Tag2")];
|
||||
book.Genres = [new GenreDto("Genre1"), new GenreDto("Genre2")];
|
||||
book.ISBNs = [new IsbnDto("1234567890", IsbnFormat.Isbn10), new IsbnDto("1234567890123", IsbnFormat.Isbn13)];
|
||||
var 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)];
|
||||
_mockContext.Books.Add(book);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
|
||||
+33
-33
@@ -1,23 +1,23 @@
|
||||
using AutoFixture;
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.Models.Books;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Models.Common;
|
||||
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.DataAccess.UnitTests.Common.Setup;
|
||||
using Lumina.Domain.Common.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Books.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BookDto"/> class.
|
||||
/// Fixture class for the <see cref="BookModel"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookDtoFixture
|
||||
public class BookModelFixture
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly Fixture _fixture;
|
||||
@@ -27,9 +27,9 @@ public class BookDtoFixture
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookDtoFixture"/> class.
|
||||
/// Initializes a new instance of the <see cref="BookModelFixture"/> class.
|
||||
/// </summary>
|
||||
public BookDtoFixture()
|
||||
public BookModelFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
|
||||
@@ -41,15 +41,15 @@ public class BookDtoFixture
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a random valid BookDto.
|
||||
/// Creates a random valid BookModel.
|
||||
/// </summary>
|
||||
/// <returns>The created BookDto.</returns>
|
||||
public BookDto CreateBookDto()
|
||||
/// <returns>The created BookModel.</returns>
|
||||
public BookModel CreateBookModel()
|
||||
{
|
||||
var releaseYear = _random.Next(2000, 2010);
|
||||
var reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
return new Faker<BookDto>()
|
||||
return new Faker<BookModel>()
|
||||
.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)))
|
||||
@@ -66,8 +66,8 @@ public class BookDtoFixture
|
||||
.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<TagDto>(CreateTags(f.Random.Number(1, 5))))
|
||||
.RuleFor(x => x.Genres, f => new HashSet<GenreDto>(CreateGenres(f.Random.Number(1, 5))))
|
||||
.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.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())
|
||||
@@ -89,17 +89,17 @@ public class BookDtoFixture
|
||||
.Generate();
|
||||
}
|
||||
|
||||
private List<TagDto> CreateTags(int count)
|
||||
private List<TagModel> CreateTags(int count)
|
||||
{
|
||||
return new Faker<TagDto>()
|
||||
.CustomInstantiator(f => new TagDto(f.Random.String2(f.Random.Number(1, 50))))
|
||||
return new Faker<TagModel>()
|
||||
.CustomInstantiator(f => new TagModel(f.Random.String2(f.Random.Number(1, 50))))
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
private List<GenreDto> CreateGenres(int count)
|
||||
private List<GenreModel> CreateGenres(int count)
|
||||
{
|
||||
return new Faker<GenreDto>()
|
||||
.CustomInstantiator(f => new GenreDto(f.Random.String2(f.Random.Number(1, 50))))
|
||||
return new Faker<GenreModel>()
|
||||
.CustomInstantiator(f => new GenreModel(f.Random.String2(f.Random.Number(1, 50))))
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
@@ -143,10 +143,10 @@ public class BookDtoFixture
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private List<IsbnDto> CreateIsbns(int count)
|
||||
private List<IsbnModel> CreateIsbns(int count)
|
||||
{
|
||||
return new Faker<IsbnDto>()
|
||||
.CustomInstantiator(f => new IsbnDto(CreateIsbn(f), f.PickRandom<IsbnFormat>()))
|
||||
return new Faker<IsbnModel>()
|
||||
.CustomInstantiator(f => new IsbnModel(CreateIsbn(f), f.PickRandom<IsbnFormat>()))
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
@@ -180,10 +180,10 @@ public class BookDtoFixture
|
||||
}
|
||||
}
|
||||
|
||||
private List<BookRatingDto> CreateBookRatings(int count)
|
||||
private List<BookRatingModel> CreateBookRatings(int count)
|
||||
{
|
||||
return new Faker<BookRatingDto>()
|
||||
.CustomInstantiator(f => new BookRatingDto(
|
||||
return new Faker<BookRatingModel>()
|
||||
.CustomInstantiator(f => new BookRatingModel(
|
||||
f.Random.Decimal(1, 5),
|
||||
5,
|
||||
f.PickRandom<BookRatingSource>(),
|
||||
@@ -194,10 +194,10 @@ public class BookDtoFixture
|
||||
|
||||
private void ConfigureCustomTypes()
|
||||
{
|
||||
_fixture.Register(() => new TagDto(_fixture.Create<string>()));
|
||||
_fixture.Register(() => new GenreDto(_fixture.Create<string>()));
|
||||
_fixture.Register(() => new IsbnDto(_fixture.Create<string>(), _fixture.Create<IsbnFormat>()));
|
||||
_fixture.Register(() => new BookRatingDto(
|
||||
_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.Create<decimal>(),
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<BookRatingSource>(),
|
||||
@@ -205,4 +205,4 @@ public class BookDtoFixture
|
||||
));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+1
@@ -5,6 +5,7 @@ using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.DataAccess.Core.Repositories.Books;
|
||||
using Lumina.DataAccess.Core.Repositories.Common.Factory;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
|
||||
+1
@@ -4,6 +4,7 @@ using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.DataAccess.Common.DependencyInjection;
|
||||
using Lumina.DataAccess.Core.Repositories.Common.Factory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -10,7 +10,10 @@ using Lumina.DataAccess.Core.UoW;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.UoW;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
Reference in new issue
Block a user