Formats code comments as sentences in the tests.

Capitalizes the first word and adds the terminal period in the unit, integration and security tests. The AAA markers stay bare, the TODO bodies stay lowercase, and no assertion, payload, expected status code or test signature changes.
This commit is contained in:
BinaryAlley committed 2026-11-16 18:17:29 +02:00
1 parent 727aa33318
commit 057f557791
540 files changed
+3888 -3888

No files matched your search

@@ -102,7 +102,7 @@ public class DomainEventPublisherTests
await publisher.PublishAsync(domainEvent, CancellationToken.None);
// Assert
// reaching this point without an exception means the publish was a no-op, as expected
// Reaching this point without an exception means the publish was a no-op, as expected.
}
[Fact]
@@ -33,13 +33,13 @@ public class PublicHostRedirectHandlerTests
}
[Theory]
[InlineData("http://127.0.0.1/cover.jpg")] // the IPv4 loopback address
[InlineData("http://localhost/cover.jpg")] // the loopback host name
[InlineData("http://[::1]/cover.jpg")] // the IPv6 loopback address
[InlineData("http://169.254.169.254/latest/meta-data/")] // the link local cloud metadata endpoint
[InlineData("http://10.0.0.5/cover.jpg")] // a private class A address
[InlineData("http://172.16.0.1/cover.jpg")] // a private class B address
[InlineData("http://192.168.1.10/cover.jpg")] // a private class C address
[InlineData("http://127.0.0.1/cover.jpg")] // The IPv4 loopback address.
[InlineData("http://localhost/cover.jpg")] // The loopback host name.
[InlineData("http://[::1]/cover.jpg")] // The IPv6 loopback address.
[InlineData("http://169.254.169.254/latest/meta-data/")] // The link local cloud metadata endpoint.
[InlineData("http://10.0.0.5/cover.jpg")] // A private class A address.
[InlineData("http://172.16.0.1/cover.jpg")] // A private class B address.
[InlineData("http://192.168.1.10/cover.jpg")] // A private class C address.
public async Task SendAsync_WhenTheInitialRequestHostIsPrivateOrLocal_ShouldThrowAndNotSendTheRequest(string url)
{
// Arrange
@@ -83,12 +83,12 @@ public class PublicHostRedirectHandlerTests
}
[Theory]
[InlineData("http://archive.org/index.json")] // a downgrade of a trusted host to plain HTTP
[InlineData("https://127.0.0.1/index.json")] // the IPv4 loopback address
[InlineData("https://localhost/index.json")] // the loopback host name
[InlineData("https://169.254.169.254/latest/meta-data/")] // the link local cloud metadata endpoint
[InlineData("https://10.0.0.5/index.json")] // a private class A address
[InlineData("https://192.168.1.10/index.json")] // a private class C address
[InlineData("http://archive.org/index.json")] // A downgrade of a trusted host to plain HTTP.
[InlineData("https://127.0.0.1/index.json")] // The IPv4 loopback address.
[InlineData("https://localhost/index.json")] // The loopback host name.
[InlineData("https://169.254.169.254/latest/meta-data/")] // The link local cloud metadata endpoint.
[InlineData("https://10.0.0.5/index.json")] // A private class A address.
[InlineData("https://192.168.1.10/index.json")] // A private class C address.
public async Task SendAsync_WhenTheInitialRequestRedirectsToADisallowedTarget_ShouldThrow(string location)
{
// Arrange
@@ -12,13 +12,13 @@ namespace Lumina.Infrastructure.UnitTests.Common.Networking;
public class PublicHostValidatorTests
{
[Theory]
[InlineData("coverartarchive.org")] // a public host name
[InlineData("example.com")] // a public host name
[InlineData("8.8.8.8")] // a public IPv4 address
[InlineData("1.1.1.1")] // a public IPv4 address
[InlineData("172.15.0.1")] // the address just below the private class B range
[InlineData("172.32.0.1")] // the address just above the private class B range
[InlineData("2606:4700:4700::1111")] // a public IPv6 address
[InlineData("coverartarchive.org")] // A public host name.
[InlineData("example.com")] // A public host name.
[InlineData("8.8.8.8")] // A public IPv4 address.
[InlineData("1.1.1.1")] // A public IPv4 address.
[InlineData("172.15.0.1")] // The address just below the private class B range.
[InlineData("172.32.0.1")] // The address just above the private class B range.
[InlineData("2606:4700:4700::1111")] // A public IPv6 address.
public void IsPublicHost_WhenTheHostIsPublic_ShouldReturnTrue(string host)
{
// Act
@@ -29,24 +29,24 @@ public class PublicHostValidatorTests
}
[Theory]
[InlineData("")] // an empty host
[InlineData(" ")] // only white space
[InlineData("localhost")] // the loopback host name
[InlineData("LOCALHOST")] // the loopback host name, upper cased
[InlineData("127.0.0.1")] // the IPv4 loopback address
[InlineData("::1")] // the IPv6 loopback address
[InlineData("[::1]")] // the IPv6 loopback address, bracketed like a URI host
[InlineData("0.0.0.0")] // the unspecified IPv4 address
[InlineData("[::]")] // the unspecified IPv6 address
[InlineData("169.254.169.254")] // the link local cloud metadata endpoint
[InlineData("10.0.0.5")] // a private class A address
[InlineData("172.16.0.1")] // the lower bound of the private class B range
[InlineData("172.31.255.255")] // the upper bound of the private class B range
[InlineData("192.168.1.10")] // a private class C address
[InlineData("100.64.0.1")] // the lower bound of the carrier grade NAT range
[InlineData("100.127.255.255")] // the upper bound of the carrier grade NAT range
[InlineData("fc00::1")] // the IPv6 unique local range
[InlineData("fe80::1")] // the IPv6 link local range
[InlineData("")] // An empty host.
[InlineData(" ")] // Only white space.
[InlineData("localhost")] // The loopback host name.
[InlineData("LOCALHOST")] // The loopback host name, upper cased.
[InlineData("127.0.0.1")] // The IPv4 loopback address.
[InlineData("::1")] // The IPv6 loopback address.
[InlineData("[::1]")] // The IPv6 loopback address, bracketed like a URI host.
[InlineData("0.0.0.0")] // The unspecified IPv4 address.
[InlineData("[::]")] // The unspecified IPv6 address.
[InlineData("169.254.169.254")] // The link local cloud metadata endpoint.
[InlineData("10.0.0.5")] // A private class A address.
[InlineData("172.16.0.1")] // The lower bound of the private class B range.
[InlineData("172.31.255.255")] // The upper bound of the private class B range.
[InlineData("192.168.1.10")] // A private class C address.
[InlineData("100.64.0.1")] // The lower bound of the carrier grade NAT range.
[InlineData("100.127.255.255")] // The upper bound of the carrier grade NAT range.
[InlineData("fc00::1")] // The IPv6 unique local range.
[InlineData("fe80::1")] // The IPv6 link local range.
public void IsPublicHost_WhenTheHostIsPrivateOrLocal_ShouldReturnFalse(string host)
{
// Act
@@ -96,8 +96,8 @@ public class ExceptionUtilitiesTests
List<Exception> result = [.. exception.GetInnerExceptions()];
// Assert
// the aggregate exception itself, its inner exceptions and their inners are traversed, and the first inner exception
// is also reachable through the regular InnerException chain, so it is yielded twice
// The aggregate exception itself, its inner exceptions and their inners are traversed, and the first inner exception
// is also reachable through the regular InnerException chain, so it is yielded twice.
Assert.Equal(6, result.Count);
Assert.Contains(result, inner => inner is AggregateException);
Assert.Equal(2, result.Count(inner => inner.Message == "first-inner"));
@@ -13,18 +13,18 @@ namespace Lumina.Infrastructure.UnitTests.Common.Utilities;
public class ImageTypeUtilitiesTests
{
[Theory]
[InlineData(ImageType.BMP, "bmp")] // bitmap image
[InlineData(ImageType.GIF, "gif")] // graphics interchange format
[InlineData(ImageType.PNG, "png")] // portable network graphics
[InlineData(ImageType.TIFF, "tiff")] // tagged image file format
[InlineData(ImageType.PICT, "pct")] // macintosh picture
[InlineData(ImageType.ICO, "ico")] // icon format
[InlineData(ImageType.PSD, "psd")] // photoshop document
[InlineData(ImageType.JPEG2000, "jp2")] // jpeg 2000
[InlineData(ImageType.AVIF, "avif")] // av1 image file format
[InlineData(ImageType.WEBP, "webp")] // web picture format
[InlineData(ImageType.TGA, "tga")] // truevision tga
[InlineData(ImageType.SVG, "svg")] // scalable vector graphics
[InlineData(ImageType.BMP, "bmp")] // Bitmap image.
[InlineData(ImageType.GIF, "gif")] // Graphics interchange format.
[InlineData(ImageType.PNG, "png")] // Portable network graphics.
[InlineData(ImageType.TIFF, "tiff")] // Tagged image file format.
[InlineData(ImageType.PICT, "pct")] // Macintosh picture.
[InlineData(ImageType.ICO, "ico")] // Icon format.
[InlineData(ImageType.PSD, "psd")] // Photoshop document.
[InlineData(ImageType.JPEG2000, "jp2")] // JPEG 2000.
[InlineData(ImageType.AVIF, "avif")] // AV1 image file format.
[InlineData(ImageType.WEBP, "webp")] // Web picture format.
[InlineData(ImageType.TGA, "tga")] // Truevision TGA.
[InlineData(ImageType.SVG, "svg")] // Scalable vector graphics.
public void ToFileExtension_WhenTypeIsRecognized_ShouldReturnConventionalExtension(ImageType imageType, string expectedExtension)
{
// Act
@@ -35,9 +35,9 @@ public class ImageTypeUtilitiesTests
}
[Theory]
[InlineData(ImageType.JPEG)] // joint photographic experts group
[InlineData(ImageType.JPEG_CANON)] // canon-specific jpeg
[InlineData(ImageType.JPEG_UNKNOWN)] // unknown jpeg
[InlineData(ImageType.JPEG)] // Joint photographic experts group.
[InlineData(ImageType.JPEG_CANON)] // Canon-specific JPEG.
[InlineData(ImageType.JPEG_UNKNOWN)] // Unknown JPEG.
public void ToFileExtension_WhenTypeIsAnyJpeg_ShouldReturnJpg(ImageType imageType)
{
// Act
@@ -33,7 +33,7 @@ public class EncryptionSettingsDtoValidatorTests
{
// Arrange
EncryptionSettingsDto model = _fixture.Build<EncryptionSettingsDto>()
.With(x => x.SecretKey, "dGhpcyBpcyBhIHZhbGlkIGJhc2U2NCBzdHJpbmc=") // "this is a valid base64 string" in base64
.With(x => x.SecretKey, "dGhpcyBpcyBhIHZhbGlkIGJhc2U2NCBzdHJpbmc=") // "this is a valid base64 string" in base64.
.Create();
// Act
@@ -75,8 +75,8 @@ public class ThemeEngineOptionsDtoValidatorTests
}
[Theory]
[InlineData(0L)] // zero, not positive
[InlineData(-1L)] // negative
[InlineData(0L)] // Zero, not positive.
[InlineData(-1L)] // Negative.
public void Validate_WhenMaxArchiveBytesIsNotPositive_ShouldHaveValidationError(long maxArchiveBytes)
{
// Arrange
@@ -91,8 +91,8 @@ public class ThemeEngineOptionsDtoValidatorTests
}
[Theory]
[InlineData(0L)] // zero, not positive
[InlineData(-1L)] // negative
[InlineData(0L)] // Zero, not positive.
[InlineData(-1L)] // Negative.
public void Validate_WhenMaxExpandedBytesIsNotPositive_ShouldHaveValidationError(long maxExpandedBytes)
{
// Arrange
@@ -107,8 +107,8 @@ public class ThemeEngineOptionsDtoValidatorTests
}
[Theory]
[InlineData(0L)] // zero, not positive
[InlineData(-1L)] // negative
[InlineData(0L)] // Zero, not positive.
[InlineData(-1L)] // Negative.
public void Validate_WhenMaxSingleFileBytesIsNotPositive_ShouldHaveValidationError(long maxSingleFileBytes)
{
// Arrange
@@ -123,8 +123,8 @@ public class ThemeEngineOptionsDtoValidatorTests
}
[Theory]
[InlineData(0)] // zero, not positive
[InlineData(-1)] // negative
[InlineData(0)] // Zero, not positive.
[InlineData(-1)] // Negative.
public void Validate_WhenMaxEntriesIsNotPositive_ShouldHaveValidationError(int maxEntries)
{
// Arrange
@@ -78,9 +78,9 @@ public class TranscodingSettingsDtoValidatorTests : IDisposable
}
[Theory]
[InlineData(null)] // a missing ffmpeg path
[InlineData("")] // an empty ffmpeg path
[InlineData(" ")] // a whitespace ffmpeg path
[InlineData(null)] // A missing ffmpeg path.
[InlineData("")] // An empty ffmpeg path.
[InlineData(" ")] // A whitespace ffmpeg path.
public void Validate_WhenFfmpegPathIsEmpty_ShouldHaveFfmpegPathCannotBeEmptyError(string? ffmpegPath)
{
// Arrange
@@ -94,8 +94,8 @@ public class TranscodingSettingsDtoValidatorTests : IDisposable
}
[Theory]
[InlineData(0)] // a job count of zero disables normalization
[InlineData(-1)] // a negative job count disables normalization
[InlineData(0)] // A job count of zero disables normalization.
[InlineData(-1)] // A negative job count disables normalization.
public void Validate_WhenMaxConcurrentJobsIsNotPositive_ShouldHaveMaxConcurrentJobsMustBePositiveError(int maxConcurrentJobs)
{
// Arrange
@@ -136,8 +136,8 @@ public class TranscodingSettingsDtoValidatorTests : IDisposable
}
[Theory]
[InlineData(0)] // a per-user job count of zero never admits a normalization
[InlineData(-1)] // a negative per-user job count never admits a normalization
[InlineData(0)] // A per-user job count of zero never admits a normalization.
[InlineData(-1)] // A negative per-user job count never admits a normalization.
public void Validate_WhenMaxConcurrentJobsPerUserIsNotPositive_ShouldHaveMaxConcurrentJobsPerUserMustBePositiveError(int maxConcurrentJobsPerUser)
{
// Arrange
@@ -178,8 +178,8 @@ public class TranscodingSettingsDtoValidatorTests : IDisposable
}
[Theory]
[InlineData(0)] // a cache with no capacity cannot hold a normalized track
[InlineData(-1)] // a negative cache size is not a capacity
[InlineData(0)] // A cache with no capacity cannot hold a normalized track.
[InlineData(-1)] // A negative cache size is not a capacity.
public void Validate_WhenMaxCacheBytesIsNotPositive_ShouldHaveMaxCacheBytesMustBePositiveError(long maxCacheBytes)
{
// Arrange
@@ -193,8 +193,8 @@ public class TranscodingSettingsDtoValidatorTests : IDisposable
}
[Theory]
[InlineData(0)] // a job timeout of zero stops every job immediately
[InlineData(-1)] // a negative job timeout stops every job immediately
[InlineData(0)] // A job timeout of zero stops every job immediately.
[InlineData(-1)] // A negative job timeout stops every job immediately.
public void Validate_WhenJobTimeoutSecondsIsNotPositive_ShouldHaveJobTimeoutMustBePositiveError(int jobTimeoutSeconds)
{
// Arrange
@@ -235,8 +235,8 @@ public class TranscodingSettingsDtoValidatorTests : IDisposable
}
[Theory]
[InlineData(0)] // an eviction grace of zero protects nothing
[InlineData(-1)] // a negative eviction grace protects nothing
[InlineData(0)] // An eviction grace of zero protects nothing.
[InlineData(-1)] // A negative eviction grace protects nothing.
public void Validate_WhenEvictionGraceSecondsIsNotPositive_ShouldHaveEvictionGraceSecondsMustBePositiveError(int evictionGraceSeconds)
{
// Arrange
@@ -386,8 +386,8 @@ public class TranscodingSettingsDtoValidatorTests : IDisposable
}
[Theory]
[InlineData(null)] // no configured directory, so the default temporary directory is used
[InlineData(" ")] // a whitespace directory, so the default temporary directory is used
[InlineData(null)] // No configured directory, so the default temporary directory is used.
[InlineData(" ")] // A whitespace directory, so the default temporary directory is used.
public void Validate_WhenCacheDirectoryIsNotConfigured_ShouldOnlyValidateTheDefaultDirectory(string? cacheDirectory)
{
// Arrange
@@ -59,17 +59,17 @@ public class JwtTokenGeneratorTests
JwtSecurityToken jwtToken = tokenHandler.ReadJwtToken(token);
// verify token properties
// Verify token properties.
Assert.Equal(_jwtSettings.Issuer, jwtToken.Issuer);
Assert.Single(jwtToken.Audiences, _jwtSettings.Audience);
Assert.Equal(_fixedUtcNow.AddMinutes(_jwtSettings.ExpiryMinutes), jwtToken.ValidTo);
// verify claims
// Verify claims.
Assert.Contains(jwtToken.Claims, c => c.Type == JwtRegisteredClaimNames.Sub && c.Value == userId);
Assert.Contains(jwtToken.Claims, c => c.Type == JwtRegisteredClaimNames.UniqueName && c.Value == username);
Assert.Contains(jwtToken.Claims, c => c.Type == JwtRegisteredClaimNames.Jti && c.Value == userId);
// verify the token is actually valid
// Verify the token is actually valid.
TokenValidationParameters validationParameters = new()
{
ValidateIssuerSigningKey = true,
@@ -80,7 +80,7 @@ public class JwtTokenGeneratorTests
ValidAudience = _jwtSettings.Audience,
ValidateLifetime = true,
ClockSkew = TimeSpan.Zero,
// override the current time to match our fixed test time
// Override the current time to match our fixed test time.
LifetimeValidator = (notBefore, expires, token, parameters) => expires > _fixedUtcNow
};
@@ -26,7 +26,7 @@ public class QRCodeGeneratorTests
// Assert
Assert.StartsWith("data:image/png;base64,", result);
Assert.True(IsBase64String(result[22..])); // skip "data:image/png;base64,"
Assert.True(IsBase64String(result[22..])); // Skip "data:image/png;base64,".
}
[Fact]
@@ -112,7 +112,7 @@ public class QRCodeGeneratorTests
{
// Arrange
(string username, _) = QRCodeGeneratorFixture.CreateQrCodeTestData();
byte[] shortSecret = [1]; // minimum length for Base32 encoding
byte[] shortSecret = [1]; // Minimum length for Base32 encoding.
// Act
string result = _sut.GenerateQrCodeDataUri(username, shortSecret);
@@ -57,7 +57,7 @@ public class TokenGeneratorTests
string token = _sut.GenerateToken();
// Assert
// 32 bytes in Base64 without padding should be 43 characters
// 32 bytes in Base64 without padding should be 43 characters.
Assert.Equal(43, token.Length);
}
}
@@ -56,10 +56,10 @@ public class TotpTokenGeneratorTests
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData("123456")] // Valid format but wrong token
[InlineData("abcdef")] // Invalid format
[InlineData("12345")] // Too short
[InlineData("1234567")] // Too long
[InlineData("123456")] // Valid format but wrong token.
[InlineData("abcdef")] // Invalid format.
[InlineData("12345")] // Too short.
[InlineData("1234567")] // Too long.
public void ValidateToken_WhenTokenIsInvalid_ShouldReturnFalse(string invalidToken)
{
// Arrange
@@ -95,6 +95,6 @@ public class TotpTokenGeneratorTests
byte[] secret = _sut.GenerateSecret();
// Assert
Assert.Equal(20, secret.Length); // standard TOTP secret length
Assert.Equal(20, secret.Length); // Standard TOTP secret length.
}
}
@@ -315,9 +315,9 @@ public class MusicArtworkServiceTests
}
[Theory]
[InlineData("cover")] // a name without an extension falls back to the .img extension
[InlineData("")] // an empty name falls back to the .img extension
[InlineData(null)] // a null name falls back to the .img extension
[InlineData("cover")] // A name without an extension falls back to the .img extension.
[InlineData("")] // An empty name falls back to the .img extension.
[InlineData(null)] // A null name falls back to the .img extension.
public async Task SaveAlbumArtworkAsync_WhenTheUploadedFileNameHasNoExtension_ShouldBufferTheUploadWithTheImgExtension(string? fileName)
{
// Arrange
@@ -427,9 +427,9 @@ public class MusicArtworkServiceTests
}
[Theory]
[InlineData(null)] // a null path is a no-op
[InlineData("")] // an empty path is a no-op
[InlineData(" ")] // a whitespace path is a no-op
[InlineData(null)] // A null path is a no-op.
[InlineData("")] // An empty path is a no-op.
[InlineData(" ")] // A whitespace path is a no-op.
public void DeleteStoredArtwork_WhenThePathIsMissing_ShouldReturnDeletedWithoutTouchingTheFileSystem(string? artworkRelativePath)
{
// Act
@@ -12,12 +12,12 @@ namespace Lumina.Infrastructure.UnitTests.Core.MediaLibrary.AudioLibrary.MusicLi
public class AudioContainerResolverTests
{
[Theory]
[InlineData(null, null)] // an absent mime type leaves the container unrecognized
[InlineData("", null)] // an empty mime type leaves the container unrecognized
[InlineData(" ", null)] // a blank mime type leaves the container unrecognized
[InlineData("taglib/wav", "WAV")] // the taglib prefix is dropped and the container is upper cased
[InlineData("taglib/png", "PNG")] // a container the resolver has no dedicated parser for still yields its name
[InlineData("audio/x-wavpack", "X-WAVPACK")] // the last segment of a standard mime type names the container
[InlineData(null, null)] // An absent mime type leaves the container unrecognized.
[InlineData("", null)] // An empty mime type leaves the container unrecognized.
[InlineData(" ", null)] // A blank mime type leaves the container unrecognized.
[InlineData("taglib/wav", "WAV")] // The taglib prefix is dropped and the container is upper cased.
[InlineData("taglib/png", "PNG")] // A container the resolver has no dedicated parser for still yields its name.
[InlineData("audio/x-wavpack", "X-WAVPACK")] // The last segment of a standard mime type names the container.
public void ResolveFromMimeType_WhenCalled_ShouldReturnTheContainerNamedByTheMimeType(string? mimeType, string? expectedContainer)
{
// Act
@@ -143,10 +143,10 @@ public class PlaybackDeliveryHandleServiceTests
}
[Theory]
[InlineData(null)] // an absent handle cannot address a delivery
[InlineData("")] // an empty handle cannot address a delivery
[InlineData(" ")] // a whitespace handle cannot address a delivery
[InlineData("0123456789abcdef0123456789abcdef")] // a well formed handle that was never issued
[InlineData(null)] // An absent handle cannot address a delivery.
[InlineData("")] // An empty handle cannot address a delivery.
[InlineData(" ")] // A whitespace handle cannot address a delivery.
[InlineData("0123456789abcdef0123456789abcdef")] // A well formed handle that was never issued.
public void GetDelivery_WhenTheHandleIsMissingOrUnknown_ShouldReturnPlaybackDeliveryNotFoundError(string? deliveryId)
{
// Act
@@ -21,13 +21,13 @@ public class PlaybackFormatCatalogTests
// Arrange
(string Container, string Codec)[] expectedPairs =
[
("MP4", "AAC"), // the preferred container of the preferred codec
("AAC", "AAC"), // the second container of the preferred codec
("OGG", "OPUS"), // the preferred lossy codec after AAC
("MP3", "MP3"), // the compatibility codec
("OGG", "VORBIS"), // the second lossy codec in OGG
("FLAC", "FLAC"), // the lossless codec
("WAV", "PCM") // the uncompressed codec
("MP4", "AAC"), // The preferred container of the preferred codec.
("AAC", "AAC"), // The second container of the preferred codec.
("OGG", "OPUS"), // The preferred lossy codec after AAC.
("MP3", "MP3"), // The compatibility codec.
("OGG", "VORBIS"), // The second lossy codec in OGG.
("FLAC", "FLAC"), // The lossless codec.
("WAV", "PCM") // The uncompressed codec.
];
// Act
@@ -80,7 +80,7 @@ public class PlaybackFormatCatalogTests
Assert.True(result.TryGetValue(expectedEntry.Key, out IReadOnlyList<string>? containers));
Assert.Equal(expectedEntry.Value, containers);
}
Assert.Equal(["MP4", "AAC"], result["AAC"]); // the preferred codec has two producible containers, in preference order
Assert.Equal(["MP4", "AAC"], result["AAC"]); // The preferred codec has two producible containers, in preference order.
Assert.Equal(["OGG"], result["OPUS"]);
Assert.Equal(["OGG"], result["VORBIS"]);
Assert.Equal(["MP3"], result["MP3"]);
@@ -130,9 +130,9 @@ public class PlaybackFormatCatalogTests
}
[Theory]
[InlineData("mp4/aac", "MP4", "AAC")] // the canonical pair in lower case
[InlineData("Mp4/Aac", "MP4", "AAC")] // the canonical pair in mixed case
[InlineData("aac/aac", "AAC", "AAC")] // the second format in the catalog, in lower case
[InlineData("mp4/aac", "MP4", "AAC")] // The canonical pair in lower case.
[InlineData("Mp4/Aac", "MP4", "AAC")] // The canonical pair in mixed case.
[InlineData("aac/aac", "AAC", "AAC")] // The second format in the catalog, in lower case.
public void FormatsByPair_WhenLookedUpWithDifferentCasing_ShouldReturnTheCatalogFormat(string pairKey, string expectedContainer, string expectedCodec)
{
// Act
@@ -167,11 +167,11 @@ public class PlaybackFormatCatalogTests
}
[Theory]
[InlineData(null, null, "/")] // both parts are absent
[InlineData("", "", "/")] // both parts are empty
[InlineData(" ", " ", "/")] // both parts are white space
[InlineData(null, "aac", "/AAC")] // only the container is absent
[InlineData("mp4", null, "MP4/")] // only the codec is absent
[InlineData(null, null, "/")] // Both parts are absent.
[InlineData("", "", "/")] // Both parts are empty.
[InlineData(" ", " ", "/")] // Both parts are white space.
[InlineData(null, "aac", "/AAC")] // Only the container is absent.
[InlineData("mp4", null, "MP4/")] // Only the codec is absent.
public void BuildPairKey_WhenAContainerOrCodecIsNullOrEmpty_ShouldProduceTheSlashSeparatedFormWithoutThrowing(string? container, string? codec, string expectedKey)
{
// Act
@@ -122,16 +122,16 @@ public class PlaybackFormatServiceTests
}
[Theory]
[InlineData("MP3", "MPEG-1 Layer 3", "MP3")] // the free form description of an MPEG-1 Layer 3 stream
[InlineData("MP3", "MP3", "MP3")] // a codec that is already named canonically
[InlineData("FLAC", "Flac", "FLAC")] // the description of a FLAC stream
[InlineData("OGG", "Vorbis I", "VORBIS")] // the description of a Vorbis stream
[InlineData("OGG", "Opus", "OPUS")] // the description of an Opus stream
[InlineData("MP4", "Apple Lossless", "ALAC")] // the description of an Apple Lossless stream
[InlineData("AAC", "MPEG-4 AAC", "AAC")] // a description naming both MPEG and AAC is AAC, not MP3
[InlineData("WAV", "PCM", "PCM")] // the description of an uncompressed stream
[InlineData("WAV", "Uncompressed", "PCM")] // another description of an uncompressed stream
[InlineData("WMA", "Windows Media Audio", "WMA")] // the description of a Windows Media stream
[InlineData("MP3", "MPEG-1 Layer 3", "MP3")] // The free form description of an MPEG-1 Layer 3 stream.
[InlineData("MP3", "MP3", "MP3")] // A codec that is already named canonically.
[InlineData("FLAC", "Flac", "FLAC")] // The description of a FLAC stream.
[InlineData("OGG", "Vorbis I", "VORBIS")] // The description of a Vorbis stream.
[InlineData("OGG", "Opus", "OPUS")] // The description of an Opus stream.
[InlineData("MP4", "Apple Lossless", "ALAC")] // The description of an Apple Lossless stream.
[InlineData("AAC", "MPEG-4 AAC", "AAC")] // A description naming both MPEG and AAC is AAC, not MP3.
[InlineData("WAV", "PCM", "PCM")] // The description of an uncompressed stream.
[InlineData("WAV", "Uncompressed", "PCM")] // Another description of an uncompressed stream.
[InlineData("WMA", "Windows Media Audio", "WMA")] // The description of a Windows Media stream.
public void DecideDelivery_WhenTheStoredCodecDescriptionIsRecognizable_ShouldCanonicalizeItAndDirectPlay(string container, string codecDescription, string canonicalCodec)
{
// Arrange
@@ -148,9 +148,9 @@ public class PlaybackFormatServiceTests
}
[Theory]
[InlineData("MPEG-1 Layer 2")] // MP2 shares the MP3 container but an MP3 decoder cannot decode it
[InlineData("MPEG-1 Layer 1")] // MP1 shares the MP3 container but an MP3 decoder cannot decode it
[InlineData("MPEG-4 Audio")] // a description that names no decodable codec is not mistaken for MP3
[InlineData("MPEG-1 Layer 2")] // MP2 shares the MP3 container but an MP3 decoder cannot decode it.
[InlineData("MPEG-1 Layer 1")] // MP1 shares the MP3 container but an MP3 decoder cannot decode it.
[InlineData("MPEG-4 Audio")] // A description that names no decodable codec is not mistaken for MP3.
public void DecideDelivery_WhenAnMpegDescriptionIsNotLayer3_ShouldReturnTranscode(string codecDescription)
{
// Arrange
@@ -166,9 +166,9 @@ public class PlaybackFormatServiceTests
}
[Theory]
[InlineData(null, null)] // an absent probe result names no codec
[InlineData("", "")] // an empty probe result names no codec
[InlineData("MP3", "AC-3")] // a codec description the server does not recognize
[InlineData(null, null)] // An absent probe result names no codec.
[InlineData("", "")] // An empty probe result names no codec.
[InlineData("MP3", "AC-3")] // A codec description the server does not recognize.
public void DecideDelivery_WhenTheStoredFormatIsUnknown_ShouldReturnTranscode(string? container, string? codec)
{
// Arrange
@@ -92,8 +92,8 @@ public class TrackNormalizationServiceTests : IDisposable
}
[Theory]
[InlineData(true)] // the source file length no longer matches the declared delivery
[InlineData(false)] // the source file modification time no longer matches the declared delivery
[InlineData(true)] // The source file length no longer matches the declared delivery.
[InlineData(false)] // The source file modification time no longer matches the declared delivery.
public async Task GetOrCreateNormalizedTrackAsync_WhenTheSourceFileChangedSinceTheDeliveryWasDeclared_ShouldReturnPlaybackDeliveryChangedError(bool isLengthChanged)
{
// Arrange
@@ -74,8 +74,8 @@ public class TranscodingToolchainStatusTests
}
[Theory]
[InlineData("AAC")] // an encoder name in upper case
[InlineData("Aac")] // an encoder name in mixed case
[InlineData("AAC")] // An encoder name in upper case.
[InlineData("Aac")] // An encoder name in mixed case.
public void RecordMissingEncoders_WhenTheNameDiffersInCase_ShouldReportTheEncoderUnavailable(string missingEncoderName)
{
// Act
@@ -26,8 +26,8 @@ public class MusicLibraryPathStructureTests
}
[Theory]
[InlineData('\\', @"C:\Music\Queen\A Night at the Opera", @"C:\Music\Queen\A Night at the Opera\Bohemian Rhapsody.flac")] // Windows separated path
[InlineData('/', "/music/queen/a-night-at-the-opera", "/music/queen/a-night-at-the-opera/bohemian-rhapsody.flac")] // Unix separated path
[InlineData('\\', @"C:\Music\Queen\A Night at the Opera", @"C:\Music\Queen\A Night at the Opera\Bohemian Rhapsody.flac")] // Windows separated path.
[InlineData('/', "/music/queen/a-night-at-the-opera", "/music/queen/a-night-at-the-opera/bohemian-rhapsody.flac")] // Unix separated path.
public void GetAlbumDirectory_WhenTheTrackIsInTheAlbumDirectory_ShouldReturnTheTrackDirectory(char separator, string albumDirectory, string trackPath)
{
// Arrange
@@ -41,14 +41,14 @@ public class MusicLibraryPathStructureTests
}
[Theory]
[InlineData('\\', "Disc 1")] // canonical disc directory name, Windows separated path
[InlineData('\\', "disc 2")] // lowercase disc directory name, Windows separated path
[InlineData('\\', "CD3")] // compact disc directory name, Windows separated path
[InlineData('\\', "disk4")] // disk directory name, Windows separated path
[InlineData('/', "Disc 1")] // canonical disc directory name, Unix separated path
[InlineData('/', "disc 2")] // lowercase disc directory name, Unix separated path
[InlineData('/', "CD3")] // compact disc directory name, Unix separated path
[InlineData('/', "disk4")] // disk directory name, Unix separated path
[InlineData('\\', "Disc 1")] // Canonical disc directory name, Windows separated path.
[InlineData('\\', "disc 2")] // Lowercase disc directory name, Windows separated path.
[InlineData('\\', "CD3")] // Compact disc directory name, Windows separated path.
[InlineData('\\', "disk4")] // Disk directory name, Windows separated path.
[InlineData('/', "Disc 1")] // Canonical disc directory name, Unix separated path.
[InlineData('/', "disc 2")] // Lowercase disc directory name, Unix separated path.
[InlineData('/', "CD3")] // Compact disc directory name, Unix separated path.
[InlineData('/', "disk4")] // Disk directory name, Unix separated path.
public void GetAlbumDirectory_WhenTheTrackIsInADiscDirectory_ShouldReturnTheParentAlbumDirectory(char separator, string discDirectoryName)
{
// Arrange
@@ -64,8 +64,8 @@ public class MusicLibraryPathStructureTests
}
[Theory]
[InlineData('\\')] // Windows separated path
[InlineData('/')] // Unix separated path
[InlineData('\\')] // Windows separated path.
[InlineData('/')] // Unix separated path.
public void GetAlbumDirectory_WhenTheDirectoryIsNotADiscDirectory_ShouldReturnTheTrackDirectory(char separator)
{
// Arrange
@@ -93,8 +93,8 @@ public class MusicLibraryPathStructureTests
}
[Theory]
[InlineData('\\')] // Windows separated path
[InlineData('/')] // Unix separated path
[InlineData('\\')] // Windows separated path.
[InlineData('/')] // Unix separated path.
public void GetAlbumDirectory_WhenThePathHasNoDirectory_ShouldReturnTheProvidedPath(char separator)
{
// Arrange
@@ -109,10 +109,10 @@ public class MusicLibraryPathStructureTests
}
[Theory]
[InlineData('\\', "Album")] // canonical release type directory, Windows separated path
[InlineData('\\', "album")] // lowercase release type directory, Windows separated path
[InlineData('/', "Album")] // canonical release type directory, Unix separated path
[InlineData('/', "album")] // lowercase release type directory, Unix separated path
[InlineData('\\', "Album")] // Canonical release type directory, Windows separated path.
[InlineData('\\', "album")] // Lowercase release type directory, Windows separated path.
[InlineData('/', "Album")] // Canonical release type directory, Unix separated path.
[InlineData('/', "album")] // Lowercase release type directory, Unix separated path.
public void GetReleaseTypeDirectoryName_WhenTheParentOfTheAlbumDirectoryIsAReleaseType_ShouldReturnIt(char separator, string releaseTypeDirectoryName)
{
// Arrange
@@ -127,8 +127,8 @@ public class MusicLibraryPathStructureTests
}
[Theory]
[InlineData('\\')] // Windows separated path
[InlineData('/')] // Unix separated path
[InlineData('\\')] // Windows separated path.
[InlineData('/')] // Unix separated path.
public void GetReleaseTypeDirectoryName_WhenTheAlbumIsMultiDisc_ShouldReturnTheReleaseTypeDirectory(char separator)
{
// Arrange
@@ -143,8 +143,8 @@ public class MusicLibraryPathStructureTests
}
[Theory]
[InlineData('\\')] // Windows separated path
[InlineData('/')] // Unix separated path
[InlineData('\\')] // Windows separated path.
[InlineData('/')] // Unix separated path.
public void GetReleaseTypeDirectoryName_WhenTheParentOfTheAlbumDirectoryIsNotAReleaseType_ShouldReturnNull(char separator)
{
// Arrange
@@ -159,10 +159,10 @@ public class MusicLibraryPathStructureTests
}
[Theory]
[InlineData('\\', "Live")] // release type name used as the artist directory name, Windows separated path
[InlineData('/', "Live")] // release type name used as the artist directory name, Unix separated path
[InlineData('\\', "42")] // numeric artist directory name, Windows separated path
[InlineData('/', "42")] // numeric artist directory name, Unix separated path
[InlineData('\\', "Live")] // Release type name used as the artist directory name, Windows separated path.
[InlineData('/', "Live")] // Release type name used as the artist directory name, Unix separated path.
[InlineData('\\', "42")] // Numeric artist directory name, Windows separated path.
[InlineData('/', "42")] // Numeric artist directory name, Unix separated path.
public void GetReleaseTypeDirectoryName_WhenTheArtistDirectoryIsNamedLikeAReleaseType_ShouldReturnNull(char separator, string artistName)
{
// Arrange
@@ -178,8 +178,8 @@ public class MusicLibraryPathStructureTests
}
[Theory]
[InlineData('\\')] // Windows separated path
[InlineData('/')] // Unix separated path
[InlineData('\\')] // Windows separated path.
[InlineData('/')] // Unix separated path.
public void GetReleaseTypeDirectoryName_WhenAReleaseTypeDirectoryDiffersFromTheArtistDirectory_ShouldReturnIt(char separator)
{
// Arrange
@@ -103,7 +103,7 @@ public class MusicMediaLibraryScanMetadataEnricherTests
_userId = _userIdFixture.Create();
_libraryId = _libraryIdFixture.Create();
// the configured providers are registered under the plugin Ids they are configured with, the way the host registers plugin provided services
// The configured providers are registered under the plugin Ids they are configured with, the way the host registers plugin provided services.
Guid pluginAId = Guid.NewGuid();
Guid pluginBId = Guid.NewGuid();
_mockMetadataConfigurationRepository.GetByLibraryIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
@@ -153,7 +153,7 @@ public class MusicMediaLibraryScanMetadataEnricherTests
await _sut.EnrichAsync(_libraryId, _scanId, _userId, CancellationToken.None);
// Assert
// the total is the sum of the artists, the albums and the tracks, and the final update reaches it
// The total is the sum of the artists, the albums and the tracks, and the final update reaches it.
await _mockDomainEventPublisher.Received(1).PublishAsync(Arg.Is<LibraryScanJobProgressChangedDomainEvent>(domainEvent =>
domainEvent.MediaLibraryScanCompositeId.ScanId == _scanId
&& domainEvent.Progress.CompletedItems == 0
@@ -215,7 +215,7 @@ public class MusicMediaLibraryScanMetadataEnricherTests
ArtistEntity artist = _artistEntityFixture.Create(libraryId: _libraryId.Value);
_mockArtistRepository.GetArtistsNeedingMetadataAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(Result<IReadOnlyList<ArtistEntity>>.Success([artist]), Result<IReadOnlyList<ArtistEntity>>.Success([]));
// a genre without a name is usable as metadata, but makes the domain conversion of the whole metadata fail
// A genre without a name is usable as metadata, but makes the domain conversion of the whole metadata fail.
_mockProviderA.GetMetadataAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>())
.Returns((MetadataDto?)CreateApplicableArtistMetadata("Local Artist", genres: [_genreDtoFixture.Create(includeName: false)]));
_mockProviderB.GetMetadataAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>())
@@ -64,7 +64,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
_mockServiceProvider.GetService(typeof(IUnitOfWork)).Returns(_mockUnitOfWork);
// the job resolves the artwork enricher of the loaded library type from the service scope, so the music enricher must be available
// The job resolves the artwork enricher of the loaded library type from the service scope, so the music enricher must be available.
_mockArtworkEnricher = Substitute.For<IMediaLibraryScanArtworkEnricher>();
_mockArtworkEnricher.SupportedLibraryType.Returns(LibraryType.Music);
_mockArtworkEnricher.EnrichAsync(Arg.Any<LibraryId>(), Arg.Any<ScanId>(), Arg.Any<UserId>(), Arg.Any<CancellationToken>())
@@ -349,7 +349,7 @@ public class MediaLibraryScanHashJobTests
// Assert
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
// the initial progress and the progress published from the hashing callback are both reported
// The initial progress and the progress published from the hashing callback are both reported.
await _mockDomainEventPublisher.Received(2).PublishAsync(Arg.Is<LibraryScanJobProgressChangedDomainEvent>(domainEvent => domainEvent.LibraryId == _libraryId), Arg.Any<CancellationToken>());
}
@@ -20,7 +20,7 @@ public class MediaLibraryScanProgressHubTests
[Fact]
public async Task SubscribeToScan_WhenCalled_ShouldAddTheConnectionToTheGroupOfTheAuthenticatedUser()
{
// Arrange.
// Arrange
MediaLibraryScanProgressHub sut = new();
HubCallerContext context = Substitute.For<HubCallerContext>();
context.ConnectionId.Returns("connection-1");
@@ -33,17 +33,17 @@ public class MediaLibraryScanProgressHubTests
ClaimsPrincipal user = new(new ClaimsIdentity([new Claim(ClaimTypes.NameIdentifier, userId.ToString())]));
context.User.Returns(user);
// Act.
// Act
await sut.SubscribeToScan(scanId);
// Assert.
// Assert
await groupManager.Received(1).AddToGroupAsync("connection-1", $"{scanId}-{userId}", CancellationToken.None);
}
[Fact]
public async Task SubscribeToScan_WhenUserClaimIsMissing_ShouldNotAddTheConnectionToAnyGroup()
{
// Arrange.
// Arrange
MediaLibraryScanProgressHub sut = new();
HubCallerContext context = Substitute.For<HubCallerContext>();
context.ConnectionId.Returns("connection-1");
@@ -54,17 +54,17 @@ public class MediaLibraryScanProgressHubTests
ClaimsPrincipal user = new(new ClaimsIdentity());
context.User.Returns(user);
// Act.
// Act
await sut.SubscribeToScan(scanId);
// Assert.
// Assert
await groupManager.DidNotReceive().AddToGroupAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
}
[Fact]
public async Task SubscribeToScan_WhenUserIdClaimIsNotAGuid_ShouldNotAddTheConnectionToAnyGroup()
{
// Arrange.
// Arrange
MediaLibraryScanProgressHub sut = new();
HubCallerContext context = Substitute.For<HubCallerContext>();
context.ConnectionId.Returns("connection-1");
@@ -75,10 +75,10 @@ public class MediaLibraryScanProgressHubTests
ClaimsPrincipal user = new(new ClaimsIdentity([new Claim(ClaimTypes.NameIdentifier, "not-a-guid")]));
context.User.Returns(user);
// Act.
// Act
await sut.SubscribeToScan(scanId);
// Assert.
// Assert
await groupManager.DidNotReceive().AddToGroupAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
}
}
@@ -84,7 +84,7 @@ public class MediaLibraryScanProcessorJobTests : IDisposable
RegisterScan(firstScanId, LibraryScanJobStatus.Pending);
RegisterScan(secondScanId, LibraryScanJobStatus.Pending);
TaskCompletionSource<bool> releaseFirstScan = new(TaskCreationOptions.RunContinuationsAsynchronously);
// ExecutionStarted is signaled before the callback runs, and resumes the test on another thread, so the test waits for the callback itself to record the scan
// ExecutionStarted is signaled before the callback runs, and resumes the test on another thread, so the test waits for the callback itself to record the scan.
TaskCompletionSource firstScanRecorded = new(TaskCreationOptions.RunContinuationsAsynchronously);
List<Guid> startedScanIds = [];
FakeMediaLibraryScanDiscoveryJob firstRootJob = _mediaLibraryScanDiscoveryJobFixture.Create(onExecute: async _ =>
@@ -25,8 +25,8 @@ public class BookReaderEnablementCacheTests
}
[Theory]
[InlineData(true)] // reader enabled
[InlineData(false)] // reader disabled
[InlineData(true)] // Reader enabled.
[InlineData(false)] // Reader disabled.
public void Set_WhenCalled_ThenGetShouldReturnTheCachedValue(bool isEnabled)
{
// Arrange
@@ -126,8 +126,8 @@ public class ReadingContentSanitizerTests
}
[Theory]
[InlineData(true)] // preserve styles
[InlineData(false)] // strip styles
[InlineData(true)] // Preserve styles.
[InlineData(false)] // Strip styles.
public void Sanitize_WhenHtmlContainsActiveContent_ShouldStripItRegardlessOfTheStylePreference(bool shouldPreserveStyles)
{
// Arrange
@@ -145,9 +145,9 @@ public class ReadingContentSanitizerTests
}
[Theory]
[InlineData(null)] // null input
[InlineData("")] // empty input
[InlineData(" ")] // whitespace input
[InlineData(null)] // Null input.
[InlineData("")] // Empty input.
[InlineData(" ")] // Whitespace input.
public void Sanitize_WhenInputIsBlank_ShouldReturnEmptyString(string? html)
{
// Act
@@ -116,7 +116,7 @@ public class CryptographyServiceTests
public void Decrypt_WhenInputIsTooShort_ShouldThrowArgumentException()
{
// Arrange
string shortCiphertext = Convert.ToBase64String(new byte[8]); // less than required 16 bytes
string shortCiphertext = Convert.ToBase64String(new byte[8]); // Less than required 16 bytes.
// Act
Action act = () => _sut.Decrypt(shortCiphertext);
@@ -135,7 +135,7 @@ public class CryptographyServiceTests
// Decode the Base64 string, modify one byte, then re-encode.
byte[] encryptedBytes = Convert.FromBase64String(encrypted);
encryptedBytes[^1] ^= 0xFF; // flip all bits in the last byte
encryptedBytes[^1] ^= 0xFF; // Flip all bits in the last byte.
string corrupted = Convert.ToBase64String(encryptedBytes);
// Act
@@ -57,7 +57,7 @@ public class HashServiceTests
// Assert
Assert.NotNull(hash);
Assert.NotEmpty(hash);
// verify it's a valid Base64 string
// Verify it's a valid Base64 string.
Assert.NotNull(Convert.FromBase64String(hash));
}
@@ -92,8 +92,8 @@ public class HashServiceTests
[Theory]
[InlineData("")]
[InlineData("dGVzdA==")] // valid base64 but wrong length
[InlineData("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo=")] // valid base64 but wrong length
[InlineData("dGVzdA==")] // Valid base64 but wrong length.
[InlineData("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo=")] // Valid base64 but wrong length.
public void CheckStringAgainstHash_WhenHashIsInvalidLength_ShouldReturnFalse(string invalidHash)
{
// Arrange
@@ -31,7 +31,7 @@ public class ThemeMimeTypesTests
public void GetMimeType_WhenExtensionIsKnown_ShouldReturnMappedContentType(string filePath, string expectedContentType)
{
// Arrange
// filePath and expectedContentType are provided by the test data
// filePath and expectedContentType are provided by the test data.
// Act
string result = ThemeMimeTypes.GetMimeType(filePath);