mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Adds deletion and restore for music library items.
This commit is contained in:
1 parent
98515dc5e8
commit
f9ad8b2fc5
224 files changed
+22384
-1360
No files matched your search
+32
@@ -471,6 +471,38 @@ public class ArtistTests
|
||||
Assert.Single(artist.Albums);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsureCanRemoveAlbum_WhenTheArtistHasAnotherAlbum_ShouldReturnSuccess()
|
||||
{
|
||||
// Arrange
|
||||
Album firstAlbum = _albumFixture.Create();
|
||||
Album secondAlbum = _albumFixture.Create();
|
||||
Artist artist = _artistFixture.Create(albums: [firstAlbum, secondAlbum]);
|
||||
|
||||
// Act
|
||||
Result<bool> result = artist.CanRemoveAlbum(firstAlbum);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(2, artist.Albums.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsureCanRemoveAlbum_WhenAlbumIsTheOnlyAlbumOfTheArtist_ShouldReturnArtistMustHaveAtLeastOneAlbumError()
|
||||
{
|
||||
// Arrange
|
||||
Album onlyAlbum = _albumFixture.Create();
|
||||
Artist artist = _artistFixture.Create(albums: [onlyAlbum]);
|
||||
|
||||
// Act
|
||||
Result<bool> result = artist.CanRemoveAlbum(onlyAlbum);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Music.ArtistMustHaveAtLeastOneAlbum, result.FirstError);
|
||||
Assert.Single(artist.Albums);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateContributors_WhenCalledWithNewContributors_ShouldReplaceThemInPlace()
|
||||
{
|
||||
|
||||
+38
@@ -955,4 +955,42 @@ public class FileProviderServiceTests
|
||||
Assert.Equal(Errors.Permission.UnauthorizedAccess, result.FirstError);
|
||||
_mockFileSystem.File.DidNotReceive().Delete(Arg.Any<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeleteFile_WhenTheFileIsLocked_ShouldReturnFileDeleteError()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemPathId path = _fileSystemPathIdFixture.Create(
|
||||
s_isUnix ? "/LockedFileToDelete.txt" : @"C:\LockedFileToDelete.txt"
|
||||
);
|
||||
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Delete).Returns(true);
|
||||
_mockFileSystem.File.When(file => file.Delete(path.Path))
|
||||
.Do(_ => throw new IOException("The file is locked by another process"));
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = _sut.DeleteFile(path);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.FileSystemManagement.FileDeleteError, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeleteFile_WhenTheFileIsReadOnly_ShouldReturnUnauthorizedAccessError()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemPathId path = _fileSystemPathIdFixture.Create(
|
||||
s_isUnix ? "/ReadOnlyFileToDelete.txt" : @"C:\ReadOnlyFileToDelete.txt"
|
||||
);
|
||||
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Delete).Returns(true);
|
||||
_mockFileSystem.File.When(file => file.Delete(path.Path))
|
||||
.Do(_ => throw new UnauthorizedAccessException("The file is read-only"));
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = _sut.DeleteFile(path);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Permission.UnauthorizedAccess, result.FirstError);
|
||||
}
|
||||
}
|
||||
+47
@@ -7,6 +7,7 @@ using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.File
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
@@ -772,6 +773,52 @@ public class PathServiceTests
|
||||
Assert.Equal(100, result.Value.Name.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SanitizeCompositeSegment_WhenTheNameFitsTheBudget_ShouldAppendTheIdentifier()
|
||||
{
|
||||
// Arrange
|
||||
_mockPathStrategy.GetInvalidPathSegmentCharsForPlatform().Returns(['<', '>', ':', '"', '|', '?', '*']);
|
||||
string identifier = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
Result<PathSegment> result = _sut.SanitizeCompositeSegment("Queen", identifier);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal($"Queen-{identifier}", result.Value.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SanitizeCompositeSegment_WhenTheNameExceedsTheBudget_ShouldTruncateOnlyTheName()
|
||||
{
|
||||
// Arrange
|
||||
_mockPathStrategy.GetInvalidPathSegmentCharsForPlatform().Returns(['<', '>', ':', '"', '|', '?', '*']);
|
||||
string identifier = Guid.NewGuid().ToString();
|
||||
|
||||
// Act
|
||||
Result<PathSegment> result = _sut.SanitizeCompositeSegment(new string('a', 99), identifier);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(100, result.Value.Name.Length);
|
||||
Assert.EndsWith($"-{identifier}", result.Value.Name);
|
||||
Assert.Equal(new string('a', 63), result.Value.Name[..^($"-{identifier}".Length)]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SanitizeCompositeSegment_WhenTheIdentifierLeavesNoRoomForTheName_ShouldReturnInvalidPath()
|
||||
{
|
||||
// Arrange
|
||||
_mockPathStrategy.GetInvalidPathSegmentCharsForPlatform().Returns(['<', '>', ':', '"', '|', '?', '*']);
|
||||
|
||||
// Act
|
||||
Result<PathSegment> result = _sut.SanitizeCompositeSegment("Queen", new string('a', 99));
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.FileSystemManagement.InvalidPath, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsPathWithin_WhenBothPathsAreValid_ShouldCreatePathIdsAndDelegateToTheStrategy()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user