-
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.
Merge branch 'add-missing-generics' of https://github.com/DiegoFaFe/m…
…anagement-sdk-net into add-missing-generics
- Loading branch information
Showing
18 changed files
with
337 additions
and
0 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
4 changes: 4 additions & 0 deletions
4
Kontent.Ai.Management.Tests/Data/WebSpotlight/ActivationWebSpotlightResponse.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,4 @@ | ||
{ | ||
"enabled": true, | ||
"root_type": "0689fcb3-24f1-49f4-b115-e7b816d59e9d" | ||
} |
4 changes: 4 additions & 0 deletions
4
...agement.Tests/Data/WebSpotlight/ActivationWebSpotlightWithProvidedRootTypeIdResponse.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,4 @@ | ||
{ | ||
"enabled": true, | ||
"root_type": "3660e894-bae8-4dcd-9d3e-5fc9205c2ece" | ||
} |
4 changes: 4 additions & 0 deletions
4
Kontent.Ai.Management.Tests/Data/WebSpotlight/DeactivationWebSpotlightResponse.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,4 @@ | ||
{ | ||
"enabled": false, | ||
"root_type": "0689fcb3-24f1-49f4-b115-e7b816d59e9d" | ||
} |
4 changes: 4 additions & 0 deletions
4
Kontent.Ai.Management.Tests/Data/WebSpotlight/GetStatusWebSpotlightResponse.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,4 @@ | ||
{ | ||
"enabled": true, | ||
"root_type": "0689fcb3-24f1-49f4-b115-e7b816d59e9d" | ||
} |
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
113 changes: 113 additions & 0 deletions
113
Kontent.Ai.Management.Tests/ManagementClientTests/WebSpotlightTests.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,113 @@ | ||
using Kontent.Ai.Management.Models.Shared; | ||
using Kontent.Ai.Management.Models.WebSpotlight; | ||
using Kontent.Ai.Management.Tests.Base; | ||
using System; | ||
using System.Net.Http; | ||
using Xunit; | ||
using static Kontent.Ai.Management.Tests.Base.Scenario; | ||
|
||
namespace Kontent.Ai.Management.Tests.ManagementClientTests; | ||
|
||
public class WebSpotlightTests : IClassFixture<FileSystemFixture> | ||
{ | ||
private static readonly string WebSpotlightBaseUrl = $"{Endpoint}/projects/{ENVIRONMENT_ID}/web-spotlight"; | ||
private readonly Scenario _scenario = new(folder: "WebSpotlight"); | ||
|
||
[Fact] | ||
public async void ActivateWebSpotlight_Returns_EnabledStatusAndRootTypeId() | ||
{ | ||
var client = _scenario | ||
.WithResponses("ActivationWebSpotlightResponse.json") | ||
.CreateManagementClient(); | ||
|
||
var webSpotlightActivateModel = new WebSpotlightActivateModel { RootType = null }; | ||
|
||
var response = await client | ||
.ActivateWebSpotlightAsync(webSpotlightActivateModel); | ||
|
||
_scenario | ||
.CreateExpectations() | ||
.HttpMethod(HttpMethod.Put) | ||
.Response(response) | ||
.Url(WebSpotlightBaseUrl) | ||
.Validate(); | ||
} | ||
|
||
[Fact] | ||
public async void ActivateWebSpotlight_WithProvidedValidRootTypeById_Returns_EnabledStatusAndRootTypeId() | ||
{ | ||
var client = _scenario | ||
.WithResponses("ActivationWebSpotlightWithProvidedRootTypeIdResponse.json") | ||
.CreateManagementClient(); | ||
|
||
var rootTypeId = Guid.Parse("3660e894-bae8-4dcd-9d3e-5fc9205c2ece"); | ||
var reference = Reference.ById(rootTypeId); | ||
var webSpotlightActivateModel = new WebSpotlightActivateModel { RootType = reference }; | ||
|
||
await client.ActivateWebSpotlightAsync(webSpotlightActivateModel); | ||
|
||
_scenario | ||
.CreateExpectations() | ||
.HttpMethod(HttpMethod.Put) | ||
.RequestPayload(webSpotlightActivateModel) | ||
.Url(WebSpotlightBaseUrl) | ||
.Validate(); | ||
} | ||
|
||
[Fact] | ||
public async void ActivateWebSpotlight_WithProvidedValidRootTypeByCodename_Returns_EnabledStatusAndRootTypeId() | ||
{ | ||
var client = _scenario | ||
.WithResponses("ActivationWebSpotlightWithProvidedRootTypeIdResponse.json") | ||
.CreateManagementClient(); | ||
|
||
var rootTypeCodename = "root_type_codename"; | ||
var reference = Reference.ByCodename(rootTypeCodename); | ||
var webSpotlightActivateModel = new WebSpotlightActivateModel { RootType = reference }; | ||
|
||
await client.ActivateWebSpotlightAsync(webSpotlightActivateModel); | ||
|
||
_scenario | ||
.CreateExpectations() | ||
.HttpMethod(HttpMethod.Put) | ||
.RequestPayload(webSpotlightActivateModel) | ||
.Url(WebSpotlightBaseUrl) | ||
.Validate(); | ||
} | ||
|
||
[Fact] | ||
public async void DeactivateWebSpotlight_Returns_DisabledStatusAndRootTypeId() | ||
{ | ||
var client = _scenario | ||
.WithResponses("DeactivationWebSpotlightResponse.json") | ||
.CreateManagementClient(); | ||
|
||
var response = await client | ||
.DeactivateWebSpotlightAsync(); | ||
|
||
_scenario | ||
.CreateExpectations() | ||
.HttpMethod(HttpMethod.Put) | ||
.Response(response) | ||
.Url(WebSpotlightBaseUrl) | ||
.Validate(); | ||
} | ||
|
||
[Fact] | ||
public async void GetWebSpotlightStatus_Returns_StatusAndRootTypeId() | ||
{ | ||
var client = _scenario | ||
.WithResponses("GetStatusWebSpotlightResponse.json") | ||
.CreateManagementClient(); | ||
|
||
var response = await client | ||
.GetWebSpotlightStatusAsync(); | ||
|
||
_scenario | ||
.CreateExpectations() | ||
.HttpMethod(HttpMethod.Get) | ||
.Response(response) | ||
.Url(WebSpotlightBaseUrl) | ||
.Validate(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Kontent.Ai.Management.Tests/Modules/UrlBuilder/WebSpotlightTests.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,15 @@ | ||
using Xunit; | ||
|
||
namespace Kontent.Ai.Management.Tests.Modules.UrlBuilder; | ||
|
||
public partial class EndpointUrlBuilderTests | ||
{ | ||
[Fact] | ||
public void BuildWebSpotlightUrl_ReturnsWebSpotlightUrl() | ||
{ | ||
var expectedUrl = $"{ENDPOINT}/projects/{ENVIRONMENT_ID}/web-spotlight"; | ||
var actualUrl = _builder.BuildWebSpotlightUrl(); | ||
|
||
Assert.Equal(expectedUrl, actualUrl); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Kontent.Ai.Management.Models.WebSpotlight; | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace Kontent.Ai.Management; | ||
|
||
/// <summary> | ||
/// Executes requests against the Kontent.ai Management API. | ||
/// </summary> | ||
public partial class ManagementClient | ||
{ | ||
/// <inheritdoc /> | ||
public async Task<WebSpotlightModel> ActivateWebSpotlightAsync(WebSpotlightActivateModel webSpotlightActivateModel) | ||
{ | ||
ArgumentNullException.ThrowIfNull(webSpotlightActivateModel); | ||
|
||
var endpointUrl = _urlBuilder.BuildWebSpotlightUrl(); | ||
return await _actionInvoker.InvokeMethodAsync<WebSpotlightActivateModel, WebSpotlightModel>(endpointUrl, HttpMethod.Put, webSpotlightActivateModel); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<WebSpotlightModel> DeactivateWebSpotlightAsync() | ||
{ | ||
var endpointUrl = _urlBuilder.BuildWebSpotlightUrl(); | ||
return await _actionInvoker.InvokeReadOnlyMethodAsync<WebSpotlightModel>(endpointUrl, HttpMethod.Put); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<WebSpotlightModel> GetWebSpotlightStatusAsync() | ||
{ | ||
var endpointUrl = _urlBuilder.BuildWebSpotlightUrl(); | ||
return await _actionInvoker.InvokeReadOnlyMethodAsync<WebSpotlightModel>(endpointUrl, HttpMethod.Get); | ||
} | ||
} |
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.