-
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.
Added tests for client Create Account
- Loading branch information
Showing
1 changed file
with
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System.Net; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using PinguApps.Appwrite.Shared.Requests; | ||
using PinguApps.Appwrite.Tests.Shared; | ||
using Refit; | ||
using RichardSzalay.MockHttp; | ||
|
@@ -59,6 +60,53 @@ public async Task Get_ShouldHandleException_WhenApiCallFails() | |
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[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); | ||
} | ||
} | ||
|
||
public static class AccountTestsExtensions | ||
|