Skip to content

Commit 68c8710

Browse files
committed
Fixed failing unit test.
1 parent 95b2b83 commit 68c8710

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

src/Umbraco.AuthorizedServices/Services/Implement/DatabaseAuthorizationParameterStorageBase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ namespace Umbraco.AuthorizedServices.Services.Implement;
55

66
internal class DatabaseAuthorizationParameterStorageBase
77
{
8-
protected IScopeProvider ScopeProvider { get; }
9-
10-
protected ISecretEncryptor Encryptor { get; }
11-
12-
protected ILogger<DatabaseAuthorizationParameterStorageBase> Logger { get; }
13-
148
public DatabaseAuthorizationParameterStorageBase(
159
IScopeProvider scopeProvider,
1610
ISecretEncryptor encryptor,
@@ -20,4 +14,10 @@ public DatabaseAuthorizationParameterStorageBase(
2014
Encryptor = encryptor;
2115
Logger = logger;
2216
}
17+
18+
protected IScopeProvider ScopeProvider { get; }
19+
20+
protected ISecretEncryptor Encryptor { get; }
21+
22+
protected ILogger<DatabaseAuthorizationParameterStorageBase> Logger { get; }
2323
}

tests/Umbraco.AuthorizedServices.Tests/Services/AuthorizedServiceCallerTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void SetUp()
2222
}
2323

2424
[Test]
25-
public async Task SendRequestAsync_WithoutData_WithValidAccessToken_WithSuccessReponse_ReturnsExpectedResponse()
25+
public async Task SendRequestAsync_WithoutData_WithValidAccessToken_WithSuccessResponse_ReturnsExpectedResponse()
2626
{
2727
// Arrange
2828
StoreToken();
@@ -42,7 +42,7 @@ public async Task SendRequestAsync_WithoutData_WithValidAccessToken_WithSuccessR
4242
}
4343

4444
[Test]
45-
public async Task SendRequestAsync_WithoutData_WithApiKeyFromStorage_WithSuccessReponse_ReturnsExpectedResponse()
45+
public async Task SendRequestAsync_WithoutData_WithApiKeyFromStorage_WithSuccessResponse_ReturnsExpectedResponse()
4646
{
4747
// Arrange
4848
StoreApiKey();
@@ -59,7 +59,7 @@ public async Task SendRequestAsync_WithoutData_WithApiKeyFromStorage_WithSuccess
5959
}
6060

6161
[Test]
62-
public async Task SendRequestAsync_WithoutData_WithValidAccessToken_WithFaileReponse_ThrowsExpectedException()
62+
public async Task SendRequestAsync_WithoutData_WithValidAccessToken_WithFailedResponse_ThrowsExpectedException()
6363
{
6464
// Arrange
6565
StoreToken();
@@ -75,7 +75,7 @@ public async Task SendRequestAsync_WithoutData_WithValidAccessToken_WithFaileRep
7575
}
7676

