mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Implements tests for commit dfd979ec1e
This commit is contained in:
1 parent
d8adf3c1b6
commit
968061e89a
111 files changed
+19955
-292
No files matched your search
+8
-4
@@ -125,9 +125,9 @@ public class GetAllUsersConsumptionStatisticsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
MediaKind mediaKind = MediaKind.MusicTrack;
|
||||
DateTime fromUtc = DateTime.UtcNow.AddDays(-10);
|
||||
DateTime toUtc = DateTime.UtcNow.AddDays(-1);
|
||||
string mediaKind = nameof(MediaKind.MusicTrack);
|
||||
string fromUtc = "2026-03-01T00:00:00Z";
|
||||
string toUtc = "2026-03-02T00:00:00Z";
|
||||
GetAllUsersConsumptionStatisticsQuery query = _getAllUsersConsumptionStatisticsQueryFixture.Create(
|
||||
libraryId: libraryId.ToString(),
|
||||
mediaKind: mediaKind,
|
||||
@@ -140,7 +140,11 @@ public class GetAllUsersConsumptionStatisticsQueryHandlerTests
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockConsumptionStatisticsRepository.Received(1).GetForAllUsersAsync(
|
||||
libraryId, mediaKind, fromUtc, toUtc, Arg.Any<CancellationToken>());
|
||||
libraryId,
|
||||
MediaKind.MusicTrack,
|
||||
Arg.Is<DateTime?>(value => value == new DateTime(2026, 3, 1, 0, 0, 0, DateTimeKind.Utc)),
|
||||
Arg.Is<DateTime?>(value => value == new DateTime(2026, 3, 2, 0, 0, 0, DateTimeKind.Utc)),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+28
-12
@@ -81,7 +81,7 @@ public class GetAllUsersConsumptionStatisticsQueryValidatorTests
|
||||
public void Validate_WhenMediaKindIsNone_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetAllUsersConsumptionStatisticsQuery query = _getAllUsersConsumptionStatisticsQueryFixture.Create(mediaKind: MediaKind.None);
|
||||
GetAllUsersConsumptionStatisticsQuery query = _getAllUsersConsumptionStatisticsQueryFixture.Create(mediaKind: nameof(MediaKind.None));
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
@@ -94,7 +94,7 @@ public class GetAllUsersConsumptionStatisticsQueryValidatorTests
|
||||
public void Validate_WhenMediaKindIsUndefined_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetAllUsersConsumptionStatisticsQuery query = _getAllUsersConsumptionStatisticsQueryFixture.Create(mediaKind: (MediaKind)99);
|
||||
GetAllUsersConsumptionStatisticsQuery query = _getAllUsersConsumptionStatisticsQueryFixture.Create(mediaKind: "999");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
@@ -104,11 +104,11 @@ public class GetAllUsersConsumptionStatisticsQueryValidatorTests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(MediaKind.MusicTrack)] // a kind supported by the current catalogues
|
||||
[InlineData(MediaKind.Book)] // another kind supported by the current catalogues
|
||||
[InlineData(MediaKind.Movie)] // a kind without a catalogue, still a defined kind
|
||||
[InlineData(MediaKind.Photo)] // a kind that every session counts for, still a defined kind
|
||||
public void Validate_WhenMediaKindIsDefined_ShouldNotHaveValidationError(MediaKind mediaKind)
|
||||
[InlineData(nameof(MediaKind.MusicTrack))] // a kind supported by the current catalogues
|
||||
[InlineData(nameof(MediaKind.Book))] // another kind supported by the current catalogues
|
||||
[InlineData(nameof(MediaKind.Movie))] // a kind without a catalogue, still a defined kind
|
||||
[InlineData(nameof(MediaKind.Photo))] // a kind that every session counts for, still a defined kind
|
||||
public void Validate_WhenMediaKindIsDefined_ShouldNotHaveValidationError(string mediaKind)
|
||||
{
|
||||
// Arrange
|
||||
GetAllUsersConsumptionStatisticsQuery query = _getAllUsersConsumptionStatisticsQueryFixture.Create(mediaKind: mediaKind);
|
||||
@@ -125,7 +125,7 @@ public class GetAllUsersConsumptionStatisticsQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetAllUsersConsumptionStatisticsQuery query = _getAllUsersConsumptionStatisticsQueryFixture.Create(
|
||||
fromUtc: DateTime.UtcNow.AddDays(-7),
|
||||
fromUtc: "2026-03-01T00:00:00Z",
|
||||
includeToUtc: false);
|
||||
|
||||
// Act
|
||||
@@ -140,7 +140,7 @@ public class GetAllUsersConsumptionStatisticsQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetAllUsersConsumptionStatisticsQuery query = _getAllUsersConsumptionStatisticsQueryFixture.Create(
|
||||
toUtc: DateTime.UtcNow,
|
||||
toUtc: "2026-03-02T00:00:00Z",
|
||||
includeFromUtc: false);
|
||||
|
||||
// Act
|
||||
@@ -154,7 +154,7 @@ public class GetAllUsersConsumptionStatisticsQueryValidatorTests
|
||||
public void Validate_WhenBothDateRangeBoundsAreEqual_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
DateTime bound = DateTime.UtcNow;
|
||||
string bound = "2026-03-02T00:00:00Z";
|
||||
GetAllUsersConsumptionStatisticsQuery query = _getAllUsersConsumptionStatisticsQueryFixture.Create(fromUtc: bound, toUtc: bound);
|
||||
|
||||
// Act
|
||||
@@ -169,8 +169,24 @@ public class GetAllUsersConsumptionStatisticsQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetAllUsersConsumptionStatisticsQuery query = _getAllUsersConsumptionStatisticsQueryFixture.Create(
|
||||
fromUtc: DateTime.UtcNow,
|
||||
toUtc: DateTime.UtcNow.AddDays(-1));
|
||||
fromUtc: "2026-03-02T00:00:00Z",
|
||||
toUtc: "2026-03-01T00:00:00Z");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")] // an empty bound
|
||||
[InlineData("not-a-date")] // a textual value that is not a date
|
||||
[InlineData("2026-13-45T99:99:99")] // a value with out of range components
|
||||
public void Validate_WhenADateRangeBoundIsNotAValidDate_ShouldHaveValidationError(string invalidBound)
|
||||
{
|
||||
// Arrange
|
||||
GetAllUsersConsumptionStatisticsQuery query = _getAllUsersConsumptionStatisticsQueryFixture.Create(fromUtc: invalidBound);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
+9
-4
@@ -198,9 +198,9 @@ public class GetConsumptionStatisticsQueryHandlerTests
|
||||
public async Task HandleAsync_WhenFiltersAreSupplied_ShouldForwardThemUnchanged()
|
||||
{
|
||||
// Arrange
|
||||
MediaKind mediaKind = MediaKind.Book;
|
||||
DateTime fromUtc = DateTime.UtcNow.AddDays(-10);
|
||||
DateTime toUtc = DateTime.UtcNow.AddDays(-1);
|
||||
string mediaKind = nameof(MediaKind.Book);
|
||||
string fromUtc = "2026-03-01T00:00:00Z";
|
||||
string toUtc = "2026-03-02T00:00:00Z";
|
||||
GetConsumptionStatisticsQuery query = _getConsumptionStatisticsQueryFixture.Create(
|
||||
includeLibraryId: false,
|
||||
mediaKind: mediaKind,
|
||||
@@ -213,7 +213,12 @@ public class GetConsumptionStatisticsQueryHandlerTests
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockConsumptionStatisticsRepository.Received(1).GetForUserAsync(
|
||||
Arg.Any<Guid>(), null, mediaKind, fromUtc, toUtc, Arg.Any<CancellationToken>());
|
||||
Arg.Any<Guid>(),
|
||||
null,
|
||||
MediaKind.Book,
|
||||
Arg.Is<DateTime?>(value => value == new DateTime(2026, 3, 1, 0, 0, 0, DateTimeKind.Utc)),
|
||||
Arg.Is<DateTime?>(value => value == new DateTime(2026, 3, 2, 0, 0, 0, DateTimeKind.Utc)),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+28
-12
@@ -124,7 +124,7 @@ public class GetConsumptionStatisticsQueryValidatorTests
|
||||
public void Validate_WhenMediaKindIsNone_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetConsumptionStatisticsQuery query = _getConsumptionStatisticsQueryFixture.Create(mediaKind: MediaKind.None);
|
||||
GetConsumptionStatisticsQuery query = _getConsumptionStatisticsQueryFixture.Create(mediaKind: nameof(MediaKind.None));
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
@@ -137,7 +137,7 @@ public class GetConsumptionStatisticsQueryValidatorTests
|
||||
public void Validate_WhenMediaKindIsUndefined_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetConsumptionStatisticsQuery query = _getConsumptionStatisticsQueryFixture.Create(mediaKind: (MediaKind)99);
|
||||
GetConsumptionStatisticsQuery query = _getConsumptionStatisticsQueryFixture.Create(mediaKind: "999");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
@@ -147,11 +147,11 @@ public class GetConsumptionStatisticsQueryValidatorTests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(MediaKind.MusicTrack)] // a kind supported by the current catalogues
|
||||
[InlineData(MediaKind.Book)] // another kind supported by the current catalogues
|
||||
[InlineData(MediaKind.Movie)] // a kind without a catalogue, still a defined kind
|
||||
[InlineData(MediaKind.Photo)] // a kind that every session counts for, still a defined kind
|
||||
public void Validate_WhenMediaKindIsDefined_ShouldNotHaveValidationError(MediaKind mediaKind)
|
||||
[InlineData(nameof(MediaKind.MusicTrack))] // a kind supported by the current catalogues
|
||||
[InlineData(nameof(MediaKind.Book))] // another kind supported by the current catalogues
|
||||
[InlineData(nameof(MediaKind.Movie))] // a kind without a catalogue, still a defined kind
|
||||
[InlineData(nameof(MediaKind.Photo))] // a kind that every session counts for, still a defined kind
|
||||
public void Validate_WhenMediaKindIsDefined_ShouldNotHaveValidationError(string mediaKind)
|
||||
{
|
||||
// Arrange
|
||||
GetConsumptionStatisticsQuery query = _getConsumptionStatisticsQueryFixture.Create(mediaKind: mediaKind);
|
||||
@@ -168,7 +168,7 @@ public class GetConsumptionStatisticsQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetConsumptionStatisticsQuery query = _getConsumptionStatisticsQueryFixture.Create(
|
||||
fromUtc: DateTime.UtcNow.AddDays(-7),
|
||||
fromUtc: "2026-03-01T00:00:00Z",
|
||||
includeToUtc: false);
|
||||
|
||||
// Act
|
||||
@@ -183,7 +183,7 @@ public class GetConsumptionStatisticsQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetConsumptionStatisticsQuery query = _getConsumptionStatisticsQueryFixture.Create(
|
||||
toUtc: DateTime.UtcNow,
|
||||
toUtc: "2026-03-02T00:00:00Z",
|
||||
includeFromUtc: false);
|
||||
|
||||
// Act
|
||||
@@ -197,7 +197,7 @@ public class GetConsumptionStatisticsQueryValidatorTests
|
||||
public void Validate_WhenBothDateRangeBoundsAreEqual_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
DateTime bound = DateTime.UtcNow;
|
||||
string bound = "2026-03-02T00:00:00Z";
|
||||
GetConsumptionStatisticsQuery query = _getConsumptionStatisticsQueryFixture.Create(fromUtc: bound, toUtc: bound);
|
||||
|
||||
// Act
|
||||
@@ -212,8 +212,24 @@ public class GetConsumptionStatisticsQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetConsumptionStatisticsQuery query = _getConsumptionStatisticsQueryFixture.Create(
|
||||
fromUtc: DateTime.UtcNow,
|
||||
toUtc: DateTime.UtcNow.AddDays(-1));
|
||||
fromUtc: "2026-03-02T00:00:00Z",
|
||||
toUtc: "2026-03-01T00:00:00Z");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")] // an empty bound
|
||||
[InlineData("not-a-date")] // a textual value that is not a date
|
||||
[InlineData("2026-13-45T99:99:99")] // a value with out of range components
|
||||
public void Validate_WhenADateRangeBoundIsNotAValidDate_ShouldHaveValidationError(string invalidBound)
|
||||
{
|
||||
// Arrange
|
||||
GetConsumptionStatisticsQuery query = _getConsumptionStatisticsQueryFixture.Create(fromUtc: invalidBound);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
+28
-12
@@ -124,7 +124,7 @@ public class GetMostConsumedQueryValidatorTests
|
||||
public void Validate_WhenMediaKindIsNone_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetMostConsumedQuery query = _getMostConsumedQueryFixture.Create(mediaKind: MediaKind.None);
|
||||
GetMostConsumedQuery query = _getMostConsumedQueryFixture.Create(mediaKind: nameof(MediaKind.None));
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
@@ -137,7 +137,7 @@ public class GetMostConsumedQueryValidatorTests
|
||||
public void Validate_WhenMediaKindIsUndefined_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetMostConsumedQuery query = _getMostConsumedQueryFixture.Create(mediaKind: (MediaKind)99);
|
||||
GetMostConsumedQuery query = _getMostConsumedQueryFixture.Create(mediaKind: "999");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
@@ -147,11 +147,11 @@ public class GetMostConsumedQueryValidatorTests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(MediaKind.MusicTrack)] // a kind supported by the current catalogues
|
||||
[InlineData(MediaKind.Book)] // another kind supported by the current catalogues
|
||||
[InlineData(MediaKind.Movie)] // a kind without a catalogue, still a defined kind
|
||||
[InlineData(MediaKind.Photo)] // a kind that every session counts for, still a defined kind
|
||||
public void Validate_WhenMediaKindIsDefined_ShouldNotHaveValidationError(MediaKind mediaKind)
|
||||
[InlineData(nameof(MediaKind.MusicTrack))] // a kind supported by the current catalogues
|
||||
[InlineData(nameof(MediaKind.Book))] // another kind supported by the current catalogues
|
||||
[InlineData(nameof(MediaKind.Movie))] // a kind without a catalogue, still a defined kind
|
||||
[InlineData(nameof(MediaKind.Photo))] // a kind that every session counts for, still a defined kind
|
||||
public void Validate_WhenMediaKindIsDefined_ShouldNotHaveValidationError(string mediaKind)
|
||||
{
|
||||
// Arrange
|
||||
GetMostConsumedQuery query = _getMostConsumedQueryFixture.Create(mediaKind: mediaKind);
|
||||
@@ -168,7 +168,7 @@ public class GetMostConsumedQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetMostConsumedQuery query = _getMostConsumedQueryFixture.Create(
|
||||
fromUtc: DateTime.UtcNow.AddDays(-7),
|
||||
fromUtc: "2026-03-01T00:00:00Z",
|
||||
includeToUtc: false);
|
||||
|
||||
// Act
|
||||
@@ -183,7 +183,7 @@ public class GetMostConsumedQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetMostConsumedQuery query = _getMostConsumedQueryFixture.Create(
|
||||
toUtc: DateTime.UtcNow,
|
||||
toUtc: "2026-03-02T00:00:00Z",
|
||||
includeFromUtc: false);
|
||||
|
||||
// Act
|
||||
@@ -197,7 +197,7 @@ public class GetMostConsumedQueryValidatorTests
|
||||
public void Validate_WhenBothDateRangeBoundsAreEqual_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
DateTime bound = DateTime.UtcNow;
|
||||
string bound = "2026-03-02T00:00:00Z";
|
||||
GetMostConsumedQuery query = _getMostConsumedQueryFixture.Create(fromUtc: bound, toUtc: bound);
|
||||
|
||||
// Act
|
||||
@@ -212,8 +212,24 @@ public class GetMostConsumedQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetMostConsumedQuery query = _getMostConsumedQueryFixture.Create(
|
||||
fromUtc: DateTime.UtcNow,
|
||||
toUtc: DateTime.UtcNow.AddDays(-1));
|
||||
fromUtc: "2026-03-02T00:00:00Z",
|
||||
toUtc: "2026-03-01T00:00:00Z");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")] // an empty bound
|
||||
[InlineData("not-a-date")] // a textual value that is not a date
|
||||
[InlineData("2026-13-45T99:99:99")] // a value with out of range components
|
||||
public void Validate_WhenADateRangeBoundIsNotAValidDate_ShouldHaveValidationError(string invalidBound)
|
||||
{
|
||||
// Arrange
|
||||
GetMostConsumedQuery query = _getMostConsumedQueryFixture.Create(fromUtc: invalidBound);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
+28
-12
@@ -124,7 +124,7 @@ public class GetRecentlyConsumedQueryValidatorTests
|
||||
public void Validate_WhenMediaKindIsNone_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetRecentlyConsumedQuery query = _getRecentlyConsumedQueryFixture.Create(mediaKind: MediaKind.None);
|
||||
GetRecentlyConsumedQuery query = _getRecentlyConsumedQueryFixture.Create(mediaKind: nameof(MediaKind.None));
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
@@ -137,7 +137,7 @@ public class GetRecentlyConsumedQueryValidatorTests
|
||||
public void Validate_WhenMediaKindIsUndefined_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetRecentlyConsumedQuery query = _getRecentlyConsumedQueryFixture.Create(mediaKind: (MediaKind)99);
|
||||
GetRecentlyConsumedQuery query = _getRecentlyConsumedQueryFixture.Create(mediaKind: "999");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
@@ -147,11 +147,11 @@ public class GetRecentlyConsumedQueryValidatorTests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(MediaKind.MusicTrack)] // a kind supported by the current catalogues
|
||||
[InlineData(MediaKind.Book)] // another kind supported by the current catalogues
|
||||
[InlineData(MediaKind.Movie)] // a kind without a catalogue, still a defined kind
|
||||
[InlineData(MediaKind.Photo)] // a kind that every session counts for, still a defined kind
|
||||
public void Validate_WhenMediaKindIsDefined_ShouldNotHaveValidationError(MediaKind mediaKind)
|
||||
[InlineData(nameof(MediaKind.MusicTrack))] // a kind supported by the current catalogues
|
||||
[InlineData(nameof(MediaKind.Book))] // another kind supported by the current catalogues
|
||||
[InlineData(nameof(MediaKind.Movie))] // a kind without a catalogue, still a defined kind
|
||||
[InlineData(nameof(MediaKind.Photo))] // a kind that every session counts for, still a defined kind
|
||||
public void Validate_WhenMediaKindIsDefined_ShouldNotHaveValidationError(string mediaKind)
|
||||
{
|
||||
// Arrange
|
||||
GetRecentlyConsumedQuery query = _getRecentlyConsumedQueryFixture.Create(mediaKind: mediaKind);
|
||||
@@ -168,7 +168,7 @@ public class GetRecentlyConsumedQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetRecentlyConsumedQuery query = _getRecentlyConsumedQueryFixture.Create(
|
||||
fromUtc: DateTime.UtcNow.AddDays(-7),
|
||||
fromUtc: "2026-03-01T00:00:00Z",
|
||||
includeToUtc: false);
|
||||
|
||||
// Act
|
||||
@@ -183,7 +183,7 @@ public class GetRecentlyConsumedQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetRecentlyConsumedQuery query = _getRecentlyConsumedQueryFixture.Create(
|
||||
toUtc: DateTime.UtcNow,
|
||||
toUtc: "2026-03-02T00:00:00Z",
|
||||
includeFromUtc: false);
|
||||
|
||||
// Act
|
||||
@@ -197,7 +197,7 @@ public class GetRecentlyConsumedQueryValidatorTests
|
||||
public void Validate_WhenBothDateRangeBoundsAreEqual_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
DateTime bound = DateTime.UtcNow;
|
||||
string bound = "2026-03-02T00:00:00Z";
|
||||
GetRecentlyConsumedQuery query = _getRecentlyConsumedQueryFixture.Create(fromUtc: bound, toUtc: bound);
|
||||
|
||||
// Act
|
||||
@@ -212,8 +212,24 @@ public class GetRecentlyConsumedQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetRecentlyConsumedQuery query = _getRecentlyConsumedQueryFixture.Create(
|
||||
fromUtc: DateTime.UtcNow,
|
||||
toUtc: DateTime.UtcNow.AddDays(-1));
|
||||
fromUtc: "2026-03-02T00:00:00Z",
|
||||
toUtc: "2026-03-01T00:00:00Z");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")] // an empty bound
|
||||
[InlineData("not-a-date")] // a textual value that is not a date
|
||||
[InlineData("2026-13-45T99:99:99")] // a value with out of range components
|
||||
public void Validate_WhenADateRangeBoundIsNotAValidDate_ShouldHaveValidationError(string invalidBound)
|
||||
{
|
||||
// Arrange
|
||||
GetRecentlyConsumedQuery query = _getRecentlyConsumedQueryFixture.Create(fromUtc: invalidBound);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
+28
-12
@@ -124,7 +124,7 @@ public class GetTagConsumptionQueryValidatorTests
|
||||
public void Validate_WhenMediaKindIsNone_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetTagConsumptionQuery query = _getTagConsumptionQueryFixture.Create(mediaKind: MediaKind.None);
|
||||
GetTagConsumptionQuery query = _getTagConsumptionQueryFixture.Create(mediaKind: nameof(MediaKind.None));
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
@@ -137,7 +137,7 @@ public class GetTagConsumptionQueryValidatorTests
|
||||
public void Validate_WhenMediaKindIsUndefined_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetTagConsumptionQuery query = _getTagConsumptionQueryFixture.Create(mediaKind: (MediaKind)99);
|
||||
GetTagConsumptionQuery query = _getTagConsumptionQueryFixture.Create(mediaKind: "999");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
@@ -147,11 +147,11 @@ public class GetTagConsumptionQueryValidatorTests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(MediaKind.MusicTrack)] // a kind supported by the current catalogues
|
||||
[InlineData(MediaKind.Book)] // another kind supported by the current catalogues
|
||||
[InlineData(MediaKind.Movie)] // a kind without a catalogue, still a defined kind
|
||||
[InlineData(MediaKind.Photo)] // a kind that every session counts for, still a defined kind
|
||||
public void Validate_WhenMediaKindIsDefined_ShouldNotHaveValidationError(MediaKind mediaKind)
|
||||
[InlineData(nameof(MediaKind.MusicTrack))] // a kind supported by the current catalogues
|
||||
[InlineData(nameof(MediaKind.Book))] // another kind supported by the current catalogues
|
||||
[InlineData(nameof(MediaKind.Movie))] // a kind without a catalogue, still a defined kind
|
||||
[InlineData(nameof(MediaKind.Photo))] // a kind that every session counts for, still a defined kind
|
||||
public void Validate_WhenMediaKindIsDefined_ShouldNotHaveValidationError(string mediaKind)
|
||||
{
|
||||
// Arrange
|
||||
GetTagConsumptionQuery query = _getTagConsumptionQueryFixture.Create(mediaKind: mediaKind);
|
||||
@@ -168,7 +168,7 @@ public class GetTagConsumptionQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetTagConsumptionQuery query = _getTagConsumptionQueryFixture.Create(
|
||||
fromUtc: DateTime.UtcNow.AddDays(-7),
|
||||
fromUtc: "2026-03-01T00:00:00Z",
|
||||
includeToUtc: false);
|
||||
|
||||
// Act
|
||||
@@ -183,7 +183,7 @@ public class GetTagConsumptionQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetTagConsumptionQuery query = _getTagConsumptionQueryFixture.Create(
|
||||
toUtc: DateTime.UtcNow,
|
||||
toUtc: "2026-03-02T00:00:00Z",
|
||||
includeFromUtc: false);
|
||||
|
||||
// Act
|
||||
@@ -197,7 +197,7 @@ public class GetTagConsumptionQueryValidatorTests
|
||||
public void Validate_WhenBothDateRangeBoundsAreEqual_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
DateTime bound = DateTime.UtcNow;
|
||||
string bound = "2026-03-02T00:00:00Z";
|
||||
GetTagConsumptionQuery query = _getTagConsumptionQueryFixture.Create(fromUtc: bound, toUtc: bound);
|
||||
|
||||
// Act
|
||||
@@ -212,8 +212,24 @@ public class GetTagConsumptionQueryValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
GetTagConsumptionQuery query = _getTagConsumptionQueryFixture.Create(
|
||||
fromUtc: DateTime.UtcNow,
|
||||
toUtc: DateTime.UtcNow.AddDays(-1));
|
||||
fromUtc: "2026-03-02T00:00:00Z",
|
||||
toUtc: "2026-03-01T00:00:00Z");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")] // an empty bound
|
||||
[InlineData("not-a-date")] // a textual value that is not a date
|
||||
[InlineData("2026-13-45T99:99:99")] // a value with out of range components
|
||||
public void Validate_WhenADateRangeBoundIsNotAValidDate_ShouldHaveValidationError(string invalidBound)
|
||||
{
|
||||
// Arrange
|
||||
GetTagConsumptionQuery query = _getTagConsumptionQueryFixture.Create(fromUtc: invalidBound);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
Reference in new issue
Block a user