mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 21:11:10 +00:00
Replaces the custom EmptyRequest with explicit API client operations
Removes the Web-specific EmptyRequest record struct and keeps FastEndpoints.EmptyRequest only as an endpoint request DTO. Adds bodyless and response-ignoring client overloads, centralizes request construction and response disposal, and separates stale-session failures from generic 404 responses. Updates the API client stub and tests, including regression coverage for non-empty response bodies, overload selection, and crafted theme asset paths.
This commit is contained in:
1 parent
c1dd08706c
commit
0a86f1a70b
70 files changed
+679
-384
No files matched your search
@@ -117,6 +117,91 @@ public class ApiHttpClientTests
|
||||
Assert.Contains("testuser", messageHandler.RequestBodies[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostAsync_WhenCalledWithoutPayload_ShouldDeserializeResponse()
|
||||
{
|
||||
// Arrange
|
||||
TestApiHttpMessageHandler messageHandler = new(_ => CreateJsonResponse(HttpStatusCode.OK, """{"success":true}"""));
|
||||
ApiHttpClient sut = CreateSut(messageHandler);
|
||||
|
||||
// Act
|
||||
SuccessResponse result = await sut.PostAsync<SuccessResponse>("libraries", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal(HttpMethod.Post, messageHandler.Requests[0].Method);
|
||||
Assert.Null(messageHandler.Requests[0].Content);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostIgnoringResponseAsync_WhenCalledWithoutPayload_ShouldSendBodylessRequestAndIgnoreNonEmptyResponse()
|
||||
{
|
||||
// Arrange
|
||||
TestApiHttpMessageHandler messageHandler = new(_ => CreateJsonResponse(HttpStatusCode.OK, "{}"));
|
||||
ApiHttpClient sut = CreateSut(messageHandler);
|
||||
|
||||
// Act
|
||||
await sut.PostIgnoringResponseAsync("libraries/1", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpMethod.Post, messageHandler.Requests[0].Method);
|
||||
Assert.Null(messageHandler.Requests[0].Content);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostIgnoringResponseAsync_WhenUserHasTokenClaim_ShouldSendAuthorizationHeader()
|
||||
{
|
||||
// Arrange
|
||||
TestApiHttpMessageHandler messageHandler = new(_ => CreateJsonResponse(HttpStatusCode.OK, "{}"));
|
||||
ApiHttpClient sut = CreateSut(messageHandler, token: "test-jwt-token");
|
||||
|
||||
// Act
|
||||
await sut.PostIgnoringResponseAsync("libraries/1", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Bearer", messageHandler.Requests[0].Headers.Authorization!.Scheme);
|
||||
Assert.Equal("test-jwt-token", messageHandler.Requests[0].Headers.Authorization!.Parameter);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PutIgnoringResponseAsync_WhenCalledWithPayload_ShouldSerializePayloadAndIgnoreNonEmptyResponse()
|
||||
{
|
||||
// Arrange
|
||||
TestApiHttpMessageHandler messageHandler = new(_ => CreateJsonResponse(HttpStatusCode.OK, """{"updated":true}"""));
|
||||
ApiHttpClient sut = CreateSut(messageHandler);
|
||||
|
||||
// Act
|
||||
await sut.PutIgnoringResponseAsync("libraries/1", new { title = "Library One" }, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("Library One", messageHandler.RequestBodies[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostIgnoringResponseAsync_WhenApiReturnsError_ShouldThrowApiExceptionWithProblemDetails()
|
||||
{
|
||||
// Arrange
|
||||
string problemDetailsJson = """
|
||||
{
|
||||
"type": "https://tools.ietf.org/html/rfc9110#section-15.6.1",
|
||||
"title": "General.Failure",
|
||||
"status": 500,
|
||||
"detail": "UnexpectedFailure"
|
||||
}
|
||||
""";
|
||||
TestApiHttpMessageHandler messageHandler = new(_ => CreateJsonResponse(HttpStatusCode.InternalServerError, problemDetailsJson));
|
||||
ApiHttpClient sut = CreateSut(messageHandler);
|
||||
|
||||
// Act
|
||||
ApiException exception = await Assert.ThrowsAsync<ApiException>(() => sut.PostIgnoringResponseAsync("libraries/1", CancellationToken.None));
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.InternalServerError, exception.HttpStatusCode);
|
||||
Assert.NotNull(exception.ProblemDetails);
|
||||
Assert.Equal("General.Failure", exception.ProblemDetails!.Title);
|
||||
Assert.Equal("UnexpectedFailure", exception.ProblemDetails.Detail);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteAsync_WhenApiReturnsError_ShouldThrowApiException()
|
||||
{
|
||||
|
||||
+12
-1
@@ -148,7 +148,6 @@ public class AuthorizationServiceTests
|
||||
[Theory]
|
||||
[InlineData(HttpStatusCode.Unauthorized)]
|
||||
[InlineData(HttpStatusCode.Forbidden)]
|
||||
[InlineData(HttpStatusCode.NotFound)]
|
||||
public async Task HasPermissionAsync_WhenTheApiReturnsAnAuthorizationStatusDuringAPageNavigation_ShouldRethrow(HttpStatusCode statusCode)
|
||||
{
|
||||
// Arrange
|
||||
@@ -160,6 +159,18 @@ public class AuthorizationServiceTests
|
||||
await Assert.ThrowsAsync<ApiException>(() => _sut.HasPermissionAsync(AuthorizationPermission.CanCreateLibraries, CancellationToken.None));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HasPermissionAsync_WhenTheApiReturnsNotFoundDuringAPageNavigation_ShouldThrowCurrentUserAuthorizationException()
|
||||
{
|
||||
// Arrange
|
||||
_httpContext.Request.Headers.Accept = "text/html";
|
||||
_mockApiHttpClient.GetAsync<GetAuthorizationResponse>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromException<GetAuthorizationResponse>(new ApiException(null, HttpStatusCode.NotFound, "/api/v1/auth/get-authorization?userId=1")));
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<CurrentUserAuthorizationException>(() => _sut.HasPermissionAsync(AuthorizationPermission.CanCreateLibraries, CancellationToken.None));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HasPermissionAsync_WhenTheApiReturnsAServerErrorDuringAPageNavigation_ShouldReturnFalseAndMarkTheServerUnreachable()
|
||||
{
|
||||
|
||||
+20
-2
@@ -220,7 +220,7 @@ public class ExceptionHandlingMiddlewareTests
|
||||
{
|
||||
// Arrange
|
||||
DefaultHttpContext httpContext = CreateHttpContext(isApiRequest: true, user: CreateAuthenticatedUser(), requestServices: CreateServiceProvider());
|
||||
_nextDelegate = _ => throw new ApiException(_problemDetailsDtoFixture.Create(), HttpStatusCode.NotFound, "/api/v1/auth/get-authorization?userId=1");
|
||||
_nextDelegate = _ => throw new CurrentUserAuthorizationException(_problemDetailsDtoFixture.Create(), HttpStatusCode.NotFound, "/api/v1/auth/get-authorization?userId=1");
|
||||
|
||||
// Act
|
||||
await _sut.InvokeAsync(httpContext);
|
||||
@@ -237,7 +237,7 @@ public class ExceptionHandlingMiddlewareTests
|
||||
// Arrange
|
||||
DefaultHttpContext httpContext = CreateHttpContext(isApiRequest: false, culture: null, user: CreateAuthenticatedUser(), requestServices: CreateServiceProvider());
|
||||
httpContext.Request.Path = "/dashboard";
|
||||
_nextDelegate = _ => throw new ApiException(_problemDetailsDtoFixture.Create(), HttpStatusCode.NotFound, "/api/v1/auth/get-authorization?userId=1");
|
||||
_nextDelegate = _ => throw new CurrentUserAuthorizationException(_problemDetailsDtoFixture.Create(), HttpStatusCode.NotFound, "/api/v1/auth/get-authorization?userId=1");
|
||||
|
||||
// Act
|
||||
await _sut.InvokeAsync(httpContext);
|
||||
@@ -248,6 +248,24 @@ public class ExceptionHandlingMiddlewareTests
|
||||
await _mockAuthenticationService.Received(1).SignOutAsync(httpContext, CookieAuthenticationDefaults.AuthenticationScheme, Arg.Any<AuthenticationProperties?>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InvokeAsync_WhenApiExceptionNotFoundWithCraftedAuthorizationPathAndAuthenticatedPageRequest_ShouldNotSignOut()
|
||||
{
|
||||
// Arrange
|
||||
DefaultHttpContext httpContext = CreateHttpContext(isApiRequest: false, culture: "en-us", user: CreateAuthenticatedUser(), requestServices: CreateServiceProvider());
|
||||
httpContext.Request.Headers.Accept = "text/html";
|
||||
httpContext.Request.Path = "/en-us/theme-assets/test-theme/auth/get-authorization";
|
||||
_nextDelegate = _ => throw new ApiException(_problemDetailsDtoFixture.Create(), HttpStatusCode.NotFound, "/api/v1/themes/test-theme/assets/auth/get-authorization");
|
||||
|
||||
// Act
|
||||
await _sut.InvokeAsync(httpContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(StatusCodes.Status302Found, httpContext.Response.StatusCode);
|
||||
Assert.Equal("/en-us/not-found", httpContext.Response.Headers.Location.ToString());
|
||||
await _mockAuthenticationService.DidNotReceive().SignOutAsync(Arg.Any<HttpContext>(), Arg.Any<string?>(), Arg.Any<AuthenticationProperties?>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InvokeAsync_WhenApiExceptionForbiddenAndApiRequest_ShouldWriteFailureJsonWithProblemDetail()
|
||||
{
|
||||
|
||||
+2
-2
@@ -47,9 +47,9 @@ public class FireScheduledJobEndpointTests
|
||||
|
||||
// Assert
|
||||
string expectedEndpoint = ApiRoutes.ScheduledJobs.FIRE_SCHEDULED_JOB.Replace("{scheduledJobId}", request.ScheduledJobId.ToString());
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest, Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<FireScheduledJobRequest>(
|
||||
expectedEndpoint,
|
||||
Arg.Any<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Is<FireScheduledJobRequest>(forwardedRequest => forwardedRequest.ScheduledJobId == request.ScheduledJobId),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
|
||||
+2
-2
@@ -47,9 +47,9 @@ public class StartScheduledJobEndpointTests
|
||||
|
||||
// Assert
|
||||
string expectedEndpoint = ApiRoutes.ScheduledJobs.START_SCHEDULED_JOB.Replace("{scheduledJobId}", request.ScheduledJobId.ToString());
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest, Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<StartScheduledJobRequest>(
|
||||
expectedEndpoint,
|
||||
Arg.Any<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Is<StartScheduledJobRequest>(forwardedRequest => forwardedRequest.ScheduledJobId == request.ScheduledJobId),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
|
||||
+2
-2
@@ -47,9 +47,9 @@ public class StopScheduledJobEndpointTests
|
||||
|
||||
// Assert
|
||||
string expectedEndpoint = ApiRoutes.ScheduledJobs.STOP_SCHEDULED_JOB.Replace("{scheduledJobId}", request.ScheduledJobId.ToString());
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<StopScheduledJobRequest>(
|
||||
expectedEndpoint,
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Is<StopScheduledJobRequest>(forwardedRequest => forwardedRequest.ScheduledJobId == request.ScheduledJobId),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class UpdateSchedulerDisplayPreferencesEndpointTests
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest, UpdateSchedulerDisplayPreferencesRequest>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<UpdateSchedulerDisplayPreferencesRequest>(
|
||||
ApiRoutes.ScheduledJobs.UPDATE_DISPLAY_PREFERENCES,
|
||||
Arg.Is<UpdateSchedulerDisplayPreferencesRequest>(forwardedRequest =>
|
||||
forwardedRequest.JobTypeFilter == request.JobTypeFilter &&
|
||||
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.RestoreTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
@@ -65,7 +64,7 @@ public class RestoreThemeEndpointTests
|
||||
await _sut.ExecuteAsync(_restoreThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ThemeResponseDto, object>(expectedEndpoint, Arg.Any<object>(), Arg.Any<CancellationToken>());
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(expectedEndpoint, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -80,6 +79,6 @@ public class RestoreThemeEndpointTests
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
Assert.Equal(StatusCodes.Status400BadRequest, problemResult.StatusCode);
|
||||
await _mockApiHttpClient.DidNotReceive().PostAsync<ThemeResponseDto, object>(Arg.Any<string>(), Arg.Any<object>(), Arg.Any<CancellationToken>());
|
||||
await _mockApiHttpClient.DidNotReceive().PostIgnoringResponseAsync(Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+6
-8
@@ -1,11 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.SetCurrentTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -26,7 +25,6 @@ public class SetCurrentThemeEndpointTests
|
||||
{
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly SetCurrentThemeEndpoint _sut;
|
||||
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
||||
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
@@ -44,8 +42,8 @@ public class SetCurrentThemeEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
string themeId = "editorial-paper";
|
||||
_mockApiHttpClient.PutAsync<ThemeResponseDto, object>(Arg.Any<string>(), Arg.Any<object>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_themeResponseDtoFixture.Create());
|
||||
_mockApiHttpClient.PutIgnoringResponseAsync<SetCurrentThemeRequest>(Arg.Any<string>(), Arg.Any<SetCurrentThemeRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(_setCurrentThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
@@ -55,9 +53,9 @@ public class SetCurrentThemeEndpointTests
|
||||
using (System.Text.Json.JsonDocument jsonDocument = System.Text.Json.JsonDocument.Parse(body))
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
|
||||
await _mockApiHttpClient.Received(1).PutAsync<ThemeResponseDto, object>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<SetCurrentThemeRequest>(
|
||||
ApiRoutes.Themes.SET_CURRENT_THEME,
|
||||
Arg.Is<object>(payload => (payload.GetType().GetProperty("ThemeId")!.GetValue(payload) as string) == themeId),
|
||||
Arg.Is<SetCurrentThemeRequest>(payload => payload.ThemeId == themeId),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -73,6 +71,6 @@ public class SetCurrentThemeEndpointTests
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
Assert.Equal(StatusCodes.Status400BadRequest, problemResult.StatusCode);
|
||||
await _mockApiHttpClient.DidNotReceive().PutAsync<ThemeResponseDto, object>(Arg.Any<string>(), Arg.Any<object>(), Arg.Any<CancellationToken>());
|
||||
await _mockApiHttpClient.DidNotReceive().PutIgnoringResponseAsync<SetCurrentThemeRequest>(Arg.Any<string>(), Arg.Any<SetCurrentThemeRequest>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+10
-22
@@ -30,11 +30,6 @@ public class RestoreMusicAlbumEndpointTests
|
||||
public RestoreMusicAlbumEndpointTests()
|
||||
{
|
||||
_mockApiHttpClient = Substitute.For<IApiHttpClient>();
|
||||
// The restore endpoints forward a bodyless POST upstream; returning an empty request lets every test that is not about
|
||||
// cancellation focus on the URL construction instead of repeating the upstream stub.
|
||||
_mockApiHttpClient.PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
Arg.Any<string>(), Arg.Any<Web.Common.Requests.Common.EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new Web.Common.Requests.Common.EmptyRequest());
|
||||
_sut = Factory.Create<RestoreMusicAlbumEndpoint>(_mockApiHttpClient);
|
||||
}
|
||||
|
||||
@@ -56,9 +51,8 @@ public class RestoreMusicAlbumEndpointTests
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, artistId, albumId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
@@ -77,9 +71,8 @@ public class RestoreMusicAlbumEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, Guid.Empty, albumId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -95,9 +88,8 @@ public class RestoreMusicAlbumEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, Guid.Empty, albumId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -113,9 +105,8 @@ public class RestoreMusicAlbumEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, artistId, Guid.Empty),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -131,9 +122,8 @@ public class RestoreMusicAlbumEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, artistId, Guid.Empty),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -149,9 +139,8 @@ public class RestoreMusicAlbumEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(Guid.Empty, artistId, albumId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -167,9 +156,8 @@ public class RestoreMusicAlbumEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(Guid.Empty, artistId, albumId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -183,9 +171,9 @@ public class RestoreMusicAlbumEndpointTests
|
||||
ConfigureRequest(artistId.ToString(), albumId.ToString(), libraryId.ToString());
|
||||
using CancellationTokenSource cancellationTokenSource = new();
|
||||
cancellationTokenSource.Cancel();
|
||||
_mockApiHttpClient.PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
Arg.Any<string>(), Arg.Any<Web.Common.Requests.Common.EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromCanceled<Web.Common.Requests.Common.EmptyRequest>(cancellationTokenSource.Token));
|
||||
_mockApiHttpClient.PostIgnoringResponseAsync(
|
||||
Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromCanceled(cancellationTokenSource.Token));
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(
|
||||
|
||||
+8
-18
@@ -30,11 +30,6 @@ public class RestoreMusicArtistEndpointTests
|
||||
public RestoreMusicArtistEndpointTests()
|
||||
{
|
||||
_mockApiHttpClient = Substitute.For<IApiHttpClient>();
|
||||
// The restore endpoints forward a bodyless POST upstream; returning an empty request lets every test that is not about
|
||||
// cancellation focus on the URL construction instead of repeating the upstream stub.
|
||||
_mockApiHttpClient.PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
Arg.Any<string>(), Arg.Any<Web.Common.Requests.Common.EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new Web.Common.Requests.Common.EmptyRequest());
|
||||
_sut = Factory.Create<RestoreMusicArtistEndpoint>(_mockApiHttpClient);
|
||||
}
|
||||
|
||||
@@ -55,9 +50,8 @@ public class RestoreMusicArtistEndpointTests
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, artistId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
@@ -75,9 +69,8 @@ public class RestoreMusicArtistEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, Guid.Empty),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -92,9 +85,8 @@ public class RestoreMusicArtistEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, Guid.Empty),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -109,9 +101,8 @@ public class RestoreMusicArtistEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(Guid.Empty, artistId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -126,9 +117,8 @@ public class RestoreMusicArtistEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(Guid.Empty, artistId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -141,9 +131,9 @@ public class RestoreMusicArtistEndpointTests
|
||||
ConfigureRequest(artistId.ToString(), libraryId.ToString());
|
||||
using CancellationTokenSource cancellationTokenSource = new();
|
||||
cancellationTokenSource.Cancel();
|
||||
_mockApiHttpClient.PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
Arg.Any<string>(), Arg.Any<Web.Common.Requests.Common.EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromCanceled<Web.Common.Requests.Common.EmptyRequest>(cancellationTokenSource.Token));
|
||||
_mockApiHttpClient.PostIgnoringResponseAsync(
|
||||
Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromCanceled(cancellationTokenSource.Token));
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(
|
||||
|
||||
+12
-26
@@ -30,11 +30,6 @@ public class RestoreMusicTrackEndpointTests
|
||||
public RestoreMusicTrackEndpointTests()
|
||||
{
|
||||
_mockApiHttpClient = Substitute.For<IApiHttpClient>();
|
||||
// The restore endpoints forward a bodyless POST upstream; returning an empty request lets every test that is not about
|
||||
// cancellation focus on the URL construction instead of repeating the upstream stub.
|
||||
_mockApiHttpClient.PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
Arg.Any<string>(), Arg.Any<Web.Common.Requests.Common.EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new Web.Common.Requests.Common.EmptyRequest());
|
||||
_sut = Factory.Create<RestoreMusicTrackEndpoint>(_mockApiHttpClient);
|
||||
}
|
||||
|
||||
@@ -57,9 +52,8 @@ public class RestoreMusicTrackEndpointTests
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, artistId, albumId, trackId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
@@ -79,9 +73,8 @@ public class RestoreMusicTrackEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, Guid.Empty, albumId, trackId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -98,9 +91,8 @@ public class RestoreMusicTrackEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, Guid.Empty, albumId, trackId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -117,9 +109,8 @@ public class RestoreMusicTrackEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, artistId, Guid.Empty, trackId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -136,9 +127,8 @@ public class RestoreMusicTrackEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, artistId, Guid.Empty, trackId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -155,9 +145,8 @@ public class RestoreMusicTrackEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, artistId, albumId, Guid.Empty),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -174,9 +163,8 @@ public class RestoreMusicTrackEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, artistId, albumId, Guid.Empty),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -193,9 +181,8 @@ public class RestoreMusicTrackEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(Guid.Empty, artistId, albumId, trackId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -212,9 +199,8 @@ public class RestoreMusicTrackEndpointTests
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(Guid.Empty, artistId, albumId, trackId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -229,9 +215,9 @@ public class RestoreMusicTrackEndpointTests
|
||||
ConfigureRequest(artistId.ToString(), albumId.ToString(), trackId.ToString(), libraryId.ToString());
|
||||
using CancellationTokenSource cancellationTokenSource = new();
|
||||
cancellationTokenSource.Cancel();
|
||||
_mockApiHttpClient.PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
Arg.Any<string>(), Arg.Any<Web.Common.Requests.Common.EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromCanceled<Web.Common.Requests.Common.EmptyRequest>(cancellationTokenSource.Token));
|
||||
_mockApiHttpClient.PostIgnoringResponseAsync(
|
||||
Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromCanceled(cancellationTokenSource.Token));
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(
|
||||
|
||||
+3
-15
@@ -40,18 +40,14 @@ public class RestoreBookEndpointTests
|
||||
Guid bookId = Guid.NewGuid();
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ConfigureRequest(bookId.ToString(), libraryId);
|
||||
_mockApiHttpClient.PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
Arg.Any<string>(), Arg.Any<Web.Common.Requests.Common.EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new Web.Common.Requests.Common.EmptyRequest());
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, bookId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
@@ -64,17 +60,13 @@ public class RestoreBookEndpointTests
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
ConfigureRequest("not-a-guid", libraryId);
|
||||
_mockApiHttpClient.PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
Arg.Any<string>(), Arg.Any<Web.Common.Requests.Common.EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new Web.Common.Requests.Common.EmptyRequest());
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(libraryId, Guid.Empty),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -84,17 +76,13 @@ public class RestoreBookEndpointTests
|
||||
// Arrange
|
||||
Guid bookId = Guid.NewGuid();
|
||||
ConfigureRequest(bookId.ToString(), "not-a-guid");
|
||||
_mockApiHttpClient.PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
Arg.Any<string>(), Arg.Any<Web.Common.Requests.Common.EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new Web.Common.Requests.Common.EmptyRequest());
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(
|
||||
BuildExpectedEndpoint(Guid.Empty, bookId),
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
|
||||
+19
-26
@@ -47,7 +47,7 @@ public class StartConsumptionEndpointTests
|
||||
// Arrange
|
||||
ConsumptionRecordDto expectedRecord = _consumptionRecordDtoFixture.Create(status: ConsumptionStatus.InProgress);
|
||||
SetRouteValues(s_libraryId, nameof(MediaKind.MusicTrack), s_mediaItemId);
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto, EmptyRequest>(Arg.Any<string>(), Arg.Any<EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedRecord);
|
||||
|
||||
// Act
|
||||
@@ -77,16 +77,15 @@ public class StartConsumptionEndpointTests
|
||||
// Arrange
|
||||
ConsumptionRecordDto expectedRecord = _consumptionRecordDtoFixture.Create();
|
||||
SetRouteValues(s_libraryId, nameof(MediaKind.MusicTrack), s_mediaItemId);
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto, EmptyRequest>(Arg.Any<string>(), Arg.Any<EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedRecord);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto, EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == $"libraries/{s_libraryId}/media-items/MusicTrack/{s_mediaItemId}/consumption-records"),
|
||||
Arg.Any<EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -98,16 +97,15 @@ public class StartConsumptionEndpointTests
|
||||
_sut.HttpContext.Request.RouteValues["libraryId"] = s_libraryId;
|
||||
_sut.HttpContext.Request.RouteValues["mediaKind"] = nameof(MediaKind.Book);
|
||||
_sut.HttpContext.Request.RouteValues["mediaItemId"] = s_mediaItemId;
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto, EmptyRequest>(Arg.Any<string>(), Arg.Any<EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedRecord);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto, EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == $"libraries/{s_libraryId}/media-items/Book/{s_mediaItemId}/consumption-records"),
|
||||
Arg.Any<EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -117,16 +115,15 @@ public class StartConsumptionEndpointTests
|
||||
// Arrange
|
||||
ConsumptionRecordDto expectedRecord = _consumptionRecordDtoFixture.Create();
|
||||
SetRouteValues("not-a-guid", nameof(MediaKind.MusicTrack), s_mediaItemId);
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto, EmptyRequest>(Arg.Any<string>(), Arg.Any<EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedRecord);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto, EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == $"libraries/{ZERO_GUID}/media-items/MusicTrack/{s_mediaItemId}/consumption-records"),
|
||||
Arg.Any<EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -136,16 +133,15 @@ public class StartConsumptionEndpointTests
|
||||
// Arrange
|
||||
ConsumptionRecordDto expectedRecord = _consumptionRecordDtoFixture.Create();
|
||||
SetRouteValues(s_libraryId, nameof(MediaKind.MusicTrack), "not-a-guid");
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto, EmptyRequest>(Arg.Any<string>(), Arg.Any<EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedRecord);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto, EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == $"libraries/{s_libraryId}/media-items/MusicTrack/{ZERO_GUID}/consumption-records"),
|
||||
Arg.Any<EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -154,16 +150,15 @@ public class StartConsumptionEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
ConsumptionRecordDto expectedRecord = _consumptionRecordDtoFixture.Create();
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto, EmptyRequest>(Arg.Any<string>(), Arg.Any<EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedRecord);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto, EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == $"libraries/{ZERO_GUID}/media-items/Invalid/{ZERO_GUID}/consumption-records"),
|
||||
Arg.Any<EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -179,16 +174,15 @@ public class StartConsumptionEndpointTests
|
||||
// Arrange
|
||||
ConsumptionRecordDto expectedRecord = _consumptionRecordDtoFixture.Create();
|
||||
SetRouteValues(s_libraryId, routeMediaKind, s_mediaItemId);
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto, EmptyRequest>(Arg.Any<string>(), Arg.Any<EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedRecord);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto, EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == $"libraries/{s_libraryId}/media-items/{expectedMediaKind}/{s_mediaItemId}/consumption-records"),
|
||||
Arg.Any<EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -206,16 +200,15 @@ public class StartConsumptionEndpointTests
|
||||
// Arrange
|
||||
ConsumptionRecordDto expectedRecord = _consumptionRecordDtoFixture.Create();
|
||||
SetRouteValues(s_libraryId, routeMediaKind, s_mediaItemId);
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto, EmptyRequest>(Arg.Any<string>(), Arg.Any<EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedRecord);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto, EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ConsumptionRecordDto>(
|
||||
Arg.Is<string>(endpoint => endpoint == $"libraries/{s_libraryId}/media-items/Invalid/{s_mediaItemId}/consumption-records"),
|
||||
Arg.Any<EmptyRequest>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -225,7 +218,7 @@ public class StartConsumptionEndpointTests
|
||||
// Arrange
|
||||
ConsumptionRecordDto expectedRecord = _consumptionRecordDtoFixture.Create();
|
||||
SetRouteValues(s_libraryId, nameof(MediaKind.MusicTrack), s_mediaItemId);
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto, EmptyRequest>(Arg.Any<string>(), Arg.Any<EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedRecord);
|
||||
|
||||
// Act
|
||||
@@ -245,14 +238,14 @@ public class StartConsumptionEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
SetRouteValues(s_libraryId, nameof(MediaKind.MusicTrack), s_mediaItemId);
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto, EmptyRequest>(Arg.Any<string>(), Arg.Any<EmptyRequest>(), Arg.Any<CancellationToken>())
|
||||
_mockApiHttpClient.PostAsync<ConsumptionRecordDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.ArgAt<CancellationToken>(2).ThrowIfCancellationRequested();
|
||||
callInfo.ArgAt<CancellationToken>(1).ThrowIfCancellationRequested();
|
||||
return expectedRecord;
|
||||
}, callInfo.ArgAt<CancellationToken>(2)));
|
||||
}, callInfo.ArgAt<CancellationToken>(1)));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(EmptyRequest.Instance, cts.Token);
|
||||
|
||||
+3
-3
@@ -40,8 +40,8 @@ public class UpdatePluginSettingsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
UpdatePluginSettingsRequest request = _updatePluginSettingsRequestFixture.Create();
|
||||
_mockApiHttpClient.PutAsync<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest, UpdatePluginSettingsRequest>(Arg.Any<string>(), Arg.Any<UpdatePluginSettingsRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest());
|
||||
_mockApiHttpClient.PutIgnoringResponseAsync<UpdatePluginSettingsRequest>(Arg.Any<string>(), Arg.Any<UpdatePluginSettingsRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
@@ -49,7 +49,7 @@ public class UpdatePluginSettingsEndpointTests
|
||||
|
||||
// Assert
|
||||
string expectedEndpoint = ApiRoutes.Plugins.UPDATE_PLUGIN_SETTINGS.Replace("{pluginId}", request.PluginId.ToString());
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest, UpdatePluginSettingsRequest>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<UpdatePluginSettingsRequest>(
|
||||
expectedEndpoint,
|
||||
Arg.Is<UpdatePluginSettingsRequest>(settings => settings.PluginId == request.PluginId),
|
||||
Arg.Any<CancellationToken>());
|
||||
|
||||
+9
-11
@@ -2,7 +2,6 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Requests.Common;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Tools.Settings.UpdatePlaybackState;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.UsersManagement;
|
||||
@@ -13,7 +12,6 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using WebEmptyRequest = Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.UnitTests.Core.Endpoints.Tools.Settings.UpdatePlaybackState;
|
||||
@@ -42,15 +40,15 @@ public class UpdatePlaybackStateEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
PlaybackStateDto request = _playbackStateDtoFixture.Create(volume: 0.35, isMuted: true);
|
||||
_mockApiHttpClient.PutAsync<WebEmptyRequest, PlaybackStateDto>(Arg.Any<string>(), Arg.Any<PlaybackStateDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new WebEmptyRequest());
|
||||
_mockApiHttpClient.PutIgnoringResponseAsync<PlaybackStateDto>(Arg.Any<string>(), Arg.Any<PlaybackStateDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PutAsync<WebEmptyRequest, PlaybackStateDto>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<PlaybackStateDto>(
|
||||
ApiRoutes.Users.UPDATE_PLAYBACK_STATE,
|
||||
Arg.Is<PlaybackStateDto>(state => state.Volume == 0.35 && state.IsMuted == true),
|
||||
Arg.Any<CancellationToken>());
|
||||
@@ -64,14 +62,14 @@ public class UpdatePlaybackStateEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
PlaybackStateDto request = _playbackStateDtoFixture.Create(volume: 0.0, isMuted: false);
|
||||
_mockApiHttpClient.PutAsync<WebEmptyRequest, PlaybackStateDto>(Arg.Any<string>(), Arg.Any<PlaybackStateDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new WebEmptyRequest());
|
||||
_mockApiHttpClient.PutIgnoringResponseAsync<PlaybackStateDto>(Arg.Any<string>(), Arg.Any<PlaybackStateDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PutAsync<WebEmptyRequest, PlaybackStateDto>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<PlaybackStateDto>(
|
||||
ApiRoutes.Users.UPDATE_PLAYBACK_STATE,
|
||||
Arg.Is<PlaybackStateDto>(state => state.Volume == 0.0 && state.IsMuted == false),
|
||||
Arg.Any<CancellationToken>());
|
||||
@@ -82,14 +80,14 @@ public class UpdatePlaybackStateEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
PlaybackStateDto request = _playbackStateDtoFixture.Create(includeVolume: false, includeIsMuted: false);
|
||||
_mockApiHttpClient.PutAsync<WebEmptyRequest, PlaybackStateDto>(Arg.Any<string>(), Arg.Any<PlaybackStateDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new WebEmptyRequest());
|
||||
_mockApiHttpClient.PutIgnoringResponseAsync<PlaybackStateDto>(Arg.Any<string>(), Arg.Any<PlaybackStateDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PutAsync<WebEmptyRequest, PlaybackStateDto>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<PlaybackStateDto>(
|
||||
ApiRoutes.Users.UPDATE_PLAYBACK_STATE,
|
||||
Arg.Is<PlaybackStateDto>(state => state.Volume == null && state.IsMuted == null),
|
||||
Arg.Any<CancellationToken>());
|
||||
|
||||
+6
-6
@@ -55,15 +55,15 @@ public class UpdateUserSettingsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
UserSettingsDto request = _userSettingsDtoFixture.Create();
|
||||
_mockApiHttpClient.PutAsync<Web.Common.Requests.Common.EmptyRequest, UserSettingsDto>(Arg.Any<string>(), Arg.Any<UserSettingsDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new Web.Common.Requests.Common.EmptyRequest());
|
||||
_mockApiHttpClient.PutIgnoringResponseAsync<UserSettingsDto>(Arg.Any<string>(), Arg.Any<UserSettingsDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Web.Common.Requests.Common.EmptyRequest, UserSettingsDto>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<UserSettingsDto>(
|
||||
ApiRoutes.Users.UPDATE_USER_SETTINGS,
|
||||
Arg.Is<UserSettingsDto>(settings => settings.ItemsPerPage == request.ItemsPerPage && settings.IsPaginationEnabled == request.IsPaginationEnabled),
|
||||
Arg.Any<CancellationToken>());
|
||||
@@ -86,15 +86,15 @@ public class UpdateUserSettingsEndpointTests
|
||||
vuMeterPeakHoldDurationInMilliseconds: 1200,
|
||||
vuMeterReleasePerSecond: 7.5,
|
||||
vuMeterPeakReleasePerSecond: 0.25);
|
||||
_mockApiHttpClient.PutAsync<Web.Common.Requests.Common.EmptyRequest, UserSettingsDto>(Arg.Any<string>(), Arg.Any<UserSettingsDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new Web.Common.Requests.Common.EmptyRequest());
|
||||
_mockApiHttpClient.PutIgnoringResponseAsync<UserSettingsDto>(Arg.Any<string>(), Arg.Any<UserSettingsDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Web.Common.Requests.Common.EmptyRequest, UserSettingsDto>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<UserSettingsDto>(
|
||||
ApiRoutes.Users.UPDATE_USER_SETTINGS,
|
||||
Arg.Is<UserSettingsDto>(settings =>
|
||||
settings.VuMeterOrientation == VuMeterOrientation.Horizontal &&
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Enums.Themes;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.FileSystemManagement;
|
||||
@@ -120,16 +121,16 @@ public class ThemeServiceTests
|
||||
{
|
||||
// Arrange
|
||||
string themeId = "editorial-paper";
|
||||
_mockApiHttpClient.PutAsync<ThemeResponseDto, object>(Arg.Any<string>(), Arg.Any<object>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_themeResponseDtoFixture.Create());
|
||||
_mockApiHttpClient.PutIgnoringResponseAsync<SetCurrentThemeRequest>(Arg.Any<string>(), Arg.Any<SetCurrentThemeRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
await _sut.SetCurrentThemeAsync(themeId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PutAsync<ThemeResponseDto, object>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<SetCurrentThemeRequest>(
|
||||
ApiRoutes.Themes.SET_CURRENT_THEME,
|
||||
Arg.Is<object>(payload => payload.GetType().GetProperty("ThemeId")!.GetValue(payload)!.ToString()! == themeId),
|
||||
Arg.Is<SetCurrentThemeRequest>(payload => payload.ThemeId == themeId),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user