diff --git a/tests/PinguApps.Appwrite.Client.Tests/ServiceCollectionExtensionsTests.cs b/tests/PinguApps.Appwrite.Client.Tests/ServiceCollectionExtensionsTests.cs new file mode 100644 index 00000000..1f93b2cb --- /dev/null +++ b/tests/PinguApps.Appwrite.Client.Tests/ServiceCollectionExtensionsTests.cs @@ -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(); + Assert.NotNull(headerHandler); + + // Assert IAccountApi is registered and configured + var accountApi = provider.GetService(); + Assert.NotNull(accountApi); + + // Assert services are registered + Assert.NotNull(provider.GetService()); + Assert.NotNull(provider.GetService()); + } + + [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(); + Assert.NotNull(headerHandler); + + // Assert IAccountApi is registered and configured + var accountApi = provider.GetService(); + 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); + } +}