-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniels Danilins
committed
Jul 22, 2024
1 parent
f8a9d8a
commit d7009f1
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
tests/Keycloak.AuthServices.Sdk.Tests/KeycloakGroupClientTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace Keycloak.AuthServices.Sdk.Tests; | ||
|
||
using System.Net; | ||
using Admin; | ||
using RichardSzalay.MockHttp; | ||
|
||
public class KeycloakGroupClientTests | ||
{ | ||
private const string BaseAddress = "http://localhost:8080"; | ||
private const string MediaType = "application/json"; | ||
private readonly MockHttpMessageHandler handler = new(); | ||
private readonly IKeycloakGroupClient keycloakGroupClient; | ||
|
||
public KeycloakGroupClientTests() | ||
{ | ||
var httpClient = handler.ToHttpClient(); | ||
httpClient.BaseAddress = new Uri(BaseAddress); | ||
|
||
keycloakGroupClient = new KeycloakClient(httpClient); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteGroupShouldCallCorrectEndpoint() | ||
{ | ||
var groupId = Guid.NewGuid(); | ||
|
||
handler.Expect(HttpMethod.Delete, $"/admin/realms/master/groups/{groupId}") | ||
.Respond(HttpStatusCode.NoContent); | ||
|
||
await keycloakGroupClient.DeleteGroupAsync("master", groupId.ToString()); | ||
|
||
handler.VerifyNoOutstandingExpectation(); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteGroupShouldThrowNotFoundApiExceptionWhenGroupDoesNotExist() | ||
{ | ||
var groupId = Guid.NewGuid().ToString(); | ||
const string errorMessage = /*lang=json,strict*/ | ||
"{\"errorMessage\":\"Group name is missing\"}"; | ||
|
||
handler.Expect(HttpMethod.Delete, $"/admin/realms/master/groups/{groupId}") | ||
.Respond(HttpStatusCode.NotFound, MediaType, errorMessage); | ||
|
||
var exception = await FluentActions | ||
.Invoking(() => keycloakGroupClient.DeleteGroupAsync("master", groupId)) | ||
.Should() | ||
.ThrowAsync<KeycloakHttpClientException>(); | ||
|
||
exception.And.StatusCode.Should().Be((int)HttpStatusCode.NotFound); | ||
|
||
handler.VerifyNoOutstandingExpectation(); | ||
} | ||
} |