Implements tests for commit c27621818c

This commit is contained in:
BinaryAlley committed 2026-10-27 22:35:33 +02:00
1 parent 54b468855a
commit d8adf3c1b6
22 files changed
+7664

No files matched your search

@@ -80,6 +80,7 @@ public class StartConsumptionCommandValidatorTests
[InlineData(" ")] // the media kind is whitespace only
[InlineData("Hologram")] // the media kind is not a member of the enumeration
[InlineData("0")] // the media kind is a numeric route value, which the validator rejects by name
[InlineData("1")] // a numeric route value that parses to the defined MusicTrack member, which the old Enum.TryParse and Enum.IsDefined logic accepted
public void Validate_WhenMediaKindIsEmptyOrUnsupported_ShouldHaveValidationError(string mediaKind)
{
// Arrange
@@ -266,6 +266,8 @@ public class GetResumePointQueryHandlerTests
Assert.Equal(DomainErrors.MediaConsumption.MediaResumePointNotFound, result.FirstError);
await _mockMediaResumePointRepository.Received(1).DeleteForUserAndMediaItemAsync(_userId, MediaKind.MusicTrack, mediaItemId, Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
// The query answers with a not-found result, which the request pipeline does not commit, so the cleanup is committed explicitly.
await _mockUnitOfWork.Received(1).CommitTransactionAsync(Arg.Any<CancellationToken>());
await _mockTrackRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<bool>(), Arg.Any<bool>(), Arg.Any<CancellationToken>());
}
@@ -289,6 +291,7 @@ public class GetResumePointQueryHandlerTests
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -309,6 +312,8 @@ public class GetResumePointQueryHandlerTests
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.MediaConsumption.MediaResumePointNotFound, result.FirstError);
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
// A concurrency conflict means the row is already gone, which is the desired outcome, so there is nothing to commit.
await _mockUnitOfWork.DidNotReceive().CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -329,6 +334,7 @@ public class GetResumePointQueryHandlerTests
// Assert
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -352,6 +358,7 @@ public class GetResumePointQueryHandlerTests
Assert.Equal(error, result.FirstError);
await _mockMediaResumePointRepository.DidNotReceive().DeleteForUserAndMediaItemAsync(Arg.Any<Guid>(), Arg.Any<MediaKind>(), Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -374,6 +381,7 @@ public class GetResumePointQueryHandlerTests
Assert.Equal(DomainErrors.Music.TrackNotFound, result.FirstError);
await _mockMediaResumePointRepository.Received(1).DeleteForUserAndMediaItemAsync(_userId, MediaKind.MusicTrack, mediaItemId, Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -395,6 +403,7 @@ public class GetResumePointQueryHandlerTests
Assert.Equal(DomainErrors.Music.TrackNotFound, result.FirstError);
await _mockMediaResumePointRepository.Received(1).DeleteForUserAndMediaItemAsync(_userId, MediaKind.MusicTrack, mediaItemId, Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -419,6 +428,7 @@ public class GetResumePointQueryHandlerTests
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -441,6 +451,7 @@ public class GetResumePointQueryHandlerTests
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.Music.TrackNotFound, result.FirstError);
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -463,6 +474,7 @@ public class GetResumePointQueryHandlerTests
// Assert
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -511,6 +523,7 @@ public class GetResumePointQueryHandlerTests
cancellationToken: Arg.Any<CancellationToken>());
await _mockMediaResumePointRepository.DidNotReceive().DeleteForUserAndMediaItemAsync(Arg.Any<Guid>(), Arg.Any<MediaKind>(), Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -529,6 +542,7 @@ public class GetResumePointQueryHandlerTests
// Assert
Assert.False(result.IsFailure);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -554,6 +568,7 @@ public class GetResumePointQueryHandlerTests
Assert.Equal(error, result.FirstError);
await _mockMediaResumePointRepository.DidNotReceive().DeleteForUserAndMediaItemAsync(Arg.Any<Guid>(), Arg.Any<MediaKind>(), Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -578,6 +593,7 @@ public class GetResumePointQueryHandlerTests
Assert.Equal(DomainErrors.WrittenContent.BookNotFound, result.FirstError);
await _mockMediaResumePointRepository.Received(1).DeleteForUserAndMediaItemAsync(_userId, MediaKind.Book, mediaItemId, Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).CommitTransactionAsync(Arg.Any<CancellationToken>());
await _mockTrackRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<bool>(), Arg.Any<bool>(), Arg.Any<CancellationToken>());
}
@@ -603,6 +619,7 @@ public class GetResumePointQueryHandlerTests
Assert.Equal(DomainErrors.WrittenContent.BookNotFound, result.FirstError);
await _mockMediaResumePointRepository.Received(1).DeleteForUserAndMediaItemAsync(_userId, MediaKind.Book, mediaItemId, Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).CommitTransactionAsync(Arg.Any<CancellationToken>());
}
[Fact]
@@ -654,6 +671,7 @@ public class GetResumePointQueryHandlerTests
cancellationToken: Arg.Any<CancellationToken>());
await _mockMediaResumePointRepository.DidNotReceive().DeleteForUserAndMediaItemAsync(Arg.Any<Guid>(), Arg.Any<MediaKind>(), Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().CommitTransactionAsync(Arg.Any<CancellationToken>());
}
/// <summary>
@@ -38,6 +38,7 @@ public class GetResumePointQueryValidatorTests
[InlineData(" ")] // the media kind is whitespace only
[InlineData("not-a-media-kind")] // the media kind is not the name of a defined kind
[InlineData("99999")] // a numeric value that is not the name of a defined kind
[InlineData("1")] // a numeric value that parses to the defined MusicTrack member, which the old Enum.TryParse and Enum.IsDefined logic accepted
public void Validate_WhenMediaKindIsNotTheNameOfADefinedKind_ShouldHaveValidationError(string mediaKind)
{
// Arrange