Skip to content

Commit

Permalink
Fixed tests, as we were failing many
Browse files Browse the repository at this point in the history
  • Loading branch information
pingu2k4 committed Jul 15, 2024
1 parent 2f14b2c commit ee8d714
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
7 changes: 5 additions & 2 deletions src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ public static IServiceCollection AddAppwriteClientForServer(this IServiceCollect
services.AddRefitClient<IAccountApi>(refitSettings)
.ConfigureHttpClient(x => x.BaseAddress = new Uri(endpoint))
.AddHttpMessageHandler<HeaderHandler>()
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
.ConfigurePrimaryHttpMessageHandler((handler, sp) =>
{
UseCookies = false
if (handler is HttpClientHandler clientHandler)
{
clientHandler.UseCookies = false;
}
});

services.AddSingleton<IAccountClient, AccountClient>();
Expand Down
4 changes: 2 additions & 2 deletions src/PinguApps.Appwrite.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddAppwriteClient(builder.Configuration.GetValue<string>("ProjectId")!);
//builder.Services.AddAppwriteClientForServer(builder.Configuration.GetValue<string>("ProjectId")!);
//builder.Services.AddAppwriteClient(builder.Configuration.GetValue<string>("ProjectId")!);
builder.Services.AddAppwriteClientForServer(builder.Configuration.GetValue<string>("ProjectId")!);
builder.Services.AddAppwriteServer(builder.Configuration.GetValue<string>("ProjectId")!, builder.Configuration.GetValue<string>("ApiKey")!);
builder.Services.AddSingleton<App>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,26 @@ public void AddAppwriteClient_RegistersExpectedServices()
// Assert
var provider = services.BuildServiceProvider();

// Assert HeaderHandler is registered
var headerHandler = provider.GetService<HeaderHandler>();
Assert.NotNull(headerHandler);

// Assert IAccountApi is registered and configured
var clientCookieSessionHandler = provider.GetService<ClientCookieSessionHandler>();
Assert.NotNull(clientCookieSessionHandler);

var accountApi = provider.GetService<IAccountApi>();
Assert.NotNull(accountApi);

// Assert services are registered
Assert.NotNull(provider.GetService<IAccountClient>());
Assert.NotNull(provider.GetService<IAppwriteClient>());

var lazyClient = provider.GetService<Lazy<IAppwriteClient>>();
Assert.NotNull(lazyClient);
var client = lazyClient.Value;
Assert.NotNull(client);
}

[Fact]
public void AddAppwriteClientForServer_RegistersExpectedServicesWithTransientLifetime()
public void AddAppwriteClientForServer_RegistersExpectedServices()
{
// Arrange
var services = new ServiceCollection();
Expand All @@ -43,21 +48,16 @@ public void AddAppwriteClientForServer_RegistersExpectedServicesWithTransientLif
// Assert
var provider = services.BuildServiceProvider();

// Assert HeaderHandler is registered
var headerHandler = provider.GetService<HeaderHandler>();
Assert.NotNull(headerHandler);

// Assert IAccountApi is registered and configured
var clientCookieSessionHandler = provider.GetService<ClientCookieSessionHandler>();
Assert.Null(clientCookieSessionHandler);

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);
Assert.NotNull(provider.GetService<IAccountClient>());
Assert.NotNull(provider.GetService<IAppwriteClient>());
}
}

0 comments on commit ee8d714

Please sign in to comment.