-
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.
Rejigged tests and added tests for create teams
- Loading branch information
Showing
7 changed files
with
228 additions
and
3 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
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
84 changes: 84 additions & 0 deletions
84
tests/PinguApps.Appwrite.Client.Tests/Clients/Teams/TeamsClientTests.ListTeams.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,84 @@ | ||
using System.Net; | ||
using PinguApps.Appwrite.Client.Clients; | ||
using PinguApps.Appwrite.Shared.Requests.Teams; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Client.Tests.Clients.Teams; | ||
public partial class TeamsClientTests | ||
{ | ||
[Fact] | ||
public async Task ListTeams_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new ListTeamsRequest(); | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams") | ||
.ExpectedHeaders(true) | ||
.Respond(TestConstants.AppJson, TestConstants.TeamsListResponse); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeams(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task ListTeams_ShouldReturnError_WhenSessionIsNull() | ||
{ | ||
// Arrange | ||
var request = new ListTeamsRequest(); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeams(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal(ISessionAware.SessionExceptionMessage, result.Result.AsT2.Message); | ||
} | ||
|
||
[Fact] | ||
public async Task ListTeams_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new ListTeamsRequest(); | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams") | ||
.ExpectedHeaders(true) | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeams(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task ListTeams_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new ListTeamsRequest(); | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams") | ||
.ExpectedHeaders(true) | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeams(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/PinguApps.Appwrite.Client.Tests/Clients/Teams/TeamsClientTests.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,38 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using PinguApps.Appwrite.Shared.Converters; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using Refit; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Client.Tests.Clients.Teams; | ||
public partial class TeamsClientTests | ||
{ | ||
private readonly MockHttpMessageHandler _mockHttp; | ||
private readonly IAppwriteClient _appwriteClient; | ||
private readonly JsonSerializerOptions _jsonSerializerOptions; | ||
|
||
public TeamsClientTests() | ||
{ | ||
_mockHttp = new MockHttpMessageHandler(); | ||
var services = new ServiceCollection(); | ||
|
||
services.AddAppwriteClientForServer(TestConstants.ProjectId, TestConstants.Endpoint, new RefitSettings | ||
{ | ||
HttpMessageHandlerFactory = () => _mockHttp | ||
}); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
_appwriteClient = serviceProvider.GetRequiredService<IAppwriteClient>(); | ||
|
||
_jsonSerializerOptions = new JsonSerializerOptions | ||
{ | ||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase | ||
}; | ||
|
||
_jsonSerializerOptions.Converters.Add(new IgnoreSdkExcludedPropertiesConverterFactory()); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
tests/PinguApps.Appwrite.Server.Tests/Clients/Teams/TeamsClientTests.ListTeams.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,62 @@ | ||
using System.Net; | ||
using PinguApps.Appwrite.Shared.Requests.Teams; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Server.Tests.Clients.Teams; | ||
public partial class TeamsClientTests | ||
{ | ||
[Fact] | ||
public async Task ListTeams_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new ListTeamsRequest(); | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams") | ||
.ExpectedHeaders() | ||
.Respond(TestConstants.AppJson, TestConstants.TeamsListResponse); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeams(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task ListTeams_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new ListTeamsRequest(); | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams") | ||
.ExpectedHeaders() | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeams(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task ListTeams_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new ListTeamsRequest(); | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams") | ||
.ExpectedHeaders() | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeams(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/PinguApps.Appwrite.Server.Tests/Clients/Teams/TeamsClientTests.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,39 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using PinguApps.Appwrite.Server.Clients; | ||
using PinguApps.Appwrite.Shared.Converters; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using Refit; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Server.Tests.Clients.Teams; | ||
public partial class TeamsClientTests | ||
{ | ||
private readonly MockHttpMessageHandler _mockHttp; | ||
private readonly IAppwriteClient _appwriteClient; | ||
private readonly JsonSerializerOptions _jsonSerializerOptions; | ||
|
||
public TeamsClientTests() | ||
{ | ||
_mockHttp = new MockHttpMessageHandler(); | ||
var services = new ServiceCollection(); | ||
|
||
services.AddAppwriteServer(TestConstants.ProjectId, TestConstants.ApiKey, TestConstants.Endpoint, new RefitSettings | ||
{ | ||
HttpMessageHandlerFactory = () => _mockHttp | ||
}); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
_appwriteClient = serviceProvider.GetRequiredService<IAppwriteClient>(); | ||
|
||
_jsonSerializerOptions = new JsonSerializerOptions | ||
{ | ||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase | ||
}; | ||
|
||
_jsonSerializerOptions.Converters.Add(new IgnoreSdkExcludedPropertiesConverterFactory()); | ||
} | ||
} |