-
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.
Create ServiceCollectionExtensionsTests.cs
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
tests/PinguApps.Appwrite.Client.Tests/ServiceCollectionExtensionsTests.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,63 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using PinguApps.Appwrite.Client.Handlers; | ||
using PinguApps.Appwrite.Client.Internals; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
|
||
namespace PinguApps.Appwrite.Client.Tests; | ||
public class ServiceCollectionExtensionsTests | ||
{ | ||
[Fact] | ||
public void AddAppwriteClient_RegistersExpectedServices() | ||
{ | ||
// Arrange | ||
var services = new ServiceCollection(); | ||
|
||
// Act | ||
services.AddAppwriteClient(Constants.ProjectId, Constants.Endpoint); | ||
|
||
// Assert | ||
var provider = services.BuildServiceProvider(); | ||
|
||
// Assert HeaderHandler is registered | ||
var headerHandler = provider.GetService<HeaderHandler>(); | ||
Assert.NotNull(headerHandler); | ||
|
||
// Assert IAccountApi is registered and configured | ||
var accountApi = provider.GetService<IAccountApi>(); | ||
Assert.NotNull(accountApi); | ||
|
||
// Assert services are registered | ||
Assert.NotNull(provider.GetService<IAccountClient>()); | ||
Assert.NotNull(provider.GetService<IAppwriteClient>()); | ||
} | ||
|
||
[Fact] | ||
public void AddAppwriteClientForServer_RegistersExpectedServicesWithTransientLifetime() | ||
{ | ||
// Arrange | ||
var services = new ServiceCollection(); | ||
|
||
// Act | ||
services.AddAppwriteClientForServer(Constants.ProjectId, Constants.Endpoint); | ||
|
||
// Assert | ||
var provider = services.BuildServiceProvider(); | ||
|
||
// Assert HeaderHandler is registered | ||
var headerHandler = provider.GetService<HeaderHandler>(); | ||
Assert.NotNull(headerHandler); | ||
|
||
// Assert IAccountApi is registered and configured | ||
var accountApi = provider.GetService<IAccountApi>(); | ||
Assert.NotNull(accountApi); | ||
|
||
// Assert services are registered with Transient lifetime | ||
var accountClientServiceDescriptor = services.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(IAccountClient)); | ||
Assert.NotNull(accountClientServiceDescriptor); | ||
Assert.Equal(ServiceLifetime.Transient, accountClientServiceDescriptor.Lifetime); | ||
|
||
var appwriteClientServiceDescriptor = services.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(IAppwriteClient)); | ||
Assert.NotNull(appwriteClientServiceDescriptor); | ||
Assert.Equal(ServiceLifetime.Transient, appwriteClientServiceDescriptor.Lifetime); | ||
} | ||
} |