Skip to content

Commit

Permalink
fix tests after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
DmyMi committed Dec 10, 2024
1 parent e9062c4 commit 83d1408
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,20 @@ public async Task GetUserInfo_WithCorrectRequest_ReturnsOkResponse()
{
CertBase64 = "cert",
};
var certSetup = SetupSendAsync(handler, HttpMethod.Get,
new Uri(eUSignServiceUri, "api/v1/certificate").ToString());
ReturnsHttpResponseAsync(certSetup, certResponse, HttpStatusCode.OK);
handler.SetupSendAsync(HttpMethod.Get,
new Uri(eUSignServiceUri, "api/v1/certificate").ToString())
.ReturnsHttpResponseAsync(certResponse, HttpStatusCode.OK);

var infoResponse = new EnvelopedUserInfoResponse
{
EncryptedUserInfo = "serialized_info",
};

var infoSetup = SetupSendAsync(handler, HttpMethod.Get, new Uri(idServerUri, "/userinfo").ToString(), true);
ReturnsHttpResponseAsync(infoSetup, infoResponse, HttpStatusCode.OK);
handler.SetupSendAsync(HttpMethod.Get, new Uri(idServerUri, "/userinfo").ToString(), true)
.ReturnsHttpResponseAsync(infoResponse, HttpStatusCode.OK);

var decryptSetup =
SetupSendAsync(handler, HttpMethod.Post, new Uri(eUSignServiceUri, "api/v1/decrypt").ToString());
ReturnsHttpResponseAsync(decryptSetup, expected, HttpStatusCode.OK);
handler.SetupSendAsync(HttpMethod.Post, new Uri(eUSignServiceUri, "api/v1/decrypt").ToString())
.ReturnsHttpResponseAsync(expected, HttpStatusCode.OK);

// Act
var userInfo = await communicationService.GetUserInfo(remoteUserId, remoteToken);
Expand All @@ -125,9 +124,9 @@ public async Task GetUserInfo_WithEUSignCertError_ReturnsErrorResponse()
// Arrange
var remoteUserId = "123";
var remoteToken = "secret";
var certSetup = SetupSendAsync(handler, HttpMethod.Get,
new Uri(eUSignServiceUri, "api/v1/certificate").ToString());
ReturnsHttpResponseAsync(certSetup, null, HttpStatusCode.InternalServerError);
handler.SetupSendAsync(HttpMethod.Get,
new Uri(eUSignServiceUri, "api/v1/certificate").ToString())
.ReturnsHttpResponseAsync(null, HttpStatusCode.InternalServerError);

// Act
var userInfo = await communicationService.GetUserInfo(remoteUserId, remoteToken);
Expand All @@ -152,17 +151,17 @@ public async Task GetUserInfo_WithGovError_ReturnsErrorResponse()
{
CertBase64 = "cert",
};
var certSetup = SetupSendAsync(handler, HttpMethod.Get,
new Uri(eUSignServiceUri, "api/v1/certificate").ToString());
ReturnsHttpResponseAsync(certSetup, certResponse, HttpStatusCode.OK);
handler.SetupSendAsync(HttpMethod.Get,
new Uri(eUSignServiceUri, "api/v1/certificate").ToString())
.ReturnsHttpResponseAsync(certResponse, HttpStatusCode.OK);

var errorResponse = new IdGovErrorResponse
{
Error = 1,
};

var infoSetup = SetupSendAsync(handler, HttpMethod.Get, new Uri(idServerUri, "/userinfo").ToString(), true);
ReturnsHttpResponseAsync(infoSetup, errorResponse, HttpStatusCode.Unauthorized);
handler.SetupSendAsync(HttpMethod.Get, new Uri(idServerUri, "/userinfo").ToString(), true)
.ReturnsHttpResponseAsync(errorResponse, HttpStatusCode.Unauthorized);

// Act
var userInfo = await communicationService.GetUserInfo(remoteUserId, remoteToken);
Expand Down Expand Up @@ -190,21 +189,20 @@ public async Task GetUserInfo_WithEUSignDecryptError_ReturnsErrorResponse()
{
CertBase64 = "cert",
};
var certSetup = SetupSendAsync(handler, HttpMethod.Get,
new Uri(eUSignServiceUri, "api/v1/certificate").ToString());
ReturnsHttpResponseAsync(certSetup, certResponse, HttpStatusCode.OK);
handler.SetupSendAsync(HttpMethod.Get,
new Uri(eUSignServiceUri, "api/v1/certificate").ToString())
.ReturnsHttpResponseAsync(certResponse, HttpStatusCode.OK);

var infoResponse = new EnvelopedUserInfoResponse
{
EncryptedUserInfo = "serialized_info",
};

var infoSetup = SetupSendAsync(handler, HttpMethod.Get, new Uri(idServerUri, "/userinfo").ToString(), true);
ReturnsHttpResponseAsync(infoSetup, infoResponse, HttpStatusCode.OK);
handler.SetupSendAsync(HttpMethod.Get, new Uri(idServerUri, "/userinfo").ToString(), true)
.ReturnsHttpResponseAsync(infoResponse, HttpStatusCode.OK);