7777
[Test]
78-
public async Task SendRequestRawAsync_WithoutData_WithValidAccessToken_WithSuccessReponse_ReturnsExpectedResponse()
78+
public async Task SendRequestRawAsync_WithoutData_WithValidAccessToken_WithSuccessResponse_ReturnsExpectedResponse()
7979
{
8080
// Arrange
8181
StoreToken();
@@ -169,7 +169,7 @@ public async Task SendRequestAsync_WithExpiredAccessToken_WithRefreshTokenSucces
169169
public void GetApiKey_WithExistingApiKey_ReturnsApiKey()
170170
{
171171
// Arrange
172-
AuthorizedServiceCaller sut = CreateService(authenticationMethod: AuthenticationMethod.ApiKey);
172+
AuthorizedServiceCaller sut = CreateService(authenticationMethod: AuthenticationMethod.ApiKey, withConfiguredApiKey: true);
173173

174174
// Act
175175
var result = sut.GetApiKey(ServiceAlias);
@@ -184,7 +184,7 @@ public void GetApiKey_WithStoredApiKey_ReturnsStoredApiKey()
184184
{
185185
// Arrange
186186
StoreApiKey();
187-
AuthorizedServiceCaller sut = CreateService(authenticationMethod: AuthenticationMethod.ApiKey);
187+
AuthorizedServiceCaller sut = CreateService(authenticationMethod: AuthenticationMethod.ApiKey, withConfiguredApiKey: false);
188188

189189
// Act
190190
var result = sut.GetApiKey(ServiceAlias);
@@ -250,7 +250,8 @@ private AuthorizedServiceCaller CreateService(
250250
HttpStatusCode statusCode = HttpStatusCode.OK,
251251
string? responseContent = null,
252252
HttpStatusCode refreshTokenStatusCode = HttpStatusCode.OK,
253-
AuthenticationMethod authenticationMethod = AuthenticationMethod.OAuth2AuthorizationCode)
253+
AuthenticationMethod authenticationMethod = AuthenticationMethod.OAuth2AuthorizationCode,
254+
bool withConfiguredApiKey = false)
254255
{
255256
var authorizationRequestSenderMock = new Mock<IAuthorizationRequestSender>();
256257

@@ -264,7 +265,7 @@ private AuthorizedServiceCaller CreateService(
264265
.Setup(x => x.SendRequest(It.Is<ServiceDetail>(y => y.Alias == ServiceAlias), It.Is<Dictionary<string, string>>(y => y["grant_type"] == "refresh_token")))
265266
.ReturnsAsync(httpResponseMessage);
266267

267-
Mock<IOptionsMonitor<ServiceDetail>> optionsMonitorServiceDetailMock = CreateOptionsMonitorServiceDetail(authenticationMethod);
268+
Mock<IOptionsMonitor<ServiceDetail>> optionsMonitorServiceDetailMock = CreateOptionsMonitorServiceDetail(authenticationMethod, withConfiguredApiKey);
268269
var factory = new JsonSerializerFactory(optionsMonitorServiceDetailMock.Object, new JsonNetSerializer());
269270

270271
return new AuthorizedServiceCaller(

tests/Umbraco.AuthorizedServices.Tests/Services/AuthorizedServiceTestsBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ internal abstract class AuthorizedServiceTestsBase
1313
protected Mock<IKeyStorage> KeyStorageMock { get; set; } = null!;
1414

1515
protected static Mock<IOptionsMonitor<ServiceDetail>> CreateOptionsMonitorServiceDetail(
16-
AuthenticationMethod authenticationMethod = AuthenticationMethod.OAuth2AuthorizationCode)
16+
AuthenticationMethod authenticationMethod = AuthenticationMethod.OAuth2AuthorizationCode,
17+
bool withConfiguredApiKey = false)
1718
{
1819
var optionsMonitorServiceDetailMock = new Mock<IOptionsMonitor<ServiceDetail>>();
1920
optionsMonitorServiceDetailMock.Setup(o => o.Get(ServiceAlias)).Returns(new ServiceDetail()
@@ -22,7 +23,7 @@ protected static Mock<IOptionsMonitor<ServiceDetail>> CreateOptionsMonitorServic
2223
ApiHost = "https://service.url",
2324
AuthenticationMethod = authenticationMethod,
2425
JsonSerializer = JsonSerializerOption.JsonNet,
25-
ApiKey = authenticationMethod == AuthenticationMethod.ApiKey ? "test-api-key" : string.Empty,
26+
ApiKey = authenticationMethod == AuthenticationMethod.ApiKey && withConfiguredApiKey ? "test-api-key" : string.Empty,
2627
ApiKeyProvision = authenticationMethod == AuthenticationMethod.ApiKey
2728
? new ApiKeyProvision { Method = ApiKeyProvisionMethod.QueryString, Key = "key"} : null
2829
});

0 commit comments

Comments
 (0)