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,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