Skip to content

Commit

Permalink
Create ServiceCollectionExtensionsTests.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
pingu2k4 committed Jul 7, 2024
1 parent 554ffd7 commit ae40c19
Showing 1 changed file with 63 additions and 0 deletions.
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);
}
}

0 comments on commit ae40c19

Please sign in to comment.