|
| 1 | +using FluentAssertions; |
| 2 | +using ksqlDb.RestApi.Client.FluentAPI.Builders; |
| 3 | +using ksqlDB.RestApi.Client.KSql.Query.Context; |
| 4 | +using Microsoft.Extensions.DependencyInjection; |
| 5 | +using NUnit.Framework; |
| 6 | +using ksqlDB.RestApi.Client.Infrastructure.Extensions; |
| 7 | +using ksqlDB.RestApi.Client.KSql.RestApi; |
| 8 | + |
| 9 | +namespace ksqlDb.RestApi.Client.Tests.Infrastructure.Extensions |
| 10 | +{ |
| 11 | + public class ServiceCollectionExtensionsTests |
| 12 | + { |
| 13 | + private readonly IServiceCollection serviceCollection = new ServiceCollection(); |
| 14 | + |
| 15 | + [Test] |
| 16 | + public void RegisterKSqlDbContextDependencies() |
| 17 | + { |
| 18 | + //Arrange |
| 19 | + var modelBuilder = new ModelBuilder(); |
| 20 | + serviceCollection.AddSingleton<IMetadataProvider>(modelBuilder); |
| 21 | + |
| 22 | + var restApiClientOptions = new KSqlDBRestApiClientOptions |
| 23 | + { |
| 24 | + ShouldPluralizeFromItemName = false, |
| 25 | + }; |
| 26 | + serviceCollection.AddSingleton(restApiClientOptions); |
| 27 | + |
| 28 | + //Act |
| 29 | + serviceCollection.RegisterKSqlDbContextDependencies(new KSqlDBContextOptions(Helpers.TestParameters.KsqlDbUrl)); |
| 30 | + |
| 31 | + var serviceProvider = serviceCollection.BuildServiceProvider(); |
| 32 | + var metadataProvider = serviceProvider.GetRequiredService<IMetadataProvider>(); |
| 33 | + var clientOptions = serviceProvider.GetRequiredService<KSqlDBRestApiClientOptions>(); |
| 34 | + var rRestApiClient = serviceProvider.GetRequiredService<IKSqlDbRestApiClient>(); |
| 35 | + |
| 36 | + //Assert |
| 37 | + metadataProvider.Should().BeSameAs(modelBuilder); |
| 38 | + restApiClientOptions.Should().BeSameAs(clientOptions); |
| 39 | + rRestApiClient.Should().NotBeNull(); |
| 40 | + } |
| 41 | + |
| 42 | + [Test] |
| 43 | + public void ConfigureHttpClients() |
| 44 | + { |
| 45 | + //Arrange |
| 46 | + |
| 47 | + //Act |
| 48 | + serviceCollection.ConfigureHttpClients(new KSqlDBContextOptions(Helpers.TestParameters.KsqlDbUrl)); |
| 49 | + |
| 50 | + var serviceProvider = serviceCollection.BuildServiceProvider(); |
| 51 | + var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>(); |
| 52 | + |
| 53 | + //Assert |
| 54 | + httpClientFactory.Should().NotBeNull(); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments