Replaces ErrorOr library with a custom implementation.

This commit is contained in:
BinaryAlley committed 2026-08-14 03:04:28 -07:00
1 parent 8fe90a4dde
commit 3b772d68ca
436 files changed
+4234 -3922

No files matched your search

@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -23,10 +23,10 @@ public class GenreDtoMappingTests
GenreDto genreDto = new("Rock");
// Act
ErrorOr<Genre> result = genreDto.ToDomainEntity();
Result<Genre> result = genreDto.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(genreDto.Name, result.Value.Name);
}
@@ -42,10 +42,10 @@ public class GenreDtoMappingTests
GenreDto genreDto = new(name);
// Act
ErrorOr<Genre> result = genreDto.ToDomainEntity();
Result<Genre> result = genreDto.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(genreDto.Name, result.Value.Name);
}
@@ -60,10 +60,10 @@ public class GenreDtoMappingTests
GenreDto genreDto = new(invalidName);
// Act
ErrorOr<Genre> result = genreDto.ToDomainEntity();
Result<Genre> result = genreDto.ToDomainEntity();
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
}
[Fact]
@@ -79,16 +79,16 @@ public class GenreDtoMappingTests
];
// Act
IEnumerable<ErrorOr<Genre>> results = genreDtos.ToDomainEntities();
IEnumerable<Result<Genre>> results = genreDtos.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(genreDtos.Count, results.Count());
List<ErrorOr<Genre>> resultList = results.ToList();
List<Result<Genre>> resultList = results.ToList();
for (int i = 0; i < genreDtos.Count; i++)
{
Assert.False(resultList[i].IsError);
Assert.False(resultList[i].IsFailure);
Assert.Equal(genreDtos[i].Name, resultList[i].Value.Name);
}
}
@@ -106,21 +106,21 @@ public class GenreDtoMappingTests
];
// Act
IEnumerable<ErrorOr<Genre>> results = genreDtos.ToDomainEntities();
IEnumerable<Result<Genre>> results = genreDtos.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(genreDtos.Count, results.Count());
List<ErrorOr<Genre>> resultList = results.ToList();
Assert.False(resultList[0].IsError);
List<Result<Genre>> resultList = results.ToList();
Assert.False(resultList[0].IsFailure);
Assert.Equal("Rock", resultList[0].Value.Name);
Assert.True(resultList[1].IsError);
Assert.True(resultList[1].IsFailure);
Assert.False(resultList[2].IsError);
Assert.False(resultList[2].IsFailure);
Assert.Equal("Jazz", resultList[2].Value.Name);
Assert.True(resultList[3].IsError);
Assert.True(resultList[3].IsFailure);
}
}
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
@@ -73,10 +73,10 @@ public class GenreEntityMappingTests
GenreEntity entity = new("Fiction");
// Act
ErrorOr<Genre> result = entity.ToDomainEntity();
Result<Genre> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(entity.Name, result.Value.Name);
}
@@ -91,10 +91,10 @@ public class GenreEntityMappingTests
GenreEntity entity = new(invalidName);
// Act
ErrorOr<Genre> result = entity.ToDomainEntity();
Result<Genre> result = entity.ToDomainEntity();
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Metadata.GenreNameCannotBeEmpty, result.FirstError);
}
@@ -111,16 +111,16 @@ public class GenreEntityMappingTests
];
// Act
IEnumerable<ErrorOr<Genre>> results = entities.ToDomainEntities();
IEnumerable<Result<Genre>> results = entities.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
List<ErrorOr<Genre>> resultList = results.ToList();
List<Result<Genre>> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
Assert.False(resultList[i].IsError);
Assert.False(resultList[i].IsFailure);
Assert.Equal(entities[i].Name, resultList[i].Value.Name);
}
}
@@ -146,8 +146,6 @@ public class GenreEntityMappingTests
List<GenreDto> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
Assert.Equal(entities[i].Name, resultList[i].Name);
}
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -20,8 +20,8 @@ public class GenreMappingTests
public void ToRepositoryEntity_WhenMappingGenre_ShouldMapCorrectly()
{
// Arrange
ErrorOr<Genre> createResult = Genre.Create("Rock");
Assert.False(createResult.IsError);
Result<Genre> createResult = Genre.Create("Rock");
Assert.False(createResult.IsFailure);
Genre genre = createResult.Value;
// Act
@@ -40,8 +40,8 @@ public class GenreMappingTests
public void ToRepositoryEntity_WhenMappingDifferentGenres_ShouldMapCorrectly(string name)
{
// Arrange
ErrorOr<Genre> createResult = Genre.Create(name);
Assert.False(createResult.IsError);
Result<Genre> createResult = Genre.Create(name);
Assert.False(createResult.IsFailure);
Genre genre = createResult.Value;
// Act
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -23,10 +23,10 @@ public class TagDtoMappingTests
TagDto tagDto = new("indie");
// Act
ErrorOr<Tag> result = tagDto.ToDomainEntity();
Result<Tag> result = tagDto.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(tagDto.Name, result.Value.Name);
}
@@ -43,10 +43,10 @@ public class TagDtoMappingTests
TagDto tagDto = new(name);
// Act
ErrorOr<Tag> result = tagDto.ToDomainEntity();
Result<Tag> result = tagDto.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(tagDto.Name, result.Value.Name);
}
@@ -61,10 +61,10 @@ public class TagDtoMappingTests
TagDto tagDto = new(invalidName);
// Act
ErrorOr<Tag> result = tagDto.ToDomainEntity();
Result<Tag> result = tagDto.ToDomainEntity();
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
}
[Fact]
@@ -80,16 +80,16 @@ public class TagDtoMappingTests
];
// Act
IEnumerable<ErrorOr<Tag>> results = tagDtos.ToDomainEntities();
IEnumerable<Result<Tag>> results = tagDtos.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(tagDtos.Count, results.Count());
List<ErrorOr<Tag>> resultList = results.ToList();
List<Result<Tag>> resultList = [.. results];
for (int i = 0; i < tagDtos.Count; i++)
{
Assert.False(resultList[i].IsError);
Assert.False(resultList[i].IsFailure);
Assert.Equal(tagDtos[i].Name, resultList[i].Value.Name);
}
}
@@ -107,21 +107,21 @@ public class TagDtoMappingTests
];
// Act
IEnumerable<ErrorOr<Tag>> results = tagDtos.ToDomainEntities();
IEnumerable<Result<Tag>> results = tagDtos.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(tagDtos.Count, results.Count());
List<ErrorOr<Tag>> resultList = results.ToList();
Assert.False(resultList[0].IsError);
List<Result<Tag>> resultList = [.. results];
Assert.False(resultList[0].IsFailure);
Assert.Equal("indie", resultList[0].Value.Name);
Assert.True(resultList[1].IsError);
Assert.True(resultList[1].IsFailure);
Assert.False(resultList[2].IsError);
Assert.False(resultList[2].IsFailure);
Assert.Equal("electronic", resultList[2].Value.Name);
Assert.True(resultList[3].IsError);
Assert.True(resultList[3].IsFailure);
}
}
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
@@ -73,10 +73,10 @@ public class TagEntityMappingTests
TagEntity entity = new("Fantasy");
// Act
ErrorOr<Tag> result = entity.ToDomainEntity();
Result<Tag> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(entity.Name, result.Value.Name);
}
@@ -91,10 +91,10 @@ public class TagEntityMappingTests
TagEntity entity = new(invalidName);
// Act
ErrorOr<Tag> result = entity.ToDomainEntity();
Result<Tag> result = entity.ToDomainEntity();
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Metadata.TagNameCannotBeEmpty, result.FirstError);
}
@@ -111,16 +111,16 @@ public class TagEntityMappingTests
];
// Act
IEnumerable<ErrorOr<Tag>> results = entities.ToDomainEntities();
IEnumerable<Result<Tag>> results = entities.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
List<ErrorOr<Tag>> resultList = results.ToList();
List<Result<Tag>> resultList = [.. results];
for (int i = 0; i < entities.Count; i++)
{
Assert.False(resultList[i].IsError);
Assert.False(resultList[i].IsFailure);
Assert.Equal(entities[i].Name, resultList[i].Value.Name);
}
}
@@ -144,7 +144,7 @@ public class TagEntityMappingTests
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
List<TagDto> resultList = results.ToList();
List<TagDto> resultList = [.. results];
for (int i = 0; i < entities.Count; i++)
Assert.Equal(entities[i].Name, resultList[i].Name);
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -20,8 +20,8 @@ public class TagMappingTests
public void ToRepositoryEntity_WhenMappingTag_ShouldMapCorrectly()
{
// Arrange
ErrorOr<Tag> createResult = Tag.Create("indie");
Assert.False(createResult.IsError);
Result<Tag> createResult = Tag.Create("indie");
Assert.False(createResult.IsFailure);
Tag tag = createResult.Value;
// Act
@@ -41,8 +41,8 @@ public class TagMappingTests
public void ToRepositoryEntity_WhenMappingDifferentTags_ShouldMapCorrectly(string name)
{
// Arrange
ErrorOr<Tag> createResult = Tag.Create(name);
Assert.False(createResult.IsError);
Result<Tag> createResult = Tag.Create(name);
Assert.False(createResult.IsFailure);
Tag tag = createResult.Value;
// Act
@@ -72,7 +72,7 @@ public class TagMappingTests
// Assert
Assert.NotNull(results);
Assert.Equal(tags.Count, results.Count());
List<TagEntity> resultList = results.ToList();
List<TagEntity> resultList = [.. results];
for (int i = 0; i < tags.Count; i++)
Assert.Equal(tags[i].Name, resultList[i].Name);
}
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Mapping.FileSystemManagement.Common;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -33,10 +33,10 @@ public class FileSystemTreeNodeResponseMappingTests
FileSystemTreeNodeResponse response = _fileSystemTreeNodeResponseFixture.Create();
// Act
ErrorOr<WindowsRootItem> result = response.ToWindowsRootItem();
Result<WindowsRootItem> result = response.ToWindowsRootItem();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(response.Path, result.Value.Id.Path);
Assert.Equal(response.Name, result.Value.Name);
@@ -50,10 +50,10 @@ public class FileSystemTreeNodeResponseMappingTests
FileSystemTreeNodeResponse response = _fileSystemTreeNodeResponseFixture.Create();
// Act
ErrorOr<UnixRootItem> result = response.ToUnixRootItem();
Result<UnixRootItem> result = response.ToUnixRootItem();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -19,8 +19,8 @@ public class UnixRootItemMappingTests
public void ToTreeNodeResponse_WhenMappingUnixRootItem_ShouldMapCorrectly()
{
// Arrange
ErrorOr<UnixRootItem> createResult = UnixRootItem.Create();
Assert.False(createResult.IsError);
Result<UnixRootItem> createResult = UnixRootItem.Create();
Assert.False(createResult.IsFailure);
UnixRootItem domainModel = createResult.Value;
// Act
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -21,8 +21,8 @@ public class WindowsRootItemMappingTests
// Arrange
string path = "C:\\";
string name = "C:";
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create(path, name);
Assert.False(createResult.IsError);
Result<WindowsRootItem> createResult = WindowsRootItem.Create(path, name);
Assert.False(createResult.IsFailure);
WindowsRootItem domainModel = createResult.Value;
// Act
@@ -45,8 +45,8 @@ public class WindowsRootItemMappingTests
string path = "D:\\";
string name = "D:";
FileSystemItemStatus customStatus = FileSystemItemStatus.Inaccessible;
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create(path, name, customStatus);
Assert.False(createResult.IsError);
Result<WindowsRootItem> createResult = WindowsRootItem.Create(path, name, customStatus);
Assert.False(createResult.IsFailure);
WindowsRootItem domainModel = createResult.Value;
// Act
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -20,8 +20,8 @@ public class PathSegmentMappingTests
public void ToResponse_WhenMappingPathSegment_ShouldMapCorrectly()
{
// Arrange
ErrorOr<PathSegment> createResult = PathSegment.Create("TestSegment", true, false);
Assert.False(createResult.IsError);
Result<PathSegment> createResult = PathSegment.Create("TestSegment", true, false);
Assert.False(createResult.IsFailure);
PathSegment pathSegment = createResult.Value;
// Act
@@ -39,8 +39,8 @@ public class PathSegmentMappingTests
public void ToResponse_WhenMappingDifferentPathSegmentTypes_ShouldMapCorrectly(string name, bool isDirectory, bool isDrive)
{
// Arrange
ErrorOr<PathSegment> createResult = PathSegment.Create(name, isDirectory, isDrive);
Assert.False(createResult.IsError);
Result<PathSegment> createResult = PathSegment.Create(name, isDirectory, isDrive);
Assert.False(createResult.IsFailure);
PathSegment pathSegment = createResult.Value;
// Act
@@ -69,7 +69,7 @@ public class PathSegmentMappingTests
// Assert
Assert.NotNull(results);
Assert.Equal(pathSegments.Count, results.Count());
List<PathSegmentResponse> resultList = results.ToList();
List<PathSegmentResponse> resultList = [.. results];
for (int i = 0; i < pathSegments.Count; i++)
Assert.Equal(pathSegments[i].Name, resultList[i].Path);
}
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -25,7 +25,7 @@ public class LibraryMappingTests
public void ToRepositoryEntity_WhenMappingValidLibrary_ShouldMapCorrectly()
{
// Arrange
ErrorOr<Library> libraryResult = Library.Create(
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Test Library",
LibraryType.Book,
@@ -64,7 +64,7 @@ public class LibraryMappingTests
public void ToRepositoryEntity_WhenMappingLibraryWithEmptyContentLocations_ShouldMapCorrectly()
{
// Arrange
ErrorOr<Library> libraryResult = Library.Create(
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Empty Library",
LibraryType.Book,
@@ -96,7 +96,7 @@ public class LibraryMappingTests
public void ToRepositoryEntity_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
{
// Arrange
ErrorOr<Library> libraryResult = Library.Create(
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Test Library",
libraryType,
@@ -136,7 +136,7 @@ public class LibraryMappingTests
"F:/Reading Material"
];
ErrorOr<Library> libraryResult = Library.Create(
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Test Library",
LibraryType.Book,
@@ -170,7 +170,7 @@ public class LibraryMappingTests
"D:/Books"
];
ErrorOr<Library> libraryResult = Library.Create(
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Test Library",
LibraryType.Book,
@@ -204,7 +204,7 @@ public class LibraryMappingTests
"D:/Books"
];
ErrorOr<Library> libraryResult = Library.Create(
Result<Library> libraryResult = Library.Create(
UserId.CreateUnique(),
"Test Library",
LibraryType.Book,
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -37,10 +37,10 @@ public class BookEntityMappingTests
BookEntity bookEntity = _bookEntityFixture.CreateBook();
// Act
ErrorOr<Book> result = bookEntity.ToDomainEntity();
Result<Book> result = bookEntity.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(bookEntity.Id, result.Value.Id.Value);
Assert.Equal(bookEntity.Title, result.Value.Metadata.Title);
@@ -325,12 +325,12 @@ public class BookEntityMappingTests
];
// Act
IEnumerable<ErrorOr<Book>> results = bookEntities.ToDomainEntities();
IEnumerable<Result<Book>> results = bookEntities.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(bookEntities.Count, results.Count());
Assert.All(results, result => Assert.False(result.IsError));
Assert.All(results, result => Assert.False(result.IsFailure));
}
[Fact]
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
@@ -26,10 +26,10 @@ public class BookMetadataDtoMappingTests
BookMetadataDto metadata = CreateBookMetadata("The Fellowship of the Ring", "3");
// Act
ErrorOr<Success> result = book.ApplyMetadata(metadata, "Goodreads", DateTime.UtcNow);
Result<Success> result = book.ApplyMetadata(metadata, "Goodreads", DateTime.UtcNow);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal("The Fellowship of the Ring", book.Metadata.Title);
Assert.Equal("3", book.GoodreadsId.Value);
Assert.Equal("The first part of J.R.R. Tolkien's epic adventure.", book.Metadata.Description.Value);
@@ -51,10 +51,10 @@ public class BookMetadataDtoMappingTests
};
// Act
ErrorOr<Success> result = book.ApplyMetadata(metadata, "Goodreads", DateTime.UtcNow);
Result<Success> result = book.ApplyMetadata(metadata, "Goodreads", DateTime.UtcNow);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(MetadataStatus.Pending, book.MetadataStatus);
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -35,10 +35,10 @@ public class BookRatingDtoMappingTests
BookRatingDto dto = _bookRatingDtoFixture.CreateComplete();
// Act
ErrorOr<BookRating> result = dto.ToDomainEntity();
Result<BookRating> result = dto.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(dto.Value!.Value, result.Value.Value);
Assert.Equal(dto.MaxValue!.Value, result.Value.MaxValue);
@@ -67,10 +67,10 @@ public class BookRatingDtoMappingTests
BookRatingDto dto = _bookRatingDtoFixture.CreateMinimal();
// Act
ErrorOr<BookRating> result = dto.ToDomainEntity();
Result<BookRating> result = dto.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(dto.Value!.Value, result.Value.Value);
Assert.Equal(dto.MaxValue!.Value, result.Value.MaxValue);
@@ -85,10 +85,10 @@ public class BookRatingDtoMappingTests
BookRatingDto dto = _bookRatingDtoFixture.CreateInvalid();
// Act
ErrorOr<BookRating> result = dto.ToDomainEntity();
Result<BookRating> result = dto.ToDomainEntity();
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
}
[Fact]
@@ -102,15 +102,15 @@ public class BookRatingDtoMappingTests
];
// Act
IEnumerable<ErrorOr<BookRating>> results = dtos.ToDomainEntities();
IEnumerable<Result<BookRating>> results = dtos.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(dtos.Count, results.Count());
List<ErrorOr<BookRating>> resultList = results.ToList();
foreach (ErrorOr<BookRating> result in resultList)
Assert.False(result.IsError);
List<Result<BookRating>> resultList = [.. results];
foreach (Result<BookRating> result in resultList)
Assert.False(result.IsFailure);
// complete rating
Assert.Equal(dtos[0].Value!.Value, resultList[0].Value.Value);
@@ -137,16 +137,16 @@ public class BookRatingDtoMappingTests
];
// Act
IEnumerable<ErrorOr<BookRating>> results = dtos.ToDomainEntities();
IEnumerable<Result<BookRating>> results = dtos.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(dtos.Count, results.Count());
List<ErrorOr<BookRating>> resultList = results.ToList();
List<Result<BookRating>> resultList = [.. results];
Assert.False(resultList[0].IsError);
Assert.True(resultList[1].IsError);
Assert.False(resultList[2].IsError);
Assert.False(resultList[0].IsFailure);
Assert.True(resultList[1].IsFailure);
Assert.False(resultList[2].IsFailure);
}
}
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -95,10 +95,10 @@ public class BookRatingEntityMappingTests
BookRatingEntity entity = _fixture.CreateBookRating();
// Act
ErrorOr<BookRating> result = entity.ToDomainEntity();
Result<BookRating> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(entity.Value, result.Value.Value);
Assert.Equal(entity.MaxValue, result.Value.MaxValue);
@@ -113,10 +113,10 @@ public class BookRatingEntityMappingTests
BookRatingEntity entity = _fixture.CreateInvalidBookRating();
// Act
ErrorOr<BookRating> result = entity.ToDomainEntity();
Result<BookRating> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(default, result.Value.Value);
Assert.Equal(default, result.Value.MaxValue);
@@ -135,14 +135,14 @@ public class BookRatingEntityMappingTests
];
// Act
IEnumerable<ErrorOr<BookRating>> results = entities.ToDomainEntities();
IEnumerable<Result<BookRating>> results = entities.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
foreach (ErrorOr<BookRating> result in results)
foreach (Result<BookRating> result in results)
{
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.InRange(result.Value.Value, 1, 5);
Assert.Equal(5, result.Value.MaxValue);
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -36,10 +36,10 @@ public class IsbnDtoMappingTests
IsbnDto dto = _isbnDtoFixture.CreateIsbn10();
// Act
ErrorOr<Isbn> result = dto.ToDomainEntity();
Result<Isbn> result = dto.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(dto.Value, result.Value.Value);
Assert.Equal(dto.Format!.Value, result.Value.Format);
@@ -52,10 +52,10 @@ public class IsbnDtoMappingTests
IsbnDto dto = _isbnDtoFixture.CreateIsbn13();
// Act
ErrorOr<Isbn> result = dto.ToDomainEntity();
Result<Isbn> result = dto.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(dto.Value, result.Value.Value);
Assert.Equal(dto.Format!.Value, result.Value.Format);
@@ -68,10 +68,10 @@ public class IsbnDtoMappingTests
IsbnDto dto = _isbnDtoFixture.CreateWithoutFormat();
// Act
ErrorOr<Isbn> result = dto.ToDomainEntity();
Result<Isbn> result = dto.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(dto.Value, result.Value.Value);
Assert.Equal(IsbnFormat.Isbn13, result.Value.Format); // default format
@@ -84,10 +84,10 @@ public class IsbnDtoMappingTests
IsbnDto dto = _isbnDtoFixture.CreateInvalid();
// Act
ErrorOr<Isbn> result = dto.ToDomainEntity();
Result<Isbn> result = dto.ToDomainEntity();
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
}
[Fact]
@@ -102,14 +102,14 @@ public class IsbnDtoMappingTests
];
// Act
IEnumerable<ErrorOr<Isbn>> results = dtos.ToDomainEntities();
IEnumerable<Result<Isbn>> results = dtos.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(dtos.Count, results.Count());
List<ErrorOr<Isbn>> resultList = results.ToList();
Assert.All(resultList, result => Assert.False(result.IsError));
List<Result<Isbn>> resultList = [.. results];
Assert.All(resultList, result => Assert.False(result.IsFailure));
Assert.Equal(dtos[0].Value, resultList[0].Value.Value);
Assert.Equal(dtos[0].Format!.Value, resultList[0].Value.Format);
@@ -133,20 +133,20 @@ public class IsbnDtoMappingTests
];
// Act
IEnumerable<ErrorOr<Isbn>> results = dtos.ToDomainEntities();
IEnumerable<Result<Isbn>> results = dtos.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(dtos.Count, results.Count());
List<ErrorOr<Isbn>> resultList = results.ToList();
List<Result<Isbn>> resultList = [.. results];
Assert.False(resultList[0].IsError);
Assert.False(resultList[0].IsFailure);
Assert.Equal(dtos[0].Value, resultList[0].Value.Value);
Assert.True(resultList[1].IsError);
Assert.True(resultList[1].IsFailure);
Assert.False(resultList[2].IsError);
Assert.False(resultList[2].IsFailure);
Assert.Equal(dtos[2].Value, resultList[2].Value.Value);
}
}
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -75,10 +75,10 @@ public class IsbnEntityMappingTests
IsbnEntity entity = new("0-7475-3269-9", IsbnFormat.Isbn10);
// Act
ErrorOr<Isbn> result = entity.ToDomainEntity();
Result<Isbn> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(entity.Value, result.Value.Value);
Assert.Equal(entity.Format, result.Value.Format);
@@ -94,10 +94,10 @@ public class IsbnEntityMappingTests
IsbnEntity entity = new(invalidValue, null);
// Act
ErrorOr<Isbn> result = entity.ToDomainEntity();
Result<Isbn> result = entity.ToDomainEntity();
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
}
[Fact]
@@ -111,16 +111,16 @@ public class IsbnEntityMappingTests
];
// Act
IEnumerable<ErrorOr<Isbn>> results = entities.ToDomainEntities();
IEnumerable<Result<Isbn>> results = entities.ToDomainEntities();
// Assert
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
List<ErrorOr<Isbn>> resultList = results.ToList();
List<Result<Isbn>> resultList = [.. results];
for (int i = 0; i < entities.Count; i++)
{
Assert.False(resultList[i].IsError);
Assert.False(resultList[i].IsFailure);
Assert.Equal(entities[i].Value, resultList[i].Value.Value);
Assert.Equal(entities[i].Format, resultList[i].Value.Format);
}
@@ -143,7 +143,7 @@ public class IsbnEntityMappingTests
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
List<IsbnDto> resultList = results.ToList();
List<IsbnDto> resultList = [.. results];
for (int i = 0; i < entities.Count; i++)
{
Assert.Equal(entities[i].Value, resultList[i].Value);
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
#endregion
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -8,6 +7,7 @@ using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Core.Admin.Authorization.Permissions.Queries.GetPermissions;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using NSubstitute;
using System;
@@ -67,13 +67,13 @@ public class GetPermissionsQueryHandlerTests
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
.Returns(true);
_mockPermissionRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(permissions));
.Returns(Result.From(permissions));
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(2, result.Value.Count());
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
await _mockPermissionRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
@@ -89,10 +89,10 @@ public class GetPermissionsQueryHandlerTests
.Returns(false);
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
await _mockPermissionRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
@@ -111,10 +111,10 @@ public class GetPermissionsQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
await _mockPermissionRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
@@ -134,13 +134,13 @@ public class GetPermissionsQueryHandlerTests
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
.Returns(true);
_mockPermissionRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(permissions));
.Returns(Result.From(permissions));
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, cancellationToken);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, cancellationToken);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Single(result.Value);
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
await _mockPermissionRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -10,6 +9,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
using Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Commands.AddRole.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using NSubstitute;
using System;
@@ -69,10 +69,10 @@ public class AddRoleCommandHandlerTests
.Returns(false);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockRoleRepository.DidNotReceive().InsertAsync(Arg.Any<RoleEntity>(), Arg.Any<CancellationToken>());
}
@@ -90,10 +90,10 @@ public class AddRoleCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -113,10 +113,10 @@ public class AddRoleCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -134,10 +134,10 @@ public class AddRoleCommandHandlerTests
.Returns((RoleEntity?)null);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Persistence.ErrorPersistingAuthorizationRole, result.FirstError);
}
@@ -172,10 +172,10 @@ public class AddRoleCommandHandlerTests
.Returns(role);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(command.RoleName, result.Value.Role.RoleName);
Assert.Equal(command.Permissions.Count, result.Value.Permissions.Length);
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Commands.AddRole.Fixtures;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -9,6 +8,7 @@ using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
using Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Commands.DeleteRole.Fixtures;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -66,10 +66,10 @@ public class DeleteRoleCommandHandlerTests
.Returns(false);
// Act
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockRoleRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -86,10 +86,10 @@ public class DeleteRoleCommandHandlerTests
.Returns((RoleEntity?)null);
// Act
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
await _mockRoleRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -107,10 +107,10 @@ public class DeleteRoleCommandHandlerTests
.Returns(adminRole);
// Act
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.AdminRoleCannotBeDeleted, result.FirstError);
await _mockRoleRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -128,10 +128,10 @@ public class DeleteRoleCommandHandlerTests
.Returns(error);
// Act
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockRoleRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -152,10 +152,10 @@ public class DeleteRoleCommandHandlerTests
.Returns(error);
// Act
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -175,10 +175,10 @@ public class DeleteRoleCommandHandlerTests
.Returns(Result.Deleted);
// Act
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
}
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -10,6 +9,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
using Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Commands.UpdateRole.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using NSubstitute;
using System;
@@ -69,10 +69,10 @@ public class UpdateRoleCommandHandlerTests
.Returns(false);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockRoleRepository.DidNotReceive().UpdateAsync(Arg.Any<RoleEntity>(), Arg.Any<CancellationToken>());
}
@@ -90,10 +90,10 @@ public class UpdateRoleCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -113,10 +113,10 @@ public class UpdateRoleCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -134,10 +134,10 @@ public class UpdateRoleCommandHandlerTests
.Returns((RoleEntity?)null);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Persistence.ErrorPersistingAuthorizationRole, result.FirstError);
}
@@ -171,10 +171,10 @@ public class UpdateRoleCommandHandlerTests
.Returns(role);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(command.RoleName, result.Value.Role.RoleName);
Assert.Equal(command.Permissions.Count, result.Value.Permissions.Length);
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Commands.UpdateRole.Fixtures;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -10,6 +9,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
using Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Queries.GetRolePermissions.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using NSubstitute;
using System;
@@ -68,10 +68,10 @@ public class GetRolePermissionsQueryHandlerTests
.Returns(false);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockRoleRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -89,10 +89,10 @@ public class GetRolePermissionsQueryHandlerTests
.Returns(error);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -108,10 +108,10 @@ public class GetRolePermissionsQueryHandlerTests
.Returns((RoleEntity?)null);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
}
@@ -146,10 +146,10 @@ public class GetRolePermissionsQueryHandlerTests
.Returns(role);
// Act
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RolePermissionsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(role.RoleName, result.Value.Role.RoleName);
Assert.Single(result.Value.Permissions);
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -9,6 +8,7 @@ using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
using Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Queries.GetRoles.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -63,10 +63,10 @@ public class GetRolesQueryHandlerTests
.Returns(false);
// Act
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<RoleResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockRoleRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -84,10 +84,10 @@ public class GetRolesQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<RoleResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -105,13 +105,13 @@ public class GetRolesQueryHandlerTests
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
.Returns(true);
_mockRoleRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(roles));
.Returns(Result.From(roles));
// Act
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<RoleResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(2, result.Value.Count());
}
}
@@ -1,10 +1,9 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -54,9 +53,9 @@ public class DirectoryFixture
dateModified ??= Optional<DateTime>.Some(_faker.Date.Recent());
status ??= _faker.PickRandom<FileSystemItemStatus>();
ErrorOr<Directory> directoryResult = Directory.Create(path, name, dateCreated.Value, dateModified.Value, status.Value);
Result<Directory> directoryResult = Directory.Create(path, name, dateCreated.Value, dateModified.Value, status.Value);
if (directoryResult.IsError)
if (directoryResult.IsFailure)
throw new InvalidOperationException("Failed to create Directory: " + string.Join(", ", directoryResult.Errors));
Directory directory = directoryResult.Value;
@@ -73,7 +72,7 @@ public class DirectoryFixture
/// <returns>The created list.</returns>
public List<Directory> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => CreateDirectory()).ToList();
return [.. Enumerable.Range(0, count).Select(_ => CreateDirectory())];
}
/// <summary>
@@ -85,7 +84,7 @@ public class DirectoryFixture
/// <returns>A list of <see cref="Directory"/> objects with nested structures.</returns>
public List<Directory> CreateManyNested(int count = 3, int maxDepth = 3, int maxChildrenPerDirectory = 3)
{
return Enumerable.Range(0, count).Select(_ => CreateNestedDirectory(1, maxDepth, maxChildrenPerDirectory)).ToList();
return [.. Enumerable.Range(0, count).Select(_ => CreateNestedDirectory(1, maxDepth, maxChildrenPerDirectory))];
}
/// <summary>
@@ -106,8 +105,8 @@ public class DirectoryFixture
for (int i = 0; i < childCount; i++)
{
Directory childDirectory = CreateNestedDirectory(currentDepth + 1, maxDepth, maxChildrenPerDirectory);
ErrorOr<Updated> addResult = childDirectory.SetParent(childDirectory);
if (!addResult.IsError)
Result<Updated> addResult = childDirectory.SetParent(childDirectory);
if (!addResult.IsFailure)
childItems.Add(childDirectory);
}
}
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -54,18 +54,18 @@ public class GetDirectoriesQueryHandlerTests
IEnumerable<Directory> directories = _directoryFixture.CreateMany();
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements)
.Returns(ErrorOrFactory.From(directories));
.Returns(Result.From(directories));
// Act
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(getDirectoriesQuery, CancellationToken.None);
Result<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(getDirectoriesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsAssignableFrom<IEnumerable<DirectoryResponse>>(result.Value);
Assert.Equal(directories.Count(), result.Value.Count());
List<DirectoryResponse> resultList = result.Value.ToList();
List<Directory> directoriesList = directories.ToList();
List<DirectoryResponse> resultList = [.. result.Value];
List<Directory> directoriesList = [.. directories];
for (int i = 0; i < resultList.Count; i++)
{
@@ -88,18 +88,18 @@ public class GetDirectoriesQueryHandlerTests
IEnumerable<Directory> directories = _directoryFixture.CreateMany();
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements)
.Returns(ErrorOrFactory.From(directories));
.Returns(Result.From(directories));
// Act
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(getDirectoriesQuery, CancellationToken.None);
Result<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(getDirectoriesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsAssignableFrom<IEnumerable<DirectoryResponse>>(result.Value);
Assert.Equal(directories.Count(), result.Value.Count());
List<DirectoryResponse> resultList = result.Value.ToList();
List<Directory> directoriesList = directories.ToList();
List<DirectoryResponse> resultList = [.. result.Value];
List<Directory> directoriesList = [.. directories];
for (int i = 0; i < resultList.Count; i++)
{
@@ -123,10 +123,10 @@ public class GetDirectoriesQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
_mockDirectoryService.Received(1).GetSubdirectories(query.Path!, query.IncludeHiddenElements);
}
@@ -136,15 +136,15 @@ public class GetDirectoriesQueryHandlerTests
{
// Arrange
GetDirectoriesQuery query = _fixture.Create<GetDirectoriesQuery>();
ErrorOr<IEnumerable<Directory>> emptyList = ErrorOrFactory.From(Enumerable.Empty<Directory>());
Result<IEnumerable<Directory>> emptyList = Result.From(Enumerable.Empty<Directory>());
_mockDirectoryService.GetSubdirectories(query.Path!, query.IncludeHiddenElements)
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Empty(result.Value);
_mockDirectoryService.Received(1).GetSubdirectories(query.Path!, query.IncludeHiddenElements);
}
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories;
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using NSubstitute;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -51,18 +51,18 @@ public class GetDrivesQueryHandlerTests
];
_mockDriveService.GetDrives()
.Returns(ErrorOrFactory.From(drives));
.Returns(Result.From(drives));
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getDrivesQuery, CancellationToken.None);
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getDrivesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsAssignableFrom<IEnumerable<FileSystemTreeNodeResponse>>(result.Value);
Assert.Equal(drives.Count(), result.Value.Count());
List<FileSystemTreeNodeResponse> resultList = result.Value.ToList();
List<FileSystemItem> drivesList = drives.ToList();
List<FileSystemTreeNodeResponse> resultList = [.. result.Value];
List<FileSystemItem> drivesList = [.. drives];
for (int i = 0; i < resultList.Count; i++)
{
@@ -90,10 +90,10 @@ public class GetDrivesQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
_mockDriveService.Received(1).GetDrives();
}
@@ -103,15 +103,15 @@ public class GetDrivesQueryHandlerTests
{
// Arrange
GetDrivesQuery query = _fixture.Create<GetDrivesQuery>();
ErrorOr<IEnumerable<FileSystemItem>> emptyList = ErrorOrFactory.From(Enumerable.Empty<FileSystemItem>());
Result<IEnumerable<FileSystemItem>> emptyList = Result.From(Enumerable.Empty<FileSystemItem>());
_mockDriveService.GetDrives()
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Empty(result.Value);
_mockDriveService.Received(1).GetDrives();
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -23,10 +23,10 @@ public class UnixRootItemFixture
/// <returns>The created <see cref="UnixRootItem"/>.</returns>
public UnixRootItem Create()
{
ErrorOr<UnixRootItem> unixRootItemResult = UnixRootItem.Create(
Result<UnixRootItem> unixRootItemResult = UnixRootItem.Create(
_faker.PickRandom<FileSystemItemStatus>()
);
if (unixRootItemResult.IsError)
if (unixRootItemResult.IsFailure)
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", unixRootItemResult.Errors));
return unixRootItemResult.Value;
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -23,12 +23,12 @@ public class WindowsRootItemFixture
/// <returns>The created <see cref="WindowsRootItem"/>.</returns>
public WindowsRootItem Create()
{
ErrorOr<WindowsRootItem> windowsRootItemResult = WindowsRootItem.Create(
Result<WindowsRootItem> windowsRootItemResult = WindowsRootItem.Create(
_faker.System.FilePath(),
_faker.System.FileName(),
_faker.PickRandom<FileSystemItemStatus>()
);
if (windowsRootItemResult.IsError)
if (windowsRootItemResult.IsFailure)
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", windowsRootItemResult.Errors));
return windowsRootItemResult.Value;
}
@@ -1,9 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -47,9 +46,9 @@ public class FileFixture
size ??= _faker.Random.Long();
status ??= _faker.PickRandom<FileSystemItemStatus>();
ErrorOr<File> fileResult = File.Create(path, name, dateCreated.Value, dateModified.Value, size.Value, status.Value);
Result<File> fileResult = File.Create(path, name, dateCreated.Value, dateModified.Value, size.Value, status.Value);
if (fileResult.IsError)
if (fileResult.IsFailure)
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", fileResult.Errors));
return fileResult.Value;
}
@@ -61,7 +60,7 @@ public class FileFixture
/// <returns>The created list.</returns>
public List<File> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => CreateFile()).ToList();
return [.. Enumerable.Range(0, count).Select(_ => CreateFile())];
}
/// <summary>
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Files;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -54,18 +54,18 @@ public class GetFilesQueryHandlerTests
IEnumerable<File> files = _fileFixture.CreateMany();
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements)
.Returns(ErrorOrFactory.From(files));
.Returns(Result.From(files));
// Act
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
Result<IEnumerable<FileResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsAssignableFrom<IEnumerable<FileResponse>>(result.Value);
Assert.Equal(files.Count(), result.Value.Count());
List<FileResponse> resultList = result.Value.ToList();
List<File> filesList = files.ToList();
List<FileResponse> resultList = [.. result.Value];
List<File> filesList = [.. files];
for (int i = 0; i < resultList.Count; i++)
{
@@ -88,18 +88,18 @@ public class GetFilesQueryHandlerTests
IEnumerable<File> files = _fileFixture.CreateMany();
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements)
.Returns(ErrorOrFactory.From(files));
.Returns(Result.From(files));
// Act
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
Result<IEnumerable<FileResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsAssignableFrom<IEnumerable<FileResponse>>(result.Value);
Assert.Equal(files.Count(), result.Value.Count());
List<FileResponse> resultList = result.Value.ToList();
List<File> filesList = files.ToList();
List<FileResponse> resultList = [.. result.Value];
List<File> filesList = [.. files];
for (int i = 0; i < resultList.Count; i++)
{
@@ -123,10 +123,10 @@ public class GetFilesQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<FileResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
}
@@ -136,15 +136,15 @@ public class GetFilesQueryHandlerTests
{
// Arrange
GetFilesQuery query = _fixture.Create<GetFilesQuery>();
ErrorOr<IEnumerable<File>> emptyList = ErrorOrFactory.From(Enumerable.Empty<File>());
Result<IEnumerable<File>> emptyList = Result.From(Enumerable.Empty<File>());
_mockFileService.GetFiles(query.Path!, query.IncludeHiddenElements)
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<FileResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Empty(result.Value);
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,15 +1,15 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles.Fixtures;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using NSubstitute;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -54,18 +54,18 @@ public class GetTreeFilesQueryHandlerTests
IEnumerable<File> files = _fileFixture.CreateMany();
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements)
.Returns(ErrorOrFactory.From(files));
.Returns(Result.From(files));
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsAssignableFrom<IEnumerable<FileSystemTreeNodeResponse>>(result.Value);
Assert.Equal(files.Count(), result.Value.Count());
List<FileSystemTreeNodeResponse> resultList = result.Value.ToList();
List<File> filesList = files.ToList();
List<FileSystemTreeNodeResponse> resultList = [.. result.Value];
List<File> filesList = [.. files];
for (int i = 0; i < resultList.Count; i++)
{
@@ -89,18 +89,18 @@ public class GetTreeFilesQueryHandlerTests
IEnumerable<File> files = _fileFixture.CreateMany();
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements)
.Returns(ErrorOrFactory.From(files));
.Returns(Result.From(files));
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsAssignableFrom<IEnumerable<FileSystemTreeNodeResponse>>(result.Value);
Assert.Equal(files.Count(), result.Value.Count());
List<FileSystemTreeNodeResponse> resultList = result.Value.ToList();
List<File> filesList = files.ToList();
List<FileSystemTreeNodeResponse> resultList = [.. result.Value];
List<File> filesList = [.. files];
for (int i = 0; i < resultList.Count; i++)
{
@@ -125,10 +125,10 @@ public class GetTreeFilesQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
}
@@ -138,15 +138,15 @@ public class GetTreeFilesQueryHandlerTests
{
// Arrange
GetTreeFilesQuery query = _fixture.Create<GetTreeFilesQuery>();
ErrorOr<IEnumerable<File>> emptyList = ErrorOrFactory.From(Enumerable.Empty<File>());
Result<IEnumerable<File>> emptyList = Result.From(Enumerable.Empty<File>());
_mockFileService.GetFiles(query.Path!, query.IncludeHiddenElements)
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Empty(result.Value);
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -33,9 +33,9 @@ public class FileSystemPathIdFixture
{
path ??= _faker.System.FilePath();
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
if (fileSystemPathIdResult.IsError)
if (fileSystemPathIdResult.IsFailure)
throw new InvalidOperationException("Failed to create FileSystemPathId: " + string.Join(", ", fileSystemPathIdResult.Errors));
return fileSystemPathIdResult.Value;
}
@@ -1,12 +1,12 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
@@ -46,13 +46,13 @@ public class CombinePathCommandHandlerTests
string combinedPath = System.IO.Path.Combine(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!);
_mockPathService.CombinePath(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!)
.Returns(ErrorOrFactory.From(combinedPath));
.Returns(Result.From(combinedPath));
// Act
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(combinePathCommand, CancellationToken.None);
Result<PathSegmentResponse> result = await _sut.HandleAsync(combinePathCommand, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsType<PathSegmentResponse>(result.Value);
Assert.Equal(combinedPath, result.Value.Path);
_mockPathService.Received(1).CombinePath(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!);
@@ -68,10 +68,10 @@ public class CombinePathCommandHandlerTests
.Returns(error);
// Act
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<PathSegmentResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
_mockPathService.Received(1).CombinePath(command.OriginalPath!, command.NewPath!);
}
@@ -82,13 +82,13 @@ public class CombinePathCommandHandlerTests
// Arrange
CombinePathCommand command = _fixture.Create<CombinePathCommand>();
_mockPathService.CombinePath(command.OriginalPath!, command.NewPath!)
.Returns(ErrorOrFactory.From(string.Empty));
.Returns(Result.From(string.Empty));
// Act
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<PathSegmentResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsType<PathSegmentResponse>(result.Value);
Assert.Empty(result.Value.Path);
_mockPathService.Received(1).CombinePath(command.OriginalPath!, command.NewPath!);
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -54,18 +54,18 @@ public class SplitPathCommandHandlerTests
IEnumerable<PathSegment> pathSegments = _pathSegmentFixture.CreateMany();
_mockPathService.ParsePath(splitPathCommand.Path!)
.Returns(ErrorOrFactory.From(pathSegments));
.Returns(Result.From(pathSegments));
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(splitPathCommand, CancellationToken.None);
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(splitPathCommand, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsAssignableFrom<IEnumerable<PathSegmentResponse>>(result.Value);
Assert.Equal(pathSegments.Count(), result.Value.Count());
List<PathSegmentResponse> resultList = result.Value.ToList();
List<PathSegment> segmentsList = pathSegments.ToList();
List<PathSegmentResponse> resultList = [.. result.Value];
List<PathSegment> segmentsList = [.. pathSegments];
for (int i = 0; i < resultList.Count; i++)
Assert.Equal(segmentsList[i].Name, resultList[i].Path);
@@ -82,10 +82,10 @@ public class SplitPathCommandHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
_mockPathService.Received(1).ParsePath(command.Path!);
}
@@ -95,15 +95,15 @@ public class SplitPathCommandHandlerTests
{
// Arrange
SplitPathCommand command = _fixture.Create<SplitPathCommand>();
ErrorOr<IEnumerable<PathSegment>> emptyList = ErrorOrFactory.From(Enumerable.Empty<PathSegment>());
Result<IEnumerable<PathSegment>> emptyList = Result.From(Enumerable.Empty<PathSegment>());
_mockPathService.ParsePath(command.Path!)
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Empty(result.Value);
_mockPathService.Received(1).ParsePath(command.Path!);
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using System;
using System.Collections.Generic;
@@ -39,9 +39,9 @@ public class PathSegmentFixture
isDirectory ??= true;
isDrive ??= false;
ErrorOr<PathSegment> pathResult = PathSegment.Create(name, isDirectory.Value, isDrive.Value);
Result<PathSegment> pathResult = PathSegment.Create(name, isDirectory.Value, isDrive.Value);
if (pathResult.IsError)
if (pathResult.IsFailure)
throw new InvalidOperationException("Failed to create PathSegment: " + string.Join(", ", pathResult.Errors));
return pathResult.Value;
}
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
@@ -42,10 +42,10 @@ public class CheckPathExistsQueryHandlerTests
_mockPathService.Exists(query.Path!).Returns(true);
// Act
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.True(result.Value.Exists);
_mockPathService.Received(1).Exists(query.Path!);
}
@@ -58,10 +58,10 @@ public class CheckPathExistsQueryHandlerTests
_mockPathService.Exists(query.Path!).Returns(true);
// Act
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.True(result.Value.Exists);
_mockPathService.Received(1).Exists(query.Path!);
}
@@ -74,10 +74,10 @@ public class CheckPathExistsQueryHandlerTests
_mockPathService.Exists(query.Path!, false).Returns(false);
// Act
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.False(result.Value.Exists);
_mockPathService.Received(1).Exists(query.Path!, false);
}
@@ -90,10 +90,10 @@ public class CheckPathExistsQueryHandlerTests
_mockPathService.Exists(query.Path!).Returns(false);
// Act
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.False(result.Value.Exists);
_mockPathService.Received(1).Exists(query.Path!);
}
@@ -106,10 +106,10 @@ public class CheckPathExistsQueryHandlerTests
_mockPathService.Exists(Arg.Any<string>(), Arg.Any<bool>()).Returns(false);
// Act
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.False(result.Value.Exists);
_mockPathService.Received(1).Exists(Arg.Any<string>(), Arg.Any<bool>());
}
@@ -123,10 +123,10 @@ public class CheckPathExistsQueryHandlerTests
CancellationToken cancellationToken = new(true);
// Act
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.True(result.Value.Exists);
_mockPathService.Received(1).Exists(query.Path!);
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -53,13 +53,13 @@ public class GetPathParentQueryHandlerTests
IEnumerable<PathSegmentResponse> pathSegmentResponses = pathSegments.Select(segment => new PathSegmentResponse(segment.Name));
_mockPathService.GoUpOneLevel(query.Path!)
.Returns(ErrorOrFactory.From(pathSegments));
.Returns(Result.From(pathSegments));
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsAssignableFrom<IEnumerable<PathSegmentResponse>>(result.Value);
Assert.Equal(pathSegmentResponses, result.Value);
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
@@ -75,10 +75,10 @@ public class GetPathParentQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
}
@@ -88,15 +88,15 @@ public class GetPathParentQueryHandlerTests
{
// Arrange
GetPathParentQuery query = _fixture.Create<GetPathParentQuery>();
ErrorOr<IEnumerable<PathSegment>> emptyList = ErrorOrFactory.From(Enumerable.Empty<PathSegment>());
Result<IEnumerable<PathSegment>> emptyList = Result.From(Enumerable.Empty<PathSegment>());
_mockPathService.GoUpOneLevel(query.Path!)
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Empty(result.Value);
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,12 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
@@ -46,13 +46,13 @@ public class GetPathRootQueryHandlerTests
PathSegment pathSegment = _pathSegmentFixture.CreatePathSegment(isDrive: true);
_mockPathService.GetPathRoot(query.Path!)
.Returns(ErrorOrFactory.From(pathSegment));
.Returns(Result.From(pathSegment));
// Act
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(pathSegment.Name, result.Value.Path);
_mockPathService.Received(1).GetPathRoot(query.Path!);
@@ -68,10 +68,10 @@ public class GetPathRootQueryHandlerTests
.Returns(error);
// Act
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
_mockPathService.Received(1).GetPathRoot(query.Path!);
}
@@ -84,13 +84,13 @@ public class GetPathRootQueryHandlerTests
PathSegment rootPathSegment = _pathSegmentFixture.CreatePathSegment(name: "/", isDirectory: true, isDrive: true);
_mockPathService.GetPathRoot(query.Path!)
.Returns(ErrorOrFactory.From(rootPathSegment));
.Returns(Result.From(rootPathSegment));
// Act
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal("/", result.Value.Path);
_mockPathService.Received(1).GetPathRoot(query.Path!);
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,13 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.SharedKernel.Common.Errors;
using NSubstitute;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
@@ -45,10 +44,10 @@ public class ValidatePathQueryHandlerTests
_mockPathService.IsValidPath(query.Path!).Returns(true);
// Act
ErrorOr<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.True(result.Value.IsValid);
_mockPathService.Received(1).IsValidPath(query.Path!);
}
@@ -61,10 +60,10 @@ public class ValidatePathQueryHandlerTests
_mockPathService.IsValidPath(query.Path!).Returns(false);
// Act
ErrorOr<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.False(result.Value.IsValid);
_mockPathService.Received(1).IsValidPath(query.Path!);
}
@@ -77,10 +76,10 @@ public class ValidatePathQueryHandlerTests
_mockPathService.IsValidPath(Arg.Any<string>()).Returns(false);
// Act
ErrorOr<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.False(result.Value.IsValid);
_mockPathService.Received(1).IsValidPath(Arg.Any<string>());
}
@@ -93,10 +92,10 @@ public class ValidatePathQueryHandlerTests
_mockPathService.IsValidPath(Arg.Any<string>()).Returns(false);
// Act
ErrorOr<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.False(result.Value.IsValid);
_mockPathService.Received(1).IsValidPath(Arg.Any<string>());
}
@@ -110,10 +109,10 @@ public class ValidatePathQueryHandlerTests
.Returns([Errors.FileSystemManagement.PathCannotBeEmpty]);
// Act
ErrorOr<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.FileSystemManagement.PathCannotBeEmpty, result.FirstError);
_mockPathService.DidNotReceive().IsValidPath(Arg.Any<string>());
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,12 +1,12 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
@@ -43,13 +43,13 @@ public class GetThumbnailQueryHandlerTests
Thumbnail thumbnail = _fixture.Create<Thumbnail>();
_mockThumbnailService.GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(thumbnail));
.Returns(Result.From(thumbnail));
// Act
ErrorOr<ThumbnailResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<ThumbnailResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(thumbnail.Type, result.Value.Type);
Assert.Equal(thumbnail.Bytes, result.Value.Bytes);
@@ -66,10 +66,10 @@ public class GetThumbnailQueryHandlerTests
.Returns(error);
// Act
ErrorOr<ThumbnailResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<ThumbnailResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>());
}
@@ -83,7 +83,7 @@ public class GetThumbnailQueryHandlerTests
cts.Cancel();
_mockThumbnailService.GetThumbnailAsync(query.Path!, query.Quality, cts.Token)
.Returns(Task.FromCanceled<ErrorOr<Thumbnail>>(cts.Token));
.Returns(Task.FromCanceled<Result<Thumbnail>>(cts.Token));
// Act & Assert
await Assert.ThrowsAsync<TaskCanceledException>(() => _sut.HandleAsync(query, cts.Token));
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.Seed;
@@ -13,6 +12,7 @@ using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplica
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Application.UnitTests.Core.Maintenance.ApplicationSetup.Commands.SetupApplication.Fixtures;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -80,17 +80,25 @@ public class SetupApplicationCommandHandlerTests
string hashedPassword = Uri.EscapeDataString("hashedPassword");
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<UserEntity>()));
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
_mockHashService.HashString(command.Password!)
.Returns(hashedPassword);
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(command.Username, result.Value.Username);
Assert.Null(result.Value.TotpSecret);
@@ -111,7 +119,7 @@ public class SetupApplicationCommandHandlerTests
string encryptedSecret = "encryptedSecret";
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<UserEntity>()));
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
_mockHashService.HashString(command.Password!)
.Returns(hashedPassword);
_mockTotpTokenGenerator.GenerateSecret()
@@ -122,12 +130,20 @@ public class SetupApplicationCommandHandlerTests
.Returns(encryptedSecret);
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(command.Username, result.Value.Username);
Assert.Equal(qrCodeUri, result.Value.TotpSecret);
@@ -148,10 +164,10 @@ public class SetupApplicationCommandHandlerTests
.Returns(new[] { existingUser });
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.AdminAccountAlreadyCreated, result.FirstError);
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
@@ -170,10 +186,10 @@ public class SetupApplicationCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
@@ -189,15 +205,15 @@ public class SetupApplicationCommandHandlerTests
Error error = Error.Failure("Database.Error", "Failed to insert user");
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<UserEntity>()));
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(error);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
@@ -213,17 +229,17 @@ public class SetupApplicationCommandHandlerTests
Error error = Error.Failure("Database.Error", "Failed to set default permissions");
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<UserEntity>()));
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(error);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
@@ -238,7 +254,7 @@ public class SetupApplicationCommandHandlerTests
Error error = Error.Failure("Database.Error", "Failed to set default roles");
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<UserEntity>()));
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
@@ -247,10 +263,10 @@ public class SetupApplicationCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
@@ -266,7 +282,7 @@ public class SetupApplicationCommandHandlerTests
Error error = Error.Failure("Database.Error", "Failed to set admin role permissions");
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<UserEntity>()));
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
@@ -277,10 +293,10 @@ public class SetupApplicationCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
@@ -297,7 +313,7 @@ public class SetupApplicationCommandHandlerTests
Error error = Error.Failure("Database.Error", "Failed to set admin role to administrator account");
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<UserEntity>()));
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
@@ -310,10 +326,10 @@ public class SetupApplicationCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
@@ -329,7 +345,7 @@ public class SetupApplicationCommandHandlerTests
SetupApplicationCommand command = _setupApplicationCommandFixture.CreateSetupApplicationCommand();
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<UserEntity>()));
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
@@ -342,10 +358,10 @@ public class SetupApplicationCommandHandlerTests
.Returns(Result.Created);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(command.Username, result.Value.Username);
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.Maintenance.ApplicationSetup.Commands.SetupApplication.Fixtures;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Core.Maintenance.ApplicationSetup.Queries.CheckInitialization;
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Contracts.Responses.UsersManagement;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -45,7 +45,7 @@ public class CheckInitializationQueryHandlerTests
// Arrange
List<UserEntity> users = UserEntityFixture.CreateMany();
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(users.AsEnumerable()));
.Returns(Result.From(users.AsEnumerable()));
// Act
InitializationResponse result = await _sut.HandleAsync(new CheckInitializationQuery(), CancellationToken.None);
@@ -60,7 +60,7 @@ public class CheckInitializationQueryHandlerTests
{
// Arrange
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<UserEntity>()));
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
// Act
InitializationResponse result = await _sut.HandleAsync(new CheckInitializationQuery(), CancellationToken.None);
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -45,7 +45,7 @@ public class DomainLibraryFixture
"F:/Content"
];
ErrorOr<Library> library = Library.Create(
Result<Library> library = Library.Create(
UserId.CreateUnique(),
_faker.Random.String2(_faker.Random.Number(1, 50)),
_faker.PickRandom<LibraryType>(),
@@ -76,7 +76,7 @@ public class DomainLibraryFixture
bool shouldSkipUnchangedDirectoriesDuringScan = false,
IEnumerable<Guid>? scanIds = null)
{
ErrorOr<Library> library = id is null ?
Result<Library> library = id is null ?
Library.Create(
userId is not null ? UserId.Create(userId.Value) : UserId.CreateUnique(),
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.UoW;
@@ -12,8 +11,9 @@ using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.Books
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Errors;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -66,10 +66,10 @@ public class AddBookCommandHandlerTests
.Returns(Result.Created);
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.IsType<BookResponse>(result.Value);
await _mockBookRepository.Received(1).InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -85,10 +85,10 @@ public class AddBookCommandHandlerTests
.Returns(Errors.WrittenContent.BookAlreadyExists);
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(Errors.WrittenContent.BookAlreadyExists, result.Errors);
await _mockBookRepository.Received(1).InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -102,10 +102,10 @@ public class AddBookCommandHandlerTests
bookCommand = bookCommand with { ISBNs = [new IsbnDto("invalid", IsbnFormat.Isbn13)] };
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.WrittenContent.InvalidIsbn13Format.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -119,10 +119,10 @@ public class AddBookCommandHandlerTests
bookCommand = bookCommand with { Ratings = [new BookRatingDto(-1, 5, null, null)] };
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.RatingValueMustBePositive.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -142,10 +142,10 @@ public class AddBookCommandHandlerTests
};
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.GenreNameCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -165,10 +165,10 @@ public class AddBookCommandHandlerTests
};
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.TagNameCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -195,10 +195,10 @@ public class AddBookCommandHandlerTests
};
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -218,10 +218,10 @@ public class AddBookCommandHandlerTests
};
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -241,10 +241,10 @@ public class AddBookCommandHandlerTests
};
// Act
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Errors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -409,7 +409,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Genres = bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = string.Empty } : genre).ToList() } };
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Genres = [.. bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = string.Empty } : genre)] } };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -423,7 +423,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Genres = bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = new Faker().Random.String2(51) } : genre).ToList() } };
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Genres = [.. bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = new Faker().Random.String2(51) } : genre)] } };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -441,7 +441,7 @@ public class AddBookCommandValidatorTests
{
Metadata = bookCommand.Metadata! with
{
Genres = bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = new Faker().Random.String2(50) } : genre).ToList()
Genres = [.. bookCommand.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = new Faker().Random.String2(50) } : genre)]
}
};
@@ -471,7 +471,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Tags = bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = string.Empty } : tag).ToList() } };
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Tags = [.. bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = string.Empty } : tag)] } };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -485,7 +485,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Tags = bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = new Faker().Random.String2(51) } : tag).ToList() } };
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Tags = [.. bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = new Faker().Random.String2(51) } : tag)] } };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -503,7 +503,7 @@ public class AddBookCommandValidatorTests
{
Metadata = bookCommand.Metadata! with
{
Tags = bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = new Faker().Random.String2(50) } : tag).ToList()
Tags = [.. bookCommand.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = new Faker().Random.String2(50) } : tag)]
}
};
@@ -1569,7 +1569,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = null! } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = null! } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1583,7 +1583,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn10 } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn10 } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1597,7 +1597,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn13 } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn13 } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1611,7 +1611,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Format = (IsbnFormat)99 } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Format = (IsbnFormat)99 } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1625,7 +1625,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = "0-306-40615-2", Format = IsbnFormat.Isbn10 } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = "0-306-40615-2", Format = IsbnFormat.Isbn10 } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1639,7 +1639,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { ISBNs = bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = "978-3-16-148410-0", Format = IsbnFormat.Isbn13 } : isbn).ToList() };
bookCommand = bookCommand with { ISBNs = [.. bookCommand.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = "978-3-16-148410-0", Format = IsbnFormat.Isbn13 } : isbn)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1667,7 +1667,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = null! } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = null! } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1681,7 +1681,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = new Faker().Random.String2(101) } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = new Faker().Random.String2(101) } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1695,7 +1695,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = null! } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = null! } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1709,7 +1709,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { LegalName = new Faker().Random.String2(101) } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { LegalName = new Faker().Random.String2(101) } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1723,7 +1723,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = null! } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = null! } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1737,7 +1737,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Name = null! } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Name = null! } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1751,7 +1751,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Name = new Faker().Random.String2(51) } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Name = new Faker().Random.String2(51) } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1765,7 +1765,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Category = null! } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Category = null! } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1779,7 +1779,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Category = new Faker().Random.String2(51) } } : contributor).ToList() };
bookCommand = bookCommand with { Contributors = [.. bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = contributor.Role! with { Category = new Faker().Random.String2(51) } } : contributor)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1807,7 +1807,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = -1 } : rating).ToList() };
bookCommand = bookCommand with { Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = -1 } : rating)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1821,7 +1821,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = 6, MaxValue = 5 } : rating).ToList() };
bookCommand = bookCommand with { Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = 6, MaxValue = 5 } : rating)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1835,7 +1835,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { MaxValue = -1 } : rating).ToList() };
bookCommand = bookCommand with { Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { MaxValue = -1 } : rating)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1849,7 +1849,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = -1 } : rating).ToList() };
bookCommand = bookCommand with { Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = -1 } : rating)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1865,9 +1865,9 @@ public class AddBookCommandValidatorTests
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with
{
Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating
Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating
with
{ Value = 4, MaxValue = 5, VoteCount = 100 } : rating).ToList()
{ Value = 4, MaxValue = 5, VoteCount = 100 } : rating)]
};
// Act
@@ -1882,7 +1882,7 @@ public class AddBookCommandValidatorTests
{
// Arrange
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
bookCommand = bookCommand with { Ratings = bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = null } : rating).ToList() };
bookCommand = bookCommand with { Ratings = [.. bookCommand.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = null } : rating)] };
// Act
List<Error> result = _validator.TestValidate(bookCommand);
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
@@ -9,6 +9,7 @@ using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.Boo
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -24,6 +25,8 @@ namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.B
public class BookFixture
{
private readonly Fixture _fixture;
private readonly IsbnFixture _isbnFixture;
private readonly BookRatingFixture _bookRatingFixture;
/// <summary>
/// Initializes a new instance of the <see cref="BookFixture"/> class.
@@ -33,6 +36,8 @@ public class BookFixture
_fixture = new Fixture();
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
_isbnFixture = new IsbnFixture();
_bookRatingFixture = new BookRatingFixture();
ConfigureCustomDomainTypes();
}
@@ -106,16 +111,8 @@ public class BookFixture
_fixture.Create<Optional<int>>()
).Value);
_fixture.Register(() => Isbn.Create(
_fixture.Create<string>(),
_fixture.Create<IsbnFormat>()
).Value);
_fixture.Register(() => _isbnFixture.CreateIsbn13());
_fixture.Register(() => BookRating.Create(
_fixture.Create<decimal>(),
_fixture.Create<decimal>(),
_fixture.Create<Optional<BookRatingSource>>(),
_fixture.Create<Optional<int>>()
).Value);
_fixture.Register(() => _bookRatingFixture.CreateBookRating());
}
}
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -52,10 +52,10 @@ public class ReorderLibraryMetadataProvidersCommandHandlerTests
.Returns(Result.Updated);
// Act
ErrorOr<Success> result = await _sut.HandleAsync(new ReorderLibraryMetadataProvidersCommand(libraryId, [secondProvider.PluginId, firstProvider.PluginId]), CancellationToken.None);
Result<Success> result = await _sut.HandleAsync(new ReorderLibraryMetadataProvidersCommand(libraryId, [secondProvider.PluginId, firstProvider.PluginId]), CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
await _mockConfigurationRepository.Received(1).UpsertAsync(
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.PluginId == secondProvider.PluginId && configuration.Rank == 1),
Arg.Any<CancellationToken>());
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -51,10 +51,10 @@ public class SetLibraryMetadataProviderEnabledCommandHandlerTests
.Returns(Result.Updated);
// Act
ErrorOr<Success> result = await _sut.HandleAsync(new SetLibraryMetadataProviderEnabledCommand(libraryId, pluginId, true), CancellationToken.None);
Result<Success> result = await _sut.HandleAsync(new SetLibraryMetadataProviderEnabledCommand(libraryId, pluginId, true), CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
await _mockConfigurationRepository.Received(1).UpsertAsync(
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.IsEnabled && configuration.Rank == 1),
Arg.Any<CancellationToken>());
@@ -81,10 +81,10 @@ public class SetLibraryMetadataProviderEnabledCommandHandlerTests
.Returns(Result.Updated);
// Act
ErrorOr<Success> result = await _sut.HandleAsync(new SetLibraryMetadataProviderEnabledCommand(existingConfiguration.LibraryId, existingConfiguration.PluginId, true), CancellationToken.None);
Result<Success> result = await _sut.HandleAsync(new SetLibraryMetadataProviderEnabledCommand(existingConfiguration.LibraryId, existingConfiguration.PluginId, true), CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
await _mockConfigurationRepository.Received(1).UpsertAsync(
Arg.Is<LibraryMetadataProviderConfigurationEntity>(configuration => configuration.IsEnabled && configuration.Rank == 2),
Arg.Any<CancellationToken>());
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -46,10 +46,10 @@ public class UpdatePluginSettingsCommandHandlerTests
.Returns(Result.Updated);
// Act
ErrorOr<Success> result = await _sut.HandleAsync(new UpdatePluginSettingsCommand(pluginId, settings), CancellationToken.None);
Result<Success> result = await _sut.HandleAsync(new UpdatePluginSettingsCommand(pluginId, settings), CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
await _mockPluginRepository.Received(1).UpdateSettingsAsync(pluginId, Arg.Any<string?>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -1,13 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Core.Plugins.Queries.GetPlugins;
using Lumina.Contracts.Responses.Plugins;
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -44,10 +43,10 @@ public class GetPluginsQueryHandlerTests
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(plugins);
// Act
ErrorOr<IReadOnlyList<PluginResponse>> result = await _sut.HandleAsync(new GetPluginsQuery(), CancellationToken.None);
Result<IReadOnlyList<PluginResponse>> result = await _sut.HandleAsync(new GetPluginsQuery(), CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(2, result.Value.Count);
Assert.Equal(plugins[0].Name, result.Value[0].Name);
Assert.Equal(plugins[0].Id, result.Value[0].Id);
@@ -61,9 +60,9 @@ public class GetPluginsQueryHandlerTests
.Returns(Error.Failure(description: "Failed to get plugins"));
// Act
ErrorOr<IReadOnlyList<PluginResponse>> result = await _sut.HandleAsync(new GetPluginsQuery(), CancellationToken.None);
Result<IReadOnlyList<PluginResponse>> result = await _sut.HandleAsync(new GetPluginsQuery(), CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -9,6 +8,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -68,7 +68,7 @@ public class ChangePasswordCommandHandlerTests
newPassword);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(currentPassword, "hashedCurrentPassword")
.Returns(true);
_mockHashService.HashString(newPassword)
@@ -77,10 +77,10 @@ public class ChangePasswordCommandHandlerTests
.Returns(Result.Updated);
// Act
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.True(result.Value.IsPasswordChanged);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -97,13 +97,13 @@ public class ChangePasswordCommandHandlerTests
ChangePasswordCommand command = new("nonexistentUser", "oldPass", "newPass", "newPass");
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
// Act
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -125,15 +125,15 @@ public class ChangePasswordCommandHandlerTests
"newPass");
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(incorrectPassword, Uri.UnescapeDataString(user.Password))
.Returns(false);
// Act
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidCurrentPassword, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -161,17 +161,17 @@ public class ChangePasswordCommandHandlerTests
newPassword);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(currentPassword, "hashedCurrentPassword")
.Returns(true);
_mockUserRepository.UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(error);
// Act
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -198,10 +198,10 @@ public class ChangePasswordCommandHandlerTests
.Returns(error);
// Act
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.ChangePassword.Fixtures;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -10,6 +9,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -72,7 +72,7 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, totpCode);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockCryptographyService.Decrypt(encryptedTotpSecret)
.Returns(decryptedTotpSecret);
_mockTotpTokenGenerator.ValidateToken(Arg.Any<byte[]>(), totpCode)
@@ -83,10 +83,10 @@ public class RecoverPasswordCommandHandlerTests
.Returns(Result.Updated);
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.True(result.Value.IsPasswordReset);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -103,13 +103,13 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new("nonexistentUser", "123456");
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -128,13 +128,13 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, "123456");
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.PasswordResetAlreadyRequested, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -152,13 +152,13 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, "123456");
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -180,17 +180,17 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, totpCode);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockCryptographyService.Decrypt(encryptedTotpSecret)
.Returns(decryptedTotpSecret);
_mockTotpTokenGenerator.ValidateToken(Arg.Any<byte[]>(), totpCode)
.Returns(false);
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -214,7 +214,7 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, totpCode);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockCryptographyService.Decrypt(encryptedTotpSecret)
.Returns(decryptedTotpSecret);
_mockTotpTokenGenerator.ValidateToken(Arg.Any<byte[]>(), totpCode)
@@ -223,10 +223,10 @@ public class RecoverPasswordCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -252,10 +252,10 @@ public class RecoverPasswordCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -275,13 +275,13 @@ public class RecoverPasswordCommandHandlerTests
RecoverPasswordCommand command = new(user.Username, null);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
// Act
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RecoverPassword.Fixtures;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -12,6 +11,7 @@ using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUs
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RegisterUser.Fixture;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -76,7 +76,7 @@ public class RegisterUserCommandHandlerTests
string hashedPassword = "hashedPassword";
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
_mockHashService.HashString(command.Password!)
.Returns(hashedPassword);
_mockTotpTokenGenerator.GenerateSecret()
@@ -89,10 +89,10 @@ public class RegisterUserCommandHandlerTests
.Returns(Result.Created);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(command.Username, result.Value.Username);
Assert.Equal(qrCodeUri, result.Value.TotpSecret);
@@ -113,17 +113,17 @@ public class RegisterUserCommandHandlerTests
string hashedPassword = "hashedPassword";
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
_mockHashService.HashString(command.Password!)
.Returns(hashedPassword);
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Created);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(command.Username, result.Value.Username);
Assert.Null(result.Value.TotpSecret);
@@ -144,13 +144,13 @@ public class RegisterUserCommandHandlerTests
UserEntity existingUser = UserEntityFixture.CreateUserEntity();
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(existingUser));
.Returns(Result.From<UserEntity?>(existingUser));
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.UsernameAlreadyExists, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -166,15 +166,15 @@ public class RegisterUserCommandHandlerTests
Error error = Error.Failure("Database.Error", "Failed to insert user");
_mockUserRepository.GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(error);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -193,10 +193,10 @@ public class RegisterUserCommandHandlerTests
.Returns(error);
// Act
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RegisterUser.Fixture;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -10,6 +9,7 @@ using Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUsers;
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Queries.GetUsers.Fixtures;
using Lumina.Contracts.Responses.UsersManagement.Users;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -65,10 +65,10 @@ public class GetUsersQueryHandlerTests
.Returns(false);
// Act
ErrorOr<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -86,10 +86,10 @@ public class GetUsersQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -104,13 +104,13 @@ public class GetUsersQueryHandlerTests
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
.Returns(true);
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(users));
.Returns(Result.From(users));
// Act
ErrorOr<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(2, result.Value.Count());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -11,6 +10,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -79,17 +79,17 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(true);
_mockJwtTokenGenerator.GenerateToken(user.Id.ToString(), user.Username)
.Returns(jwtToken);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
@@ -114,7 +114,7 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password, totpCode);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(true);
_mockJwtTokenGenerator.GenerateToken(user.Id.ToString(), user.Username)
@@ -125,10 +125,10 @@ public class LoginUserQueryHandlerTests
.Returns(true);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
@@ -142,13 +142,13 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new("nonexistentUser", "password");
_mockUserRepository.GetByUsernameAsync(query.Username!, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(null));
.Returns(Result.From<UserEntity?>(null));
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
}
@@ -166,15 +166,15 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(false);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
}
@@ -194,17 +194,17 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(false);
_mockHashService.CheckStringAgainstHash(password, hashedTempPassword)
.Returns(true);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.TempPasswordExpired, result.FirstError);
await _mockUserRepository.Received(1).UpdateAsync(Arg.Is<UserEntity>(u =>
@@ -232,7 +232,7 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(false); // Regular password check fails
_mockHashService.CheckStringAgainstHash(password, hashedTempPassword)
@@ -241,10 +241,10 @@ public class LoginUserQueryHandlerTests
.Returns(jwtToken);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
@@ -266,15 +266,15 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(true);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
}
@@ -295,7 +295,7 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password, totpCode);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(true);
_mockCryptographyService.Decrypt(encryptedTotpSecret)
@@ -304,10 +304,10 @@ public class LoginUserQueryHandlerTests
.Returns(false);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
}
@@ -322,10 +322,10 @@ public class LoginUserQueryHandlerTests
.Returns(error);
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -345,17 +345,17 @@ public class LoginUserQueryHandlerTests
LoginUserQuery query = new(user.Username, password);
_mockUserRepository.GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<UserEntity?>(user));
.Returns(Result.From<UserEntity?>(user));
_mockHashService.CheckStringAgainstHash(password, hashedPassword)
.Returns(false); // Regular password check fails
_mockHashService.CheckStringAgainstHash(password, hashedTempPassword)
.Returns(false); // Temp password check also fails
// Act
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
_mockHashService.Received(1).CheckStringAgainstHash(password, hashedPassword);
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Errors;
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Queries.LoginUser.Fixtures;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -12,6 +11,7 @@ using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserR
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using NSubstitute;
using System;
@@ -21,7 +21,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
@@ -80,10 +80,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
.Returns(false);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
}
@@ -99,10 +99,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
.Returns((UserEntity?)null);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.Users.UserDoesNotExist, result.FirstError);
}
@@ -121,10 +121,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
.Returns((RoleEntity?)null);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(ApplicationErrors.Authorization.RoleNotFound, result.FirstError);
}
@@ -164,13 +164,13 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
.Returns(newRole);
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(users));
.Returns(Result.From(users));
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(ApplicationErrors.Authorization.CannotRemoveLastAdmin, result.FirstError);
}
@@ -192,15 +192,15 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
.Returns(role);
_mockPermissionRepository.GetByIdsAsync(command.Permissions, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(permissions));
.Returns(Result.From(permissions));
_mockUserRepository.UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(error);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -216,7 +216,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
Username = "testUser",
Password = "hashedPassword",
Libraries = [],
UserPermissions = command.Permissions.Select((p, i) => new UserPermissionEntity
UserPermissions = [.. command.Permissions.Select((p, i) => new UserPermissionEntity
{
UserId = command.UserId,
PermissionId = p,
@@ -226,7 +226,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
Id = p,
PermissionName = (AuthorizationPermission)(i + 1)
}
}).ToList(),
})],
UserRole = null,
CreatedOnUtc = DateTime.UtcNow,
CreatedBy = command.UserId
@@ -242,15 +242,15 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
.Returns(role);
_mockPermissionRepository.GetByIdsAsync(command.Permissions, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(permissions));
.Returns(Result.From(permissions));
_mockUserRepository.UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Updated);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(command.UserId, result.Value.UserId);
Assert.Equal(role.RoleName, result.Value.Role);
Assert.Equal(command.Permissions.Count, result.Value.Permissions.Count);
@@ -291,10 +291,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
.Returns(error);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -326,10 +326,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
.Returns(error);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
}
@@ -1,12 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Authentication;
@@ -8,6 +7,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetAuthorization.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -50,13 +50,13 @@ public class GetAuthorizationQueryHandlerTests
_mockCurrentUserService.UserId.Returns(userId);
_mockAuthorizationService.GetUserAuthorizationAsync(userId, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(authEntity));
.Returns(Result.From(authEntity));
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(userId, result.Value.UserId);
Assert.Equal(authEntity.Role, result.Value.Role);
Assert.Equal(authEntity.Permissions, result.Value.Permissions);
@@ -74,15 +74,15 @@ public class GetAuthorizationQueryHandlerTests
_mockCurrentUserService.UserId.Returns(adminUserId);
_mockAuthorizationService.GetUserAuthorizationAsync(adminUserId, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(adminAuthEntity));
.Returns(Result.From(adminAuthEntity));
_mockAuthorizationService.GetUserAuthorizationAsync(targetUserId, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(targetAuthEntity));
.Returns(Result.From(targetAuthEntity));
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(targetUserId, result.Value.UserId);
Assert.Equal(targetAuthEntity.Role, result.Value.Role);
Assert.Equal(targetAuthEntity.Permissions, result.Value.Permissions);
@@ -99,13 +99,13 @@ public class GetAuthorizationQueryHandlerTests
_mockCurrentUserService.UserId.Returns(currentUserId);
_mockAuthorizationService.GetUserAuthorizationAsync(currentUserId, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(currentUserAuth));
.Returns(Result.From(currentUserAuth));
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
}
@@ -123,10 +123,10 @@ public class GetAuthorizationQueryHandlerTests
.Returns(error);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -142,15 +142,15 @@ public class GetAuthorizationQueryHandlerTests
_mockCurrentUserService.UserId.Returns(adminUserId);
_mockAuthorizationService.GetUserAuthorizationAsync(adminUserId, Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(adminAuthEntity));
.Returns(Result.From(adminAuthEntity));
_mockAuthorizationService.GetUserAuthorizationAsync(targetUserId, Arg.Any<CancellationToken>())
.Returns(error);
// Act
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetAuthorization.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -10,6 +9,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetUserPermissions.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using NSubstitute;
using System;
@@ -70,10 +70,10 @@ public class GetUserPermissionsQueryHandlerTests
.Returns(false);
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -91,10 +91,10 @@ public class GetUserPermissionsQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -110,10 +110,10 @@ public class GetUserPermissionsQueryHandlerTests
.Returns((UserEntity?)null);
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
}
@@ -149,10 +149,10 @@ public class GetUserPermissionsQueryHandlerTests
.Returns(user);
// Act
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Single(result.Value);
Assert.Equal(AuthorizationPermission.CanViewUsers, result.Value.First().PermissionName);
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -11,6 +10,7 @@ using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetUserRole.Fixtures;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Primitives;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -68,10 +68,10 @@ public class GetUserRoleQueryHandlerTests
.Returns(false);
// Act
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -89,10 +89,10 @@ public class GetUserRoleQueryHandlerTests
.Returns(error);
// Act
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
}
@@ -108,10 +108,10 @@ public class GetUserRoleQueryHandlerTests
.Returns((UserEntity?)null);
// Act
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
}
@@ -128,10 +128,10 @@ public class GetUserRoleQueryHandlerTests
.Returns(user);
// Act
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Null(result.Value);
}
@@ -164,10 +164,10 @@ public class GetUserRoleQueryHandlerTests
.Returns(user);
// Act
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
Result<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Contains("TestRole", result.Value!.RoleName);
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.DataAccess.Core.Repositories.Authorization;
using Lumina.DataAccess.Core.UoW;
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
using Lumina.Domain.Common.Primitives;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System;
@@ -45,10 +45,10 @@ public class PermissionRepositoryTests
PermissionEntity permissionModel = _permissionEntityFixture.CreatePermissionModel();
// Act
ErrorOr<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
// check if the permission was added to the context's ChangeTracker
@@ -67,10 +67,10 @@ public class PermissionRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.PermissionAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<PermissionEntity>());
}
@@ -89,10 +89,10 @@ public class PermissionRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
Result<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(3, result.Value.Count());
Assert.Equal(permissions, result.Value);
@@ -102,10 +102,10 @@ public class PermissionRepositoryTests
public async Task GetAllAsync_WhenNoPermissionsExist_ShouldReturnEmptyList()
{
// Act
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
Result<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
@@ -123,16 +123,16 @@ public class PermissionRepositoryTests
_mockContext.Permissions.AddRange(permissions);
await _mockContext.SaveChangesAsync();
List<Guid> requestedIds = permissions.Take(2).Select(p => p.Id).ToList();
List<Guid> requestedIds = [.. permissions.Take(2).Select(p => p.Id)];
// Act
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
Result<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(2, result.Value.Count());
Assert.Equal(requestedIds, result.Value.Select(p => p.Id).ToList());
Assert.Equal(requestedIds, [.. result.Value.Select(p => p.Id)]);
}
[Fact]
@@ -142,10 +142,10 @@ public class PermissionRepositoryTests
List<Guid> requestedIds = [Guid.NewGuid(), Guid.NewGuid()];
// Act
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
Result<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.DataAccess.Core.Repositories.Authorization;
using Lumina.DataAccess.Core.UoW;
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
using Lumina.Domain.Common.Primitives;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System.Diagnostics.CodeAnalysis;
@@ -42,10 +42,10 @@ public class RolePermissionRepositoryTests
RolePermissionEntity rolePermissionModel = _rolePermissionEntityFixture.CreateRolePermissionModel();
// Act
ErrorOr<Created> result = await _sut.InsertAsync(rolePermissionModel, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(rolePermissionModel, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
// check if the role permission was added to the context's ChangeTracker
@@ -1,12 +1,11 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.DataAccess.Core.Repositories.Authorization;
using Lumina.DataAccess.Core.UoW;
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using Lumina.Domain.Common.Primitives;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System;
@@ -50,10 +49,10 @@ public class RoleRepositoryTests
};
// Act
ErrorOr<Created> result = await _sut.InsertAsync(role, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(role, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
// Check if the role was added to the context's ChangeTracker
@@ -86,10 +85,10 @@ public class RoleRepositoryTests
};
// Act
ErrorOr<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.RoleAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<RoleEntity>());
}
@@ -118,10 +117,10 @@ public class RoleRepositoryTests
};
// Act
ErrorOr<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.RoleAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<RoleEntity>());
}
@@ -152,10 +151,10 @@ public class RoleRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
Result<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(2, result.Value.Count());
Assert.Equal(roles, result.Value);
@@ -165,10 +164,10 @@ public class RoleRepositoryTests
public async Task GetAllAsync_WhenNoRolesExist_ShouldReturnEmptyList()
{
// Act
ErrorOr<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
Result<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
@@ -189,10 +188,10 @@ public class RoleRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<RoleEntity?> result = await _sut.GetByNameAsync("Admin", CancellationToken.None);
Result<RoleEntity?> result = await _sut.GetByNameAsync("Admin", CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(role, result.Value);
}
@@ -201,10 +200,10 @@ public class RoleRepositoryTests
public async Task GetByNameAsync_WhenRoleDoesNotExist_ShouldReturnNull()
{
// Act
ErrorOr<RoleEntity?> result = await _sut.GetByNameAsync("NonExistentRole", CancellationToken.None);
Result<RoleEntity?> result = await _sut.GetByNameAsync("NonExistentRole", CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Null(result.Value);
}
@@ -220,10 +219,10 @@ public class RoleRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<RoleEntity?> result = await _sut.GetByIdAsync(role.Id, CancellationToken.None);
Result<RoleEntity?> result = await _sut.GetByIdAsync(role.Id, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(role.Id, result.Value.Id);
Assert.Equal(role.RoleName, result.Value.RoleName);
@@ -238,10 +237,10 @@ public class RoleRepositoryTests
Guid nonExistentId = Guid.NewGuid();
// Act
ErrorOr<RoleEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
Result<RoleEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Null(result.Value);
}
@@ -271,10 +270,10 @@ public class RoleRepositoryTests
};
// Act
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
Result<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<RoleEntity>? updatedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
@@ -296,10 +295,10 @@ public class RoleRepositoryTests
};
// Act
ErrorOr<Updated> result = await _sut.UpdateAsync(nonExistentRole, CancellationToken.None);
Result<Updated> result = await _sut.UpdateAsync(nonExistentRole, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
}
@@ -328,10 +327,10 @@ public class RoleRepositoryTests
};
// Act
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
Result<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<RoleEntity>? updatedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
@@ -357,10 +356,10 @@ public class RoleRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
Result<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Deleted, result.Value);
EntityEntry<RoleEntity>? deletedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
@@ -376,10 +375,10 @@ public class RoleRepositoryTests
Guid nonExistentId = Guid.NewGuid();
// Act
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(nonExistentId, CancellationToken.None);
Result<Deleted> result = await _sut.DeleteByIdAsync(nonExistentId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
}
@@ -396,10 +395,10 @@ public class RoleRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
Result<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Deleted, result.Value);
EntityEntry<RoleEntity>? deletedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
@@ -1,16 +1,12 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.DataAccess.Core.Repositories.Authorization;
using Lumina.DataAccess.Core.UoW;
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using Lumina.Domain.Common.Primitives;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
@@ -46,10 +42,10 @@ public class UserRoleRepositoryTests
UserRoleEntity userRole = _userRoleEntityFixture.CreateUserRoleModel();
// Act
ErrorOr<Created> result = await _sut.InsertAsync(userRole, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(userRole, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
EntityEntry<UserRoleEntity>? addedUserRole = _mockContext.ChangeTracker.Entries<UserRoleEntity>()
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.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.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Errors;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System;
@@ -47,10 +47,10 @@ public class BookRepositoryTests
BookEntity bookModel = _bookEntityFixture.CreateBookModel();
// Act
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
// check if the book was added to the context's ChangeTracker
@@ -69,10 +69,10 @@ public class BookRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.WrittenContent.BookAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<BookEntity>()); // only the existing book should be in the context
}
@@ -89,10 +89,10 @@ public class BookRepositoryTests
bookModel.Tags = [new("Existing"), new("New")];
// Act
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
@@ -116,10 +116,10 @@ public class BookRepositoryTests
bookModel.Genres = [new("Existing"), new("New")];
// Act
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
@@ -145,10 +145,10 @@ public class BookRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
Result<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(3, result.Value.Count());
Assert.Equal(books, result.Value);
@@ -158,10 +158,10 @@ public class BookRepositoryTests
public async Task GetAllAsync_WhenNoBooksExist_ShouldReturnEmptyList()
{
// Act
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
Result<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
@@ -178,10 +178,10 @@ public class BookRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
Result<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Single(result.Value);
BookEntity retrievedBook = result.Value.First();
@@ -203,10 +203,10 @@ public class BookRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetByLibraryIdAsync(libraryId, CancellationToken.None);
Result<IEnumerable<BookEntity>> result = await _sut.GetByLibraryIdAsync(libraryId, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
BookEntity retrievedBook = Assert.Single(result.Value);
Assert.Equal(bookOfLibrary.Id, retrievedBook.Id);
}
@@ -220,10 +220,10 @@ public class BookRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<BookEntity?> result = await _sut.GetByPathAsync(book.LibraryId, book.Path, CancellationToken.None);
Result<BookEntity?> result = await _sut.GetByPathAsync(book.LibraryId, book.Path, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(book.Id, result.Value!.Id);
}
@@ -236,10 +236,10 @@ public class BookRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<BookEntity?> result = await _sut.GetByPathAsync(book.LibraryId, "/books/non-existent.epub", CancellationToken.None);
Result<BookEntity?> result = await _sut.GetByPathAsync(book.LibraryId, "/books/non-existent.epub", CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Null(result.Value);
}
@@ -267,10 +267,10 @@ public class BookRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<IReadOnlyList<BookEntity>> result = await _sut.GetBooksNeedingMetadataAsync(libraryId, null, 10, CancellationToken.None);
Result<IReadOnlyList<BookEntity>> result = await _sut.GetBooksNeedingMetadataAsync(libraryId, null, 10, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(2, result.Value.Count);
Assert.Contains(result.Value, book => book.Id == pendingBook.Id);
Assert.Contains(result.Value, book => book.Id == failedBook.Id);
@@ -291,10 +291,10 @@ public class BookRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<IReadOnlyList<BookEntity>> result = await _sut.GetBooksNeedingMetadataAsync(libraryId, firstBook.Path, 10, CancellationToken.None);
Result<IReadOnlyList<BookEntity>> result = await _sut.GetBooksNeedingMetadataAsync(libraryId, firstBook.Path, 10, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
BookEntity retrievedBook = Assert.Single(result.Value);
Assert.Equal(secondBook.Id, retrievedBook.Id);
}
@@ -310,10 +310,10 @@ public class BookRepositoryTests
book.Title = "Updated Title";
// Act
ErrorOr<Updated> result = await _sut.UpdateAsync(book, CancellationToken.None);
Result<Updated> result = await _sut.UpdateAsync(book, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Updated, result.Value);
BookEntity? retrievedBook = await _mockContext.Books.FindAsync(book.Id);
Assert.Equal("Updated Title", retrievedBook!.Title);
@@ -326,10 +326,10 @@ public class BookRepositoryTests
BookEntity book = _bookEntityFixture.CreateBookModel();
// Act
ErrorOr<Updated> result = await _sut.UpdateAsync(book, CancellationToken.None);
Result<Updated> result = await _sut.UpdateAsync(book, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.WrittenContent.BookNotFound, result.FirstError);
}
}
@@ -1,11 +1,10 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.DataAccess.Core.Repositories.Plugins;
using Lumina.DataAccess.Core.UoW;
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
using Microsoft.EntityFrameworkCore;
using Lumina.Domain.Common.Primitives;
using System;
using System.Linq;
using System.Threading;
@@ -44,10 +43,10 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<System.Collections.Generic.IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> result = await _sut.GetByLibraryIdAsync(libraryId, CancellationToken.None);
Result<System.Collections.Generic.IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> result = await _sut.GetByLibraryIdAsync(libraryId, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
LibraryMetadataProviderConfigurationEntity retrievedConfiguration = Assert.Single(result.Value);
Assert.Equal(configurationOfLibrary.PluginId, retrievedConfiguration.PluginId);
}
@@ -61,10 +60,10 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<LibraryMetadataProviderConfigurationEntity?> result = await _sut.GetByLibraryAndPluginIdAsync(configuration.LibraryId, configuration.PluginId, CancellationToken.None);
Result<LibraryMetadataProviderConfigurationEntity?> result = await _sut.GetByLibraryAndPluginIdAsync(configuration.LibraryId, configuration.PluginId, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(configuration.Id, result.Value!.Id);
}
@@ -75,11 +74,11 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
LibraryMetadataProviderConfigurationEntity configuration = _configurationFixture.CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
// Act
ErrorOr<Updated> result = await _sut.UpsertAsync(configuration, CancellationToken.None);
Result<Updated> result = await _sut.UpsertAsync(configuration, CancellationToken.None);
await _mockContext.SaveChangesAsync();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Single(_mockContext.LibraryMetadataProviderConfigurations);
}
@@ -95,11 +94,11 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
updatedConfiguration.IsEnabled = true;
// Act
ErrorOr<Updated> result = await _sut.UpsertAsync(updatedConfiguration, CancellationToken.None);
Result<Updated> result = await _sut.UpsertAsync(updatedConfiguration, CancellationToken.None);
await _mockContext.SaveChangesAsync();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
LibraryMetadataProviderConfigurationEntity retrievedConfiguration = _mockContext.LibraryMetadataProviderConfigurations.Single();
Assert.Equal(5, retrievedConfiguration.Rank);
Assert.True(retrievedConfiguration.IsEnabled);
@@ -1,12 +1,11 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.DataAccess.Core.Repositories.Plugins;
using Lumina.DataAccess.Core.UoW;
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Microsoft.EntityFrameworkCore;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Linq;
using System.Threading;
@@ -43,10 +42,10 @@ public class PluginRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<PluginEntity?> result = await _sut.GetByIdAsync(plugin.Id, CancellationToken.None);
Result<PluginEntity?> result = await _sut.GetByIdAsync(plugin.Id, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(plugin.Id, result.Value!.Id);
}
@@ -57,11 +56,11 @@ public class PluginRepositoryTests
PluginEntity plugin = _pluginFixture.CreatePluginEntity();
// Act
ErrorOr<Updated> result = await _sut.UpsertAsync(plugin, CancellationToken.None);
Result<Updated> result = await _sut.UpsertAsync(plugin, CancellationToken.None);
await _mockContext.SaveChangesAsync();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Single(_mockContext.Plugins);
}
@@ -79,11 +78,11 @@ public class PluginRepositoryTests
updatedPlugin.SettingsJson = null; // the stored settings must be preserved
// Act
ErrorOr<Updated> result = await _sut.UpsertAsync(updatedPlugin, CancellationToken.None);
Result<Updated> result = await _sut.UpsertAsync(updatedPlugin, CancellationToken.None);
await _mockContext.SaveChangesAsync();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
PluginEntity retrievedPlugin = _mockContext.Plugins.Single();
Assert.Equal("Updated Name", retrievedPlugin.Name);
Assert.Equal("""{"preferredLanguage":"en"}""", retrievedPlugin.SettingsJson);
@@ -98,11 +97,11 @@ public class PluginRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<Updated> result = await _sut.UpdateSettingsAsync(plugin.Id, """{"preferredLanguage":"fr"}""", CancellationToken.None);
Result<Updated> result = await _sut.UpdateSettingsAsync(plugin.Id, """{"preferredLanguage":"fr"}""", CancellationToken.None);
await _mockContext.SaveChangesAsync();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal("""{"preferredLanguage":"fr"}""", _mockContext.Plugins.Single().SettingsJson);
}
@@ -110,10 +109,10 @@ public class PluginRepositoryTests
public async Task UpdateSettingsAsync_WhenPluginDoesNotExist_ShouldReturnError()
{
// Act
ErrorOr<Updated> result = await _sut.UpdateSettingsAsync(Guid.NewGuid(), null, CancellationToken.None);
Result<Updated> result = await _sut.UpdateSettingsAsync(Guid.NewGuid(), null, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Plugins.PluginNotFound, result.FirstError);
}
}
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.DataAccess.Core.Repositories.Users;
using Lumina.DataAccess.Core.UoW;
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
using Lumina.DataAccess.UnitTests.Core.Repositories.Users.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System;
@@ -49,10 +49,10 @@ public class UserRepositoryTests
UserEntity userModel = _userEntityFixture.CreateUserModel();
// Act
ErrorOr<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
EntityEntry<UserEntity>? addedUser = _mockContext.ChangeTracker.Entries<UserEntity>()
@@ -70,10 +70,10 @@ public class UserRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
Result<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Users.UserAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<UserEntity>());
}
@@ -92,10 +92,10 @@ public class UserRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
Result<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(3, result.Value.Count());
Assert.Equal(users, result.Value);
@@ -105,10 +105,10 @@ public class UserRepositoryTests
public async Task GetAllAsync_WhenNoUsersExist_ShouldReturnEmptyList()
{
// Act
ErrorOr<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
Result<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
@@ -122,10 +122,10 @@ public class UserRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<UserEntity?> result = await _sut.GetByUsernameAsync(userModel.Username, CancellationToken.None);
Result<UserEntity?> result = await _sut.GetByUsernameAsync(userModel.Username, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(userModel, result.Value);
}
@@ -134,10 +134,10 @@ public class UserRepositoryTests
public async Task GetByUsernameAsync_WhenUserDoesNotExist_ShouldReturnNull()
{
// Act
ErrorOr<UserEntity?> result = await _sut.GetByUsernameAsync("nonexistent", CancellationToken.None);
Result<UserEntity?> result = await _sut.GetByUsernameAsync("nonexistent", CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Null(result.Value);
}
@@ -166,10 +166,10 @@ public class UserRepositoryTests
};
// Act
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Updated, result.Value);
UserEntity? modifiedUser = await _mockContext.Users.FirstOrDefaultAsync(u => u.Username == existingUser.Username);
@@ -186,10 +186,10 @@ public class UserRepositoryTests
UserEntity userModel = _userEntityFixture.CreateUserModel();
// Act
ErrorOr<Updated> result = await _sut.UpdateAsync(userModel, CancellationToken.None);
Result<Updated> result = await _sut.UpdateAsync(userModel, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Users.UserDoesNotExist, result.FirstError);
}
@@ -202,10 +202,10 @@ public class UserRepositoryTests
await _mockContext.SaveChangesAsync();
// Act
ErrorOr<UserEntity?> result = await _sut.GetByIdAsync(userModel.Id, CancellationToken.None);
Result<UserEntity?> result = await _sut.GetByIdAsync(userModel.Id, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(userModel.Id, result.Value.Id);
Assert.Equal(userModel.Username, result.Value.Username);
@@ -222,10 +222,10 @@ public class UserRepositoryTests
Guid nonExistentId = Guid.NewGuid();
// Act
ErrorOr<UserEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
Result<UserEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Null(result.Value);
}
@@ -268,10 +268,10 @@ public class UserRepositoryTests
};
// Act
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Updated, result.Value);
UserEntity? modifiedUser = await _mockContext.Users
@@ -333,10 +333,10 @@ public class UserRepositoryTests
};
// Act
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<UserPermissionEntity>? removedPermission = _mockContext.ChangeTracker
@@ -436,10 +436,10 @@ public class UserRepositoryTests
};
// Act
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<UserRoleEntity>? removedRole = _mockContext.ChangeTracker
@@ -496,10 +496,10 @@ public class UserRepositoryTests
};
// Act
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<UserRoleEntity>? removedRole = _mockContext.ChangeTracker
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -9,6 +8,7 @@ using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Time;
using Lumina.DataAccess.Core.Seed;
using Lumina.DataAccess.UnitTests.Core.Repositories.Users.Fixtures;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using NSubstitute;
using System;
@@ -58,10 +58,10 @@ public class DataSeedServiceTests
.Returns(Result.Created);
// Act
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationPermissionsAsync(adminId, CancellationToken.None);
Result<Created> result = await _sut.SetDefaultAuthorizationPermissionsAsync(adminId, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
await _mockPermissionRepository
@@ -86,10 +86,10 @@ public class DataSeedServiceTests
.Returns(expectedError);
// Act
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationPermissionsAsync(adminId, CancellationToken.None);
Result<Created> result = await _sut.SetDefaultAuthorizationPermissionsAsync(adminId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -132,10 +132,10 @@ public class DataSeedServiceTests
.Returns(Result.Created);
// Act
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
Result<Created> result = await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
await mockRoleRepository
@@ -164,10 +164,10 @@ public class DataSeedServiceTests
.Returns(expectedError);
// Act
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
Result<Created> result = await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -247,10 +247,10 @@ public class DataSeedServiceTests
mockRolePermissionRepository.InsertAsync(Arg.Any<RolePermissionEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Created);
// Act
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
Result<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
await mockRolePermissionRepository
@@ -278,10 +278,10 @@ public class DataSeedServiceTests
.Returns((RoleEntity?)null);
// Act
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
Result<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.AdminAccountNotFound, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -304,10 +304,10 @@ public class DataSeedServiceTests
mockPermissionRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(expectedError);
// Act
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
Result<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -335,10 +335,10 @@ public class DataSeedServiceTests
mockRolePermissionRepository.InsertAsync(Arg.Any<RolePermissionEntity>(), Arg.Any<CancellationToken>()).Returns(expectedError);
// Act
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
Result<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -359,10 +359,10 @@ public class DataSeedServiceTests
.Returns(expectedError);
// Act
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
Result<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -392,10 +392,10 @@ public class DataSeedServiceTests
mockUserRoleRepository.InsertAsync(Arg.Any<UserRoleEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Created);
// Act
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Created, result.Value);
await mockUserRoleRepository
@@ -424,10 +424,10 @@ public class DataSeedServiceTests
.Returns((RoleEntity?)null);
// Act
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.AdminRoleNotFound, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -449,10 +449,10 @@ public class DataSeedServiceTests
mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>()).Returns((UserEntity?)null);
// Act
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.Authorization.AdminAccountNotFound, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -481,10 +481,10 @@ public class DataSeedServiceTests
mockUserRoleRepository.InsertAsync(Arg.Any<UserRoleEntity>(), Arg.Any<CancellationToken>()).Returns(expectedError);
// Act
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -505,10 +505,10 @@ public class DataSeedServiceTests
.Returns(expectedError);
// Act
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -532,10 +532,10 @@ public class DataSeedServiceTests
mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>()).Returns(expectedError);
// Act
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
@@ -1,14 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -26,7 +24,7 @@ public static class BookFixture
/// <returns>The created <see cref="Book"/> domain entity.</returns>
public static Book CreateValidBook()
{
ErrorOr<Book> bookResult = Book.Create(
Result<Book> bookResult = Book.Create(
LibraryId.Create(Guid.NewGuid()),
"/books/test.epub",
WrittenContentMetadata.Create(
@@ -65,7 +63,7 @@ public static class BookFixture
[],
[]
);
if (bookResult.IsError)
if (bookResult.IsFailure)
throw new InvalidOperationException("Failed to create a valid book in the test fixture.");
return bookResult.Value;
}
@@ -1,11 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.Fixtures;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -29,10 +28,10 @@ public class DirectoryTests
Optional<DateTime> dateModified = DateTime.Now;
// Act
ErrorOr<Directory> result = Directory.Create(path, name, dateCreated, dateModified);
Result<Directory> result = Directory.Create(path, name, dateCreated, dateModified);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(name, result.Value.Name);
Assert.Equal(dateCreated, result.Value.DateCreated);
@@ -50,10 +49,10 @@ public class DirectoryTests
Optional<DateTime> dateModified = DateTime.Now;
// Act
ErrorOr<Directory> result = Directory.Create(invalidPath, name, dateCreated, dateModified);
Result<Directory> result = Directory.Create(invalidPath, name, dateCreated, dateModified);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.FileSystemManagement.InvalidPath, result.FirstError);
}
@@ -61,18 +60,18 @@ public class DirectoryTests
public void Create_WhenCalledWithFileSystemPathId_ShouldReturnSuccessfulResult()
{
// Arrange
ErrorOr<FileSystemPathId> pathIdResult = FileSystemPathId.Create("/valid/path");
Assert.False(pathIdResult.IsError);
Result<FileSystemPathId> pathIdResult = FileSystemPathId.Create("/valid/path");
Assert.False(pathIdResult.IsFailure);
FileSystemPathId pathId = pathIdResult.Value;
string name = "TestDirectory";
Optional<DateTime> dateCreated = DateTime.Now;
Optional<DateTime> dateModified = DateTime.Now;
// Act
ErrorOr<Directory> result = Directory.Create(pathId, name, dateCreated, dateModified);
Result<Directory> result = Directory.Create(pathId, name, dateCreated, dateModified);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(pathId, result.Value.Id);
Assert.Equal(name, result.Value.Name);
@@ -85,16 +84,16 @@ public class DirectoryTests
public void UpdateLastModified_WhenCalled_ShouldUpdateDateModified()
{
// Arrange
ErrorOr<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
Assert.False(directoryResult.IsError);
Result<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
Assert.False(directoryResult.IsFailure);
Directory directory = directoryResult.Value;
DateTime newDate = DateTime.Now;
// Act
ErrorOr<Updated> result = directory.UpdateLastModified(newDate);
Result<Updated> result = directory.UpdateLastModified(newDate);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(newDate, directory.DateModified.Value);
}
@@ -102,16 +101,16 @@ public class DirectoryTests
public void AddItem_WhenCalled_ShouldAddItemToCollection()
{
// Arrange
ErrorOr<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
Assert.False(directoryResult.IsError);
Result<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
Assert.False(directoryResult.IsFailure);
Directory directory = directoryResult.Value;
FileSystemItem item = new FileSystemItemFixture(FileSystemPathId.Create("/mock/path").Value, "MockItem", FileSystemItemType.File);
// Act
ErrorOr<Updated> result = directory.AddItem(item);
Result<Updated> result = directory.AddItem(item);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Contains(item, directory.Items);
}
@@ -119,17 +118,17 @@ public class DirectoryTests
public void RemoveItem_WhenCalledWithExistingItem_ShouldRemoveItemFromCollection()
{
// Arrange
ErrorOr<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
Assert.False(directoryResult.IsError);
Result<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
Assert.False(directoryResult.IsFailure);
Directory directory = directoryResult.Value;
FileSystemItem item = new FileSystemItemFixture(FileSystemPathId.Create("/mock/path").Value, "MockItem", FileSystemItemType.File);
directory.AddItem(item);
// Act
ErrorOr<Updated> result = directory.RemoveItem(item);
Result<Updated> result = directory.RemoveItem(item);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.DoesNotContain(item, directory.Items);
}
}
@@ -1,10 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -28,10 +27,10 @@ public class FileTests
long size = 1024;
// Act
ErrorOr<File> result = File.Create(path, name, dateCreated, dateModified, size);
Result<File> result = File.Create(path, name, dateCreated, dateModified, size);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(name, result.Value.Name);
Assert.Equal(dateCreated, result.Value.DateCreated);
@@ -51,10 +50,10 @@ public class FileTests
long size = 1024;
// Act
ErrorOr<File> result = File.Create(invalidPath, name, dateCreated, dateModified, size);
Result<File> result = File.Create(invalidPath, name, dateCreated, dateModified, size);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.FileSystemManagement.InvalidPath, result.FirstError);
}
@@ -62,8 +61,8 @@ public class FileTests
public void Create_WhenCalledWithFileSystemPathId_ShouldReturnSuccessfulResult()
{
// Arrange
ErrorOr<FileSystemPathId> pathIdResult = FileSystemPathId.Create("/valid/path/file.txt");
Assert.False(pathIdResult.IsError);
Result<FileSystemPathId> pathIdResult = FileSystemPathId.Create("/valid/path/file.txt");
Assert.False(pathIdResult.IsFailure);
FileSystemPathId pathId = pathIdResult.Value;
string name = "file.txt";
Optional<DateTime> dateCreated = DateTime.Now;
@@ -71,10 +70,10 @@ public class FileTests
long size = 1024;
// Act
ErrorOr<File> result = File.Create(pathId, name, dateCreated, dateModified, size);
Result<File> result = File.Create(pathId, name, dateCreated, dateModified, size);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(pathId, result.Value.Id);
Assert.Equal(name, result.Value.Name);
@@ -88,16 +87,16 @@ public class FileTests
public void UpdateLastModified_WhenCalled_ShouldUpdateDateModified()
{
// Arrange
ErrorOr<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
Assert.False(fileResult.IsError);
Result<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
Assert.False(fileResult.IsFailure);
File file = fileResult.Value;
DateTime newDate = DateTime.Now;
// Act
ErrorOr<Updated> result = file.UpdateLastModified(newDate);
Result<Updated> result = file.UpdateLastModified(newDate);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(newDate, file.DateModified.Value);
}
@@ -105,16 +104,16 @@ public class FileTests
public void UpdateSize_WhenCalled_ShouldUpdateFileSize()
{
// Arrange
ErrorOr<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
Assert.False(fileResult.IsError);
Result<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
Assert.False(fileResult.IsFailure);
File file = fileResult.Value;
long newSize = 2048;
// Act
ErrorOr<Updated> result = file.UpdateSize(newSize);
Result<Updated> result = file.UpdateSize(newSize);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(newSize, file.Size);
}
@@ -122,16 +121,16 @@ public class FileTests
public void Rename_WhenCalledWithValidName_ShouldUpdateFileName()
{
// Arrange
ErrorOr<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
Assert.False(fileResult.IsError);
Result<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
Assert.False(fileResult.IsFailure);
File file = fileResult.Value;
string newName = "newfile.txt";
// Act
ErrorOr<Updated> result = file.Rename(newName);
Result<Updated> result = file.Rename(newName);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(newName, file.Name);
}
@@ -139,16 +138,16 @@ public class FileTests
public void Rename_WhenCalledWithEmptyName_ShouldReturnError()
{
// Arrange
ErrorOr<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
Assert.False(fileResult.IsError);
Result<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
Assert.False(fileResult.IsFailure);
File file = fileResult.Value;
string emptyName = "";
// Act
ErrorOr<Updated> result = file.Rename(emptyName);
Result<Updated> result = file.Rename(emptyName);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.FileSystemManagement.NameCannotBeEmpty, result.FirstError);
Assert.Equal("file.txt", file.Name);
}
@@ -1,10 +1,9 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -54,9 +53,9 @@ public class DirectoryFixture
dateModified ??= Optional<DateTime>.Some(_faker.Date.Recent());
status ??= _faker.PickRandom<FileSystemItemStatus>();
ErrorOr<Directory> directoryResult = Directory.Create(path, name, dateCreated.Value, dateModified.Value, status.Value);
Result<Directory> directoryResult = Directory.Create(path, name, dateCreated.Value, dateModified.Value, status.Value);
if (directoryResult.IsError)
if (directoryResult.IsFailure)
throw new InvalidOperationException("Failed to create Directory: " + string.Join(", ", directoryResult.Errors));
Directory directory = directoryResult.Value;
@@ -73,7 +72,7 @@ public class DirectoryFixture
/// <returns>The created list.</returns>
public List<Directory> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => CreateDirectory()).ToList();
return [.. Enumerable.Range(0, count).Select(_ => CreateDirectory())];
}
/// <summary>
@@ -85,7 +84,7 @@ public class DirectoryFixture
/// <returns>A list of <see cref="Directory"/> objects with nested structures.</returns>
public List<Directory> CreateManyNested(int count = 3, int maxDepth = 3, int maxChildrenPerDirectory = 3)
{
return Enumerable.Range(0, count).Select(_ => CreateNestedDirectory(1, maxDepth, maxChildrenPerDirectory)).ToList();
return [.. Enumerable.Range(0, count).Select(_ => CreateNestedDirectory(1, maxDepth, maxChildrenPerDirectory))];
}
/// <summary>
@@ -1,9 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -47,9 +46,9 @@ public class FileFixture
size ??= _faker.Random.Long();
status ??= _faker.PickRandom<FileSystemItemStatus>();
ErrorOr<File> fileResult = File.Create(path, name, dateCreated.Value, dateModified.Value, size.Value, status.Value);
Result<File> fileResult = File.Create(path, name, dateCreated.Value, dateModified.Value, size.Value, status.Value);
if (fileResult.IsError)
if (fileResult.IsFailure)
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", fileResult.Errors));
return fileResult.Value;
}
@@ -61,7 +60,7 @@ public class FileFixture
/// <returns>The created list.</returns>
public List<File> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => CreateFile()).ToList();
return [.. Enumerable.Range(0, count).Select(_ => CreateFile())];
}
/// <summary>
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -20,10 +20,10 @@ public class UnixRootItemTests
public void Create_WhenCalledWithDefaultStatus_ShouldReturnSuccessfulResult()
{
// Arrange & Act
ErrorOr<UnixRootItem> result = UnixRootItem.Create();
Result<UnixRootItem> result = UnixRootItem.Create();
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal("/", result.Value.Name);
Assert.Equal("/", result.Value.Id.Path);
@@ -39,10 +39,10 @@ public class UnixRootItemTests
FileSystemItemStatus customStatus = FileSystemItemStatus.Accessible;
// Act
ErrorOr<UnixRootItem> result = UnixRootItem.Create(customStatus);
Result<UnixRootItem> result = UnixRootItem.Create(customStatus);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal("/", result.Value.Name);
Assert.Equal("/", result.Value.Id.Path);
@@ -55,8 +55,8 @@ public class UnixRootItemTests
public void Items_WhenAccessed_ShouldReturnEmptyReadOnlyCollection()
{
// Arrange
ErrorOr<UnixRootItem> createResult = UnixRootItem.Create();
Assert.False(createResult.IsError);
Result<UnixRootItem> createResult = UnixRootItem.Create();
Assert.False(createResult.IsFailure);
UnixRootItem unixRootItem = createResult.Value;
// Act
@@ -71,16 +71,16 @@ public class UnixRootItemTests
public void SetStatus_WhenCalledWithNewStatus_ShouldUpdateStatus()
{
// Arrange
ErrorOr<UnixRootItem> createResult = UnixRootItem.Create();
Assert.False(createResult.IsError);
Result<UnixRootItem> createResult = UnixRootItem.Create();
Assert.False(createResult.IsFailure);
UnixRootItem unixRootItem = createResult.Value;
FileSystemItemStatus newStatus = FileSystemItemStatus.Accessible;
// Act
ErrorOr<Updated> result = unixRootItem.SetStatus(newStatus);
Result<Updated> result = unixRootItem.SetStatus(newStatus);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(newStatus, unixRootItem.Status);
}
@@ -88,15 +88,15 @@ public class UnixRootItemTests
public void SetParent_WhenCalledWithNullParent_ShouldReturnError()
{
// Arrange
ErrorOr<UnixRootItem> createResult = UnixRootItem.Create();
Assert.False(createResult.IsError);
Result<UnixRootItem> createResult = UnixRootItem.Create();
Assert.False(createResult.IsFailure);
UnixRootItem unixRootItem = createResult.Value;
// Act
ErrorOr<Updated> result = unixRootItem.SetParent(null!);
Result<Updated> result = unixRootItem.SetParent(null!);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.FileSystemManagement.ParentNodeCannotBeNull, result.FirstError);
Assert.False(unixRootItem.Parent.HasValue);
}
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -25,10 +25,10 @@ public class WindowsRootItemTests
string name = "C:";
// Act
ErrorOr<WindowsRootItem> result = WindowsRootItem.Create(path, name);
Result<WindowsRootItem> result = WindowsRootItem.Create(path, name);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(name, result.Value.Name);
Assert.Equal(path, result.Value.Id.Path);
@@ -45,10 +45,10 @@ public class WindowsRootItemTests
string name = "Invalid";
// Act
ErrorOr<WindowsRootItem> result = WindowsRootItem.Create(invalidPath, name);
Result<WindowsRootItem> result = WindowsRootItem.Create(invalidPath, name);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.FileSystemManagement.InvalidPath, result.FirstError);
}
@@ -61,10 +61,10 @@ public class WindowsRootItemTests
FileSystemItemStatus customStatus = FileSystemItemStatus.Accessible;
// Act
ErrorOr<WindowsRootItem> result = WindowsRootItem.Create(path, name, customStatus);
Result<WindowsRootItem> result = WindowsRootItem.Create(path, name, customStatus);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(name, result.Value.Name);
Assert.Equal(path, result.Value.Id.Path);
@@ -76,16 +76,16 @@ public class WindowsRootItemTests
public void Create_WhenCalledWithFileSystemPathId_ShouldReturnSuccessfulResult()
{
// Arrange
ErrorOr<FileSystemPathId> pathIdResult = FileSystemPathId.Create("E:\\");
Assert.False(pathIdResult.IsError);
Result<FileSystemPathId> pathIdResult = FileSystemPathId.Create("E:\\");
Assert.False(pathIdResult.IsFailure);
FileSystemPathId pathId = pathIdResult.Value;
string name = "E:";
// Act
ErrorOr<WindowsRootItem> result = WindowsRootItem.Create(pathId, name);
Result<WindowsRootItem> result = WindowsRootItem.Create(pathId, name);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(pathId, result.Value.Id);
Assert.Equal(name, result.Value.Name);
@@ -97,8 +97,8 @@ public class WindowsRootItemTests
public void Items_WhenAccessed_ShouldReturnEmptyReadOnlyCollection()
{
// Arrange
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create("F:\\", "F:");
Assert.False(createResult.IsError);
Result<WindowsRootItem> createResult = WindowsRootItem.Create("F:\\", "F:");
Assert.False(createResult.IsFailure);
WindowsRootItem windowsRootItem = createResult.Value;
// Act
@@ -113,16 +113,16 @@ public class WindowsRootItemTests
public void SetStatus_WhenCalledWithNewStatus_ShouldUpdateStatus()
{
// Arrange
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create("G:\\", "G:");
Assert.False(createResult.IsError);
Result<WindowsRootItem> createResult = WindowsRootItem.Create("G:\\", "G:");
Assert.False(createResult.IsFailure);
WindowsRootItem windowsRootItem = createResult.Value;
FileSystemItemStatus newStatus = FileSystemItemStatus.Accessible;
// Act
ErrorOr<Updated> result = windowsRootItem.SetStatus(newStatus);
Result<Updated> result = windowsRootItem.SetStatus(newStatus);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(newStatus, windowsRootItem.Status);
}
@@ -130,15 +130,15 @@ public class WindowsRootItemTests
public void SetParent_WhenCalledWithNullParent_ShouldReturnError()
{
// Arrange
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create("H:\\", "H:");
Assert.False(createResult.IsError);
Result<WindowsRootItem> createResult = WindowsRootItem.Create("H:\\", "H:");
Assert.False(createResult.IsFailure);
WindowsRootItem windowsRootItem = createResult.Value;
// Act
ErrorOr<Updated> result = windowsRootItem.SetParent(null!);
Result<Updated> result = windowsRootItem.SetParent(null!);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.FileSystemManagement.ParentNodeCannotBeNull, result.FirstError);
Assert.False(windowsRootItem.Parent.HasValue);
}
@@ -1,12 +1,11 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.Fixtures;
using Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.ValueObjects.Fixtures;
using System.Diagnostics.CodeAnalysis;
@@ -59,10 +58,10 @@ public class FileSystemItemTests
FileSystemItemStatus newStatus = FileSystemItemStatus.Inaccessible;
// Act
ErrorOr<Updated> result = item.SetStatus(newStatus);
Result<Updated> result = item.SetStatus(newStatus);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Updated, result.Value);
Assert.Equal(newStatus, item.Status);
}
@@ -75,10 +74,10 @@ public class FileSystemItemTests
FileSystemItemFixture parent = CreateFileSystemItemFixture();
// Act
ErrorOr<Updated> result = item.SetParent(parent);
Result<Updated> result = item.SetParent(parent);
// Assert
Assert.False(result.IsError);
Assert.False(result.IsFailure);
Assert.Equal(Result.Updated, result.Value);
Assert.Equal(Optional<FileSystemItem>.Some(parent), item.Parent);
}
@@ -90,10 +89,10 @@ public class FileSystemItemTests
FileSystemItemFixture item = CreateFileSystemItemFixture();
// Act
ErrorOr<Updated> result = item.SetParent(null!);
Result<Updated> result = item.SetParent(null!);
// Assert
Assert.True(result.IsError);
Assert.True(result.IsFailure);
Assert.Equal(Errors.FileSystemManagement.ParentNodeCannotBeNull, result.FirstError);
Assert.Equal(Optional<FileSystemItem>.None(), item.Parent);
}
Loaded 100 of 436 files, more files were not shown because too many files have changed in this diff. Show more