var decryptSetup =
SetupSendAsync(handler, HttpMethod.Post, new Uri(eUSignServiceUri, "api/v1/decrypt").ToString());
ReturnsHttpResponseAsync(decryptSetup, null, HttpStatusCode.InternalServerError);
handler.SetupSendAsync(HttpMethod.Post, new Uri(eUSignServiceUri, "api/v1/decrypt").ToString())
.ReturnsHttpResponseAsync(null, HttpStatusCode.InternalServerError);

// Act
var userInfo = await communicationService.GetUserInfo(remoteUserId, remoteToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<NuGetAuditMode>direct</NuGetAuditMode>
</PropertyGroup>
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using OutOfSchool.Common.Config;
using OutOfSchool.Common.Models;
using OutOfSchool.Tests.Common;
using static OutOfSchool.Tests.Common.HttpClientTestHelper;

namespace OutOfSchool.WebApi.Tests.Common;

Expand Down Expand Up @@ -59,8 +58,8 @@ public async Task SendRequest_WithCorrectRequest_ReturnsOkResponse()
Url = uri,
};
var response = new TestResponse("OK");
var setup = SetupSendAsync(handler, HttpMethod.Post, uri.ToString());
ReturnsHttpResponseAsync(setup, response, HttpStatusCode.OK);
handler.SetupSendAsync(HttpMethod.Post, uri.ToString())
.ReturnsHttpResponseAsync(response, HttpStatusCode.OK);

// Act
var result = await communicationService.SendRequest<TestResponse, ErrorResponse>(request);
Expand All @@ -72,8 +71,8 @@ public async Task SendRequest_WithCorrectRequest_ReturnsOkResponse()
public async Task SendRequest_WithEmptyRequest_ReturnsErrorResponse()
{
// Arrange
var setup = SetupSendAsync(handler, HttpMethod.Get, uri.ToString());
ReturnsHttpResponseAsync(setup, null, HttpStatusCode.OK);
handler.SetupSendAsync(HttpMethod.Get, uri.ToString())
.ReturnsHttpResponseAsync(null, HttpStatusCode.OK);

// Act
var result = await communicationService.SendRequest<TestResponse, ErrorResponse>(null);
Expand All @@ -90,8 +89,8 @@ public async Task SendRequest_WithServerError_ReturnsErrorResponse()
HttpMethodType = HttpMethodType.Get,
Url = uri,
};
var setup = SetupSendAsync(handler, HttpMethod.Get, uri.ToString());
ReturnsHttpResponseAsync(setup, null, HttpStatusCode.Unauthorized);
handler.SetupSendAsync(HttpMethod.Get, uri.ToString())
.ReturnsHttpResponseAsync(null, HttpStatusCode.Unauthorized);

// Act
var result = await communicationService.SendRequest<TestResponse, ErrorResponse>(request);
Expand All @@ -108,8 +107,8 @@ public void SendRequest_WithServerErrorAndWrongHandler_ThrowsException()
HttpMethodType = HttpMethodType.Get,
Url = uri,
};
var setup = SetupSendAsync(handler, HttpMethod.Get, uri.ToString());
ReturnsHttpResponseAsync(setup, null, HttpStatusCode.Unauthorized);
handler.SetupSendAsync(HttpMethod.Get, uri.ToString())
.ReturnsHttpResponseAsync(null, HttpStatusCode.Unauthorized);

// Act
Assert.ThrowsAsync<InvalidOperationException>(() =>
Expand All @@ -125,8 +124,8 @@ public async Task SendRequest_WithServerErrorAndCustomHandler_ReturnsErrorRespon
HttpMethodType = HttpMethodType.Get,
Url = uri,
};
var setup = SetupSendAsync(handler, HttpMethod.Get, uri.ToString());
ReturnsHttpResponseAsync(setup, null, HttpStatusCode.Unauthorized);
handler.SetupSendAsync(HttpMethod.Get, uri.ToString())
.ReturnsHttpResponseAsync(null, HttpStatusCode.Unauthorized);

// Act
var result = await communicationService.SendRequest<TestResponse, TestError>(request, new TestErrorHandler());
Expand All @@ -148,8 +147,8 @@ public async Task SendRequest_WithHttpException_ReturnsErrorResponse()
Token = "secret",
Url = uri,
};
var setup = SetupSendAsync(handler, HttpMethod.Get, uri.ToString());
setup.Throws(new HttpRequestException(null, null, HttpStatusCode.InsufficientStorage));
handler.SetupSendAsync(HttpMethod.Get, uri.ToString())
.Throws(new HttpRequestException(null, null, HttpStatusCode.InsufficientStorage));

// Act
var result = await communicationService.SendRequest<TestResponse, ErrorResponse>(request);
Expand Down

0 comments on commit 83d1408

Please sign in to comment.