-
Notifications
You must be signed in to change notification settings - Fork 31
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
Showing
24 changed files
with
550 additions
and
267 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Kentico.Kontent.Management.Models.LanguageVariants; | ||
using Kentico.Kontent.Management.Models.Shared; | ||
using Kentico.Kontent.Management.UrlBuilder; | ||
|
@@ -233,6 +234,41 @@ public void BuildItemUrl_ReturnsValidationUrl() | |
|
||
#endregion | ||
|
||
[Fact] | ||
public void BuildUsersUrl_ReturnsExpectedUrl() | ||
{ | ||
var expectedResult = $"{ENDPOINT}/projects/{PROJECT_ID}/users"; | ||
var actualResult = _builder.BuildUsersUrl(); | ||
|
||
Assert.Equal(expectedResult, actualResult); | ||
} | ||
|
||
[Fact] | ||
public void BuildModifyUsersRoleUrl_WithEmail_ReturnsExpectedUrl() | ||
{ | ||
var email = "[email protected]"; | ||
var expectedResult = $"{ENDPOINT}/projects/{PROJECT_ID}/users/email/{email}/roles"; | ||
var actualResult = _builder.BuildModifyUsersRoleUrl(UserIdentifier.ByEmail(email)); | ||
|
||
Assert.Equal(expectedResult, actualResult); | ||
} | ||
|
||
[Fact] | ||
public void BuildModifyUsersRoleUrl_WithId_ReturnsExpectedUrl() | ||
{ | ||
var id = "id"; | ||
var expectedResult = $"{ENDPOINT}/projects/{PROJECT_ID}/users/{id}/roles"; | ||
var actualResult = _builder.BuildModifyUsersRoleUrl(UserIdentifier.ById(id)); | ||
|
||
Assert.Equal(expectedResult, actualResult); | ||
} | ||
|
||
[Fact] | ||
public void BuildModifyUsersRoleUrl_MissingId_MissingEmail_ThrowsException() | ||
{ | ||
_builder.Invoking(x => x.BuildModifyUsersRoleUrl(UserIdentifier.ByEmail(null))).Should().ThrowExactly<ArgumentException>(); | ||
} | ||
|
||
[Fact] | ||
public void BuildProjectRolesUrl_ReturnsCorrectUrl() | ||
{ | ||
|
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
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
using Kentico.Kontent.Management.Models.Types.Patch; | ||
using Kentico.Kontent.Management.Models.TypeSnippets; | ||
using Kentico.Kontent.Management.Models.TypeSnippets.Patch; | ||
using Kentico.Kontent.Management.Models.Users; | ||
using Kentico.Kontent.Management.Models.Webhooks; | ||
using Kentico.Kontent.Management.Models.Webhooks.Triggers; | ||
using Kentico.Kontent.Management.Models.Workflow; | ||
|
@@ -1144,6 +1145,39 @@ public async void PostWebhook() | |
Assert.NotNull(response); | ||
} | ||
|
||
// DocSection: cm_api_v2_post_user | ||
// Tip: Find more about .NET SDKs at https://docs.kontent.ai/net | ||
[Fact] | ||
public async void PostUser() | ||
{ | ||
var client = _fileSystemFixture.CreateMockClientWithResponse("ProjectUser.json"); | ||
|
||
var response = await client.InviteUserIntoProjectAsync(new UserInviteModel | ||
{ | ||
CollectionGroup = new List<UserCollectionGroup> | ||
{ | ||
new UserCollectionGroup | ||
{ | ||
Collections = new List<Reference> | ||
{ | ||
Reference.ById(Guid.Empty), | ||
Reference.ById(Guid.Parse("28b68213-d636-4b01-9fd1-988b93789e17")) | ||
}, | ||
Roles = new List<Role> | ||
{ | ||
new Role | ||
{ | ||
Id = Guid.Parse("f58733b9-520b-406b-9d45-eb15a2baee96"), | ||
Languages = new List<Reference>() { Reference.ById(Guid.Parse("7df9a691-cf29-402d-9598-66273e7561b7")) } | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
Assert.NotNull(response); | ||
} | ||
|
||
// DocSection: cm_api_v2_put_asset | ||
// Tip: Find more about .NET SDKs at https://docs.kontent.ai/net | ||
[Fact] | ||
|
@@ -1455,5 +1489,42 @@ public async void PutEnableWebhook() | |
await client.EnableWebhookAsync(Reference.ById(Guid.Parse("5df74e27-1213-484e-b9ae-bcbe90bd5990")))); | ||
Assert.Null(exception); | ||
} | ||
|
||
// DocSection: cm_api_v2_put_user | ||
// Tip: Find more about .NET SDKs at https://docs.kontent.ai/net | ||
[Fact] | ||
public async void PutUser() | ||
{ | ||
var client = _fileSystemFixture.CreateMockClientWithResponse("ProjectUser.json"); | ||
|
||
var identifier = UserIdentifier.ByEmail("[email protected]"); | ||
//var identifier = UserIdentifier.ById("d94bc87a-c066-48a1-a910-4f991ccc1fb5"); | ||
|
||
var response = await client.ModifyUsersRolesAsync( | ||
identifier, | ||
new UserModel | ||
{ | ||
CollectionGroup = new List<UserCollectionGroup> | ||
{ | ||
new UserCollectionGroup | ||
{ | ||
Collections = new List<Reference> | ||
{ | ||
Reference.ById(Guid.Empty), | ||
}, | ||
Roles = new List<Role> | ||
{ | ||
new Role | ||
{ | ||
Id = Guid.Parse("f58733b9-520b-406b-9d45-eb15a2baee96"), | ||
Languages = new List<Reference>() { Reference.ByCodename("english") } | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
Assert.NotNull(response); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Kentico.Kontent.Management.Tests/Unit/Data/CodeSamples/ProjectUser.json
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,25 @@ | ||
{ | ||
"user_id": "d94bc87a-c066-48a1-a910-4f991ccc1fb5", | ||
"collection_groups": [ | ||
{ | ||
"collections": [ | ||
{ | ||
"id": "00000000-0000-0000-0000-000000000000" | ||
}, | ||
{ | ||
"id": "28b68213-d636-4b01-9fd1-988b93789e17" | ||
} | ||
], | ||
"roles": [ | ||
{ | ||
"id": "f58733b9-520b-406b-9d45-eb15a2baee96", | ||
"languages": [ | ||
{ | ||
"id": "7df9a691-cf29-402d-9598-66273e7561b7" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
Kentico.Kontent.Management.Tests/Unit/Data/ProjectUser/ProjectUser.json
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,17 @@ | ||
{ | ||
"user_id": "usr_0vRMQhkfhH0A5azU753QPz", | ||
"collection_groups": [ | ||
{ | ||
"collections": [ { "id": "00000000-0000-0000-0000-000000000000" } ], | ||
"roles": [ | ||
{ | ||
"id": "97a2590d-340b-4e7b-a9e8-569a96d24990", | ||
"languages": [ | ||
{ "id": "00000000-0000-0000-0000-000000000000" }, | ||
{ "id": "78dbefe8-831b-457e-9352-f4c4eacd5024" } | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
79 changes: 79 additions & 0 deletions
79
Kentico.Kontent.Management.Tests/Unit/ManagementClientTests/ProjectUserTests.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,79 @@ | ||
using FluentAssertions; | ||
using Kentico.Kontent.Management.Models.Shared; | ||
using Kentico.Kontent.Management.Models.Users; | ||
using Kentico.Kontent.Management.Tests.Unit.Base; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Kentico.Kontent.Management.Tests.Unit.ManagementClientTests | ||
{ | ||
public class ProjectUserTests : IClassFixture<FileSystemFixture> | ||
{ | ||
private FileSystemFixture _fileSystemFixture; | ||
|
||
public ProjectUserTests(FileSystemFixture fileSystemFixture) | ||
{ | ||
_fileSystemFixture = fileSystemFixture; | ||
_fileSystemFixture.SetSubFolder("ProjectUser"); | ||
} | ||
|
||
[Fact] | ||
public async Task InviteUser_InvitesUser() | ||
{ | ||
var client = _fileSystemFixture.CreateMockClientWithResponse("ProjectUser.json"); | ||
|
||
var expected = _fileSystemFixture.GetExpectedResponse<UserModel>("ProjectUser.json"); | ||
|
||
var invitation = new UserInviteModel | ||
{ | ||
email = "[email protected]", | ||
CollectionGroup = expected.CollectionGroup | ||
}; | ||
|
||
var response = await client.InviteUserIntoProjectAsync(invitation); | ||
|
||
response.Should().BeEquivalentTo(expected); | ||
} | ||
|
||
[Fact] | ||
public async Task InviteUser_UserInvitationModelNotProvided_ThrowsException() | ||
{ | ||
var client = _fileSystemFixture.CreateMockClientWithResponse("ProjectUser.json"); | ||
|
||
await client.Invoking(x => x.InviteUserIntoProjectAsync(null)).Should().ThrowExactlyAsync<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public async Task ModifyUsersRole_ByEmail_ModifiesUserRoles() | ||
{ | ||
var client = _fileSystemFixture.CreateMockClientWithResponse("ProjectUser.json"); | ||
|
||
var expected = _fileSystemFixture.GetExpectedResponse<UserModel>("ProjectUser.json"); | ||
|
||
var response = await client.ModifyUsersRolesAsync(UserIdentifier.ByEmail("[email protected]"), expected); | ||
|
||
response.Should().BeEquivalentTo(expected); | ||
} | ||
|
||
[Fact] | ||
public async Task ModifyUsersRole_ById_ModifiesUserRoles() | ||
{ | ||
var client = _fileSystemFixture.CreateMockClientWithResponse("ProjectUser.json"); | ||
|
||
var expected = _fileSystemFixture.GetExpectedResponse<UserModel>("ProjectUser.json"); | ||
|
||
var response = await client.ModifyUsersRolesAsync(UserIdentifier.ById(expected.Id), expected); | ||
|
||
response.Should().BeEquivalentTo(expected); | ||
} | ||
|
||
[Fact] | ||
public async Task ModifyUsersRole_NullIdentifier_ModifiesUserRoles() | ||
{ | ||
var client = _fileSystemFixture.CreateMockClientWithResponse("ProjectUser.json"); | ||
|
||
await client.Invoking(x => x.ModifyUsersRolesAsync(null, new UserModel())).Should().ThrowExactlyAsync<ArgumentNullException>(); | ||
} | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.