-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor API structure #933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/XtremeIdiots.Portal.Integrations.Servers.Abstractions.V1/Interfaces/V1/IApiHealthApi.cs
This file contains hidden or 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,8 @@ | ||
| using MX.Api.Abstractions; | ||
|
|
||
| namespace XtremeIdiots.Portal.Integrations.Servers.Abstractions.Interfaces.V1; | ||
|
|
||
| public interface IApiHealthApi | ||
| { | ||
| Task<ApiResult> CheckHealth(CancellationToken cancellationToken = default); | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/XtremeIdiots.Portal.Integrations.Servers.Abstractions.V1/Interfaces/V1/IApiInfoApi.cs
This file contains hidden or 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,9 @@ | ||
| using MX.Api.Abstractions; | ||
| using XtremeIdiots.Portal.Integrations.Servers.Abstractions.Models.V1; | ||
|
|
||
| namespace XtremeIdiots.Portal.Integrations.Servers.Abstractions.Interfaces.V1; | ||
|
|
||
| public interface IApiInfoApi | ||
| { | ||
| Task<ApiResult<ApiInfoDto>> GetApiInfo(CancellationToken cancellationToken = default); | ||
| } |
8 changes: 0 additions & 8 deletions
8
src/XtremeIdiots.Portal.Integrations.Servers.Abstractions.V1/Interfaces/V1/IRootApi.cs
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
src/XtremeIdiots.Portal.Integrations.Servers.Abstractions.V1/Models/V1/ApiInfoDto.cs
This file contains hidden or 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,8 @@ | ||
| namespace XtremeIdiots.Portal.Integrations.Servers.Abstractions.Models.V1; | ||
|
|
||
| public class ApiInfoDto | ||
| { | ||
| public string Version { get; set; } = string.Empty; | ||
| public string BuildVersion { get; set; } = string.Empty; | ||
| public string AssemblyVersion { get; set; } = string.Empty; | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
...tremeIdiots.Portal.Integrations.Servers.Api.Client.Testing.Tests/FakeApiHealthApiTests.cs
This file contains hidden or 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,50 @@ | ||
| using System.Net; | ||
| using XtremeIdiots.Portal.Integrations.Servers.Api.Client.Testing; | ||
|
|
||
| namespace XtremeIdiots.Portal.Integrations.Servers.Api.Client.Testing.Tests; | ||
|
|
||
| [Trait("Category", "Unit")] | ||
| public class FakeApiHealthApiTests | ||
| { | ||
| [Fact] | ||
| public async Task CheckHealth_DefaultStatusCode_ReturnsSuccess() | ||
| { | ||
| var fakeApi = new FakeApiHealthApi(); | ||
|
|
||
| var result = await fakeApi.CheckHealth(); | ||
|
|
||
| Assert.True(result.IsSuccess); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CheckHealth_WithErrorStatusCode_ReturnsError() | ||
| { | ||
| var fakeApi = new FakeApiHealthApi(); | ||
| fakeApi.WithStatusCode(HttpStatusCode.ServiceUnavailable); | ||
|
|
||
| var result = await fakeApi.CheckHealth(); | ||
|
|
||
| Assert.False(result.IsSuccess); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Reset_RestoresDefaultStatusCode() | ||
| { | ||
| var fakeApi = new FakeApiHealthApi(); | ||
| fakeApi.WithStatusCode(HttpStatusCode.InternalServerError); | ||
|
|
||
| fakeApi.Reset(); | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, fakeApi.StatusCode); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void FluentApi_SupportsChainingCalls() | ||
| { | ||
| var fakeApi = new FakeApiHealthApi(); | ||
|
|
||
| var result = fakeApi.WithStatusCode(HttpStatusCode.OK); | ||
|
|
||
| Assert.Same(fakeApi, result); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
37 changes: 37 additions & 0 deletions
37
src/XtremeIdiots.Portal.Integrations.Servers.Api.Client.Testing/FakeApiInfoApi.cs
This file contains hidden or 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,37 @@ | ||
| using System.Net; | ||
| using MX.Api.Abstractions; | ||
| using XtremeIdiots.Portal.Integrations.Servers.Abstractions.Interfaces.V1; | ||
| using XtremeIdiots.Portal.Integrations.Servers.Abstractions.Models.V1; | ||
|
|
||
| namespace XtremeIdiots.Portal.Integrations.Servers.Api.Client.Testing; | ||
|
|
||
| /// <summary> | ||
| /// In-memory fake of <see cref="IApiInfoApi"/> for unit and integration testing. | ||
| /// </summary> | ||
| public class FakeApiInfoApi : IApiInfoApi | ||
| { | ||
| public HttpStatusCode StatusCode { get; private set; } = HttpStatusCode.OK; | ||
|
|
||
| public FakeApiInfoApi WithStatusCode(HttpStatusCode statusCode) | ||
| { | ||
| StatusCode = statusCode; | ||
| return this; | ||
| } | ||
|
|
||
| public void Reset() | ||
| { | ||
| StatusCode = HttpStatusCode.OK; | ||
| } | ||
|
|
||
| public Task<ApiResult<ApiInfoDto>> GetApiInfo(CancellationToken cancellationToken = default) | ||
| { | ||
| return Task.FromResult(StatusCode == HttpStatusCode.OK | ||
| ? new ApiResult<ApiInfoDto>(HttpStatusCode.OK, new ApiResponse<ApiInfoDto>(new ApiInfoDto | ||
| { | ||
| Version = "1.0.0", | ||
| BuildVersion = "1.0.0", | ||
| AssemblyVersion = "1.0.0.0" | ||
| })) | ||
| : new ApiResult<ApiInfoDto>(StatusCode, new ApiResponse<ApiInfoDto>(new ApiError("ERROR", "Error")))); | ||
| } | ||
frasermolyneux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.