-
Notifications
You must be signed in to change notification settings - Fork 2
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 #48 from PinguApps/35-feat-add-additional-tests-to…
…-cover-shared-lib-and-increase-code-coverage Added fuller test coverage
- Loading branch information
Showing
36 changed files
with
1,094 additions
and
187 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
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 |
---|---|---|
|
@@ -398,3 +398,4 @@ FodyWeavers.xsd | |
*.sln.iml | ||
|
||
**/*appsettings*.json | ||
**/coverage-report/** |
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,22 @@ | ||
<Project> | ||
<Target Name="AddInternalsVisibleTo" BeforeTargets="BeforeCompile"> | ||
<!-- Add default suffix if there is no InternalsVisibleTo or InternalsVisibleToSuffix defined --> | ||
<ItemGroup Condition="@(InternalsVisibleToSuffix->Count()) == 0 AND @(InternalsVisibleTo->Count()) == 0"> | ||
<InternalsVisibleToSuffix Include=".Tests" /> | ||
</ItemGroup> | ||
|
||
<!-- Handle InternalsVisibleTo --> | ||
<ItemGroup Condition="'@(InternalsVisibleTo->Count())' > 0"> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo"> | ||
<_Parameter1>%(InternalsVisibleTo.Identity)</_Parameter1> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
|
||
<!-- Handle InternalsVisibleToSuffix --> | ||
<ItemGroup Condition="@(InternalsVisibleToSuffix->Count()) > 0"> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo"> | ||
<_Parameter1>$(AssemblyName)%(InternalsVisibleToSuffix.Identity)</_Parameter1> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
</Target> | ||
</Project> |
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,9 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PinguApps.Appwrite.Shared.Responses; | ||
public record HashOptions( | ||
[property: JsonPropertyName("type")] string Type, | ||
[property: JsonPropertyName("memoryCost")] long MemoryCost, | ||
[property: JsonPropertyName("timeCost")] int TimeCost, | ||
[property: JsonPropertyName("threads")] int Threads | ||
); |
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 was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create.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,80 @@ | ||
using System.Net; | ||
using PinguApps.Appwrite.Shared.Requests; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Client.Tests.Clients.Account; | ||
public partial class AccountClientTests | ||
{ | ||
[Fact] | ||
public async Task Create_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new CreateAccountRequest() | ||
{ | ||
Email = "[email protected]", | ||
Password = "password", | ||
Name = "name" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{Constants.Endpoint}/account") | ||
.ExpectedHeaders() | ||
.WithJsonContent(request) | ||
.Respond(Constants.AppJson, Constants.UserResponse); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.Create(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task Create_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new CreateAccountRequest() | ||
{ | ||
Email = "[email protected]", | ||
Password = "password", | ||
Name = "name" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{Constants.Endpoint}/account") | ||
.ExpectedHeaders() | ||
.WithJsonContent(request) | ||
.Respond(HttpStatusCode.BadRequest, Constants.AppJson, Constants.AppwriteError); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.Create(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task Create_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new CreateAccountRequest() | ||
{ | ||
Email = "[email protected]", | ||
Password = "password", | ||
Name = "name" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{Constants.Endpoint}/account") | ||
.ExpectedHeaders() | ||
.WithJsonContent(request) | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.Create(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Get.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,61 @@ | ||
using System.Net; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Client.Tests.Clients.Account; | ||
public partial class AccountClientTests | ||
{ | ||
[Fact] | ||
public async Task Get_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
_mockHttp.Expect(HttpMethod.Get, $"{Constants.Endpoint}/account") | ||
.ExpectedHeaders(true) | ||
.Respond(Constants.AppJson, Constants.UserResponse); | ||
|
||
_appwriteClient.SetSession(Constants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.Get(); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
_mockHttp.Expect(HttpMethod.Get, $"{Constants.Endpoint}/account") | ||
.ExpectedHeaders(true) | ||
.Respond(HttpStatusCode.BadRequest, Constants.AppJson, Constants.AppwriteError); | ||
|
||
_appwriteClient.SetSession(Constants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.Get(); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
_mockHttp.Expect(HttpMethod.Get, $"{Constants.Endpoint}/account") | ||
.ExpectedHeaders(true) | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
_appwriteClient.SetSession(Constants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.Get(); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
Oops, something went wrong.