-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from msx752/development
bugfix & package version upgrades and new XUnit Tests
- Loading branch information
Showing
17 changed files
with
428 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This workflow will build a .NET project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | ||
name: xunit-tests | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
dotnet-version: [ '7.0.x' ] | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }} | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: ${{ matrix.dotnet-version }} | ||
|
||
- name: Install dependencies | ||
run: dotnet restore | ||
|
||
- name: Test | ||
run: dotnet test test/SampleDotnet.Result.Tests/SampleDotnet.Result.Tests.csproj --no-restore --verbosity normal |
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
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,26 @@ | ||
namespace SampleDotnet.Result | ||
{ | ||
public class StatusCodeResponse | ||
: BaseJsonResult | ||
{ | ||
public StatusCodeResponse(int statusCode) : base(statusCode) | ||
{ | ||
} | ||
|
||
public StatusCodeResponse(int statusCode, IEnumerable<string> errorMessages) : base(statusCode, errorMessages) | ||
{ | ||
} | ||
|
||
public StatusCodeResponse(int statusCode, string errorMessages) : base(statusCode, errorMessages) | ||
{ | ||
} | ||
|
||
public StatusCodeResponse(int statusCode, object body) : base(statusCode, body) | ||
{ | ||
} | ||
|
||
public StatusCodeResponse(int statusCode, IEnumerable<object> body) : base(statusCode, body) | ||
{ | ||
} | ||
} | ||
} |
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,71 @@ | ||
namespace SampleDotnet.Result.Tests; | ||
|
||
public class BadRequestResponseTests | ||
{ | ||
private const int statusCode_BADREQUEST = 400; | ||
|
||
[Fact] | ||
public void BadRequestResponse_Default() | ||
{ | ||
BadRequestResponse response = new BadRequestResponse(); | ||
|
||
response.Model.Errors.ShouldBeNull(); | ||
response.ShouldBeDefaultResponseModel(new ResponseModel()); | ||
} | ||
|
||
[Fact] | ||
public void BadRequestResponse_Ctor1() | ||
{ | ||
string responseObject = "error message1"; | ||
BadRequestResponse response = new BadRequestResponse(responseObject); | ||
|
||
response.ShouldValidatetCommons(statusCode_BADREQUEST); | ||
response.Model.ShouldNotBeNull(); | ||
response.Model.GetType().ShouldBeEquivalentTo(typeof(ResponseModel)); | ||
|
||
ResponseModel responseModel = new ResponseModel(responseObject); | ||
response.ShouldSerializeAndDeserialize(responseModel); | ||
} | ||
|
||
[Fact] | ||
public void BadRequestResponse_Ctor2() | ||
{ | ||
IEnumerable<string> responseObjects = new List<string> { "error message1", "error message2" }; | ||
BadRequestResponse response = new BadRequestResponse(responseObjects); | ||
|
||
response.ShouldValidatetCommons(statusCode_BADREQUEST); | ||
response.Model.ShouldNotBeNull(); | ||
response.Model.GetType().ShouldBeEquivalentTo(typeof(ResponseModel)); | ||
|
||
ResponseModel responseModel = new ResponseModel(responseObjects); | ||
response.ShouldSerializeAndDeserialize(responseModel); | ||
} | ||
|
||
[Fact] | ||
public void StatusCodeResponse_Ctor1() | ||
{ | ||
string responseObject = "error message1"; | ||
StatusCodeResponse response = new StatusCodeResponse(statusCode_BADREQUEST, responseObject); | ||
|
||
response.ShouldValidatetCommons(statusCode_BADREQUEST); | ||
response.Model.ShouldNotBeNull(); | ||
response.Model.GetType().ShouldBeEquivalentTo(typeof(ResponseModel)); | ||
|
||
ResponseModel responseModel = new ResponseModel(responseObject); | ||
response.ShouldSerializeAndDeserialize(responseModel); | ||
} | ||
|
||
[Fact] | ||
public void StatusCodeResponse_Ctor2() | ||
{ | ||
IEnumerable<string> responseObjects = new List<string> { "error message1", "error message2" }; | ||
StatusCodeResponse response = new StatusCodeResponse(statusCode_BADREQUEST, responseObjects); | ||
|
||
response.ShouldValidatetCommons(statusCode_BADREQUEST); | ||
response.Model.ShouldNotBeNull(); | ||
response.Model.GetType().ShouldBeEquivalentTo(typeof(ResponseModel)); | ||
|
||
ResponseModel responseModel = new ResponseModel(responseObjects); | ||
response.ShouldSerializeAndDeserialize(responseModel); | ||
} | ||
} |
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,10 @@ | ||
namespace SampleDotnet.Result.Tests; | ||
|
||
public class ExecuteTests | ||
{ | ||
[Fact] | ||
public void Execute_Stats1() | ||
{ | ||
//TODO: initialize demo app with WebApplicationFactory then exetuce ActionContext | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
test/SampleDotnet.Result.Tests/InternalServerErrorResponseTests.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,43 @@ | ||
namespace SampleDotnet.Result.Tests; | ||
|
||
public class InternalServerErrorResponseTests | ||
{ | ||
private const int statusCode_INTERNALSERVERERROR = 500; | ||
|
||
[Fact] | ||
public void InternalServerErrorResponse_Default() | ||
{ | ||
InternalServerErrorResponse response = new InternalServerErrorResponse(); | ||
|
||
response.Model.Errors.ShouldBeNull(); | ||
response.ShouldBeDefaultResponseModel(new ResponseModel()); | ||
} | ||
|
||
[Fact] | ||
public void InternalServerErrorResponse_Ctor1() | ||
{ | ||
string responseObject = "User Friendly Message1"; | ||
InternalServerErrorResponse response = new InternalServerErrorResponse(responseObject); | ||
|
||
response.ShouldValidatetCommons(statusCode_INTERNALSERVERERROR); | ||
response.Model.ShouldNotBeNull(); | ||
response.Model.GetType().ShouldBeEquivalentTo(typeof(ResponseModel)); | ||
|
||
ResponseModel responseModel = new ResponseModel(responseObject); | ||
response.ShouldSerializeAndDeserialize(responseModel); | ||
} | ||
|
||
[Fact] | ||
public void InternalServerErrorResponse_Ctor2() | ||
{ | ||
IEnumerable<string> responseObjects = new List<string> { "User Friendly Message1", "User Friendly Message2" }; | ||
InternalServerErrorResponse response = new InternalServerErrorResponse(responseObjects); | ||
|
||
response.ShouldValidatetCommons(statusCode_INTERNALSERVERERROR); | ||
response.Model.ShouldNotBeNull(); | ||
response.Model.GetType().ShouldBeEquivalentTo(typeof(ResponseModel)); | ||
|
||
ResponseModel responseModel = new ResponseModel(responseObjects); | ||
response.ShouldSerializeAndDeserialize(responseModel); | ||
} | ||
} |
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,29 @@ | ||
namespace SampleDotnet.Result.Tests; | ||
|
||
public class NotFoundResponseTests | ||
{ | ||
private const int statusCode_NOTFOUND = 404; | ||
|
||
[Fact] | ||
public void NotFoundResponse_Default() | ||
{ | ||
NotFoundResponse response = new NotFoundResponse(); | ||
|
||
response.Model.Errors.ShouldBeNull(); | ||
response.ShouldBeDefaultResponseModel(new ResponseModel()); | ||
} | ||
|
||
[Fact] | ||
public void NotFoundResponse_Ctor1() | ||
{ | ||
string responseObject = "NotFound error message1"; | ||
NotFoundResponse response = new NotFoundResponse(responseObject); | ||
|
||
response.ShouldValidatetCommons(statusCode_NOTFOUND); | ||
response.Model.ShouldNotBeNull(); | ||
response.Model.GetType().ShouldBeEquivalentTo(typeof(ResponseModel)); | ||
|
||
ResponseModel responseModel = new ResponseModel(responseObject); | ||
response.ShouldSerializeAndDeserialize(responseModel); | ||
} | ||
} |
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,78 @@ | ||
namespace SampleDotnet.Result.Tests; | ||
|
||
public class OkResponseTests | ||
{ | ||
private const int statusCode_OK = 200; | ||
|
||
[Fact] | ||
public void OkResponse_Default() | ||
{ | ||
OkResponse response = new OkResponse(); | ||
|
||
response.Model.Errors.ShouldBeNull(); | ||
response.ShouldValidatetCommons(statusCode_OK); | ||
response.ShouldBeDefaultResponseModel(new ResponseModel()); | ||
} | ||
|
||
[Fact] | ||
public void OkResponse_Ctor1() | ||
{ | ||
OkResponseTestData responseObject = new OkResponseTestData { strval1 = "valueOfName" }; | ||
OkResponse response = new OkResponse(responseObject); | ||
|
||
response.ShouldValidatetCommons(statusCode_OK); | ||
response.Model.Errors.ShouldBeNull(); | ||
response.Model.GetType().ShouldBeEquivalentTo(typeof(ResponseModel<object>)); | ||
|
||
ResponseModel<OkResponseTestData> responseModel = new ResponseModel<OkResponseTestData>(responseObject); | ||
response.ShouldSerializeAndDeserialize(responseModel); | ||
} | ||
|
||
[Fact] | ||
public void OkResponse_Ctor2() | ||
{ | ||
IEnumerable<OkResponseTestData> responseObjects = new List<OkResponseTestData> { new OkResponseTestData() { strval1 = "valueOfName1", intval1 = 1 }, new OkResponseTestData { strval1 = "valueOfName2", intval1 = 2 } }; | ||
OkResponse response = new OkResponse(responseObjects); | ||
|
||
response.ShouldValidatetCommons(statusCode_OK); | ||
response.Model.Errors.ShouldBeNull(); | ||
response.Model.GetType().ShouldBeEquivalentTo(typeof(ResponseModel<object>)); | ||
|
||
ResponseModel<OkResponseTestData> responseModel = new ResponseModel<OkResponseTestData>(responseObjects); | ||
response.ShouldSerializeAndDeserialize(responseModel); | ||
} | ||
|
||
[Fact] | ||
public void StatusCodeResponse_Ctor1() | ||
{ | ||
OkResponseTestData responseObject = new OkResponseTestData { strval1 = "valueOfName" }; | ||
StatusCodeResponse response = new StatusCodeResponse(statusCode_OK, responseObject); | ||
|
||
response.ShouldValidatetCommons(statusCode_OK); | ||
response.Model.Errors.ShouldBeNull(); | ||
response.Model.GetType().ShouldBeEquivalentTo(typeof(ResponseModel<object>)); | ||
|
||
ResponseModel<OkResponseTestData> responseModel = new ResponseModel<OkResponseTestData>(responseObject); | ||
response.ShouldSerializeAndDeserialize(responseModel); | ||
} | ||
|
||
[Fact] | ||
public void StatusCodeResponse_Ctor2() | ||
{ | ||
IEnumerable<OkResponseTestData> responseObjects = new List<OkResponseTestData> { new OkResponseTestData() { strval1 = "valueOfName1", intval1 = 1 }, new OkResponseTestData { strval1 = "valueOfName2", intval1 = 2 } }; | ||
StatusCodeResponse response = new StatusCodeResponse(statusCode_OK, responseObjects); | ||
|
||
response.ShouldValidatetCommons(statusCode_OK); | ||
response.Model.Errors.ShouldBeNull(); | ||
response.Model.GetType().ShouldBeEquivalentTo(typeof(ResponseModel<object>)); | ||
|
||
ResponseModel<OkResponseTestData> responseModel = new ResponseModel<OkResponseTestData>(responseObjects); | ||
response.ShouldSerializeAndDeserialize(responseModel); | ||
} | ||
} | ||
|
||
internal class OkResponseTestData | ||
{ | ||
public int intval1 { get; set; } | ||
public string strval1 { get; set; } | ||
} |
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.