|
5 | 5 | using NUnit.Framework;
|
6 | 6 | using ksqlDB.RestApi.Client.Infrastructure.Extensions;
|
7 | 7 | using ksqlDB.RestApi.Client.KSql.RestApi;
|
| 8 | +using ksqlDB.RestApi.Client.KSql.RestApi.Parameters; |
8 | 9 |
|
9 | 10 | namespace ksqlDb.RestApi.Client.Tests.Infrastructure.Extensions
|
10 | 11 | {
|
11 | 12 | public class ServiceCollectionExtensionsTests
|
12 | 13 | {
|
13 |
| - private readonly IServiceCollection serviceCollection = new ServiceCollection(); |
| 14 | + private IServiceCollection serviceCollection; |
| 15 | + |
| 16 | + [SetUp] |
| 17 | + public void Setup() |
| 18 | + { |
| 19 | + serviceCollection = new ServiceCollection(); |
| 20 | + } |
14 | 21 |
|
15 | 22 | [Test]
|
16 | 23 | public void RegisterKSqlDbContextDependencies()
|
@@ -43,15 +50,59 @@ public void RegisterKSqlDbContextDependencies()
|
43 | 50 | public void ConfigureHttpClients()
|
44 | 51 | {
|
45 | 52 | //Arrange
|
| 53 | + var contextOptions = new KSqlDBContextOptions(Helpers.TestParameters.KsqlDbUrl); |
46 | 54 |
|
47 | 55 | //Act
|
48 |
| - serviceCollection.ConfigureHttpClients(new KSqlDBContextOptions(Helpers.TestParameters.KsqlDbUrl)); |
| 56 | + serviceCollection.ConfigureHttpClients(contextOptions); |
49 | 57 |
|
50 | 58 | var serviceProvider = serviceCollection.BuildServiceProvider();
|
51 |
| - var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>(); |
| 59 | + var httpClientFactory = serviceProvider.GetRequiredService<ksqlDB.RestApi.Client.KSql.RestApi.Http.IHttpClientFactory>(); |
52 | 60 |
|
53 | 61 | //Assert
|
54 | 62 | httpClientFactory.Should().NotBeNull();
|
| 63 | + |
| 64 | + var httpClient = httpClientFactory.CreateClient(); |
| 65 | + httpClient.BaseAddress.Should().Be(Helpers.TestParameters.KsqlDbUrl); |
| 66 | + } |
| 67 | + |
| 68 | + [Test] |
| 69 | + public void RegisterEndpointDependencies() |
| 70 | + { |
| 71 | + //Arrange |
| 72 | + var contextOptions = new KSqlDBContextOptions(Helpers.TestParameters.KsqlDbUrl); |
| 73 | + |
| 74 | + //Act |
| 75 | + serviceCollection.RegisterEndpointDependencies(contextOptions); |
| 76 | + |
| 77 | + var serviceProvider = serviceCollection.BuildServiceProvider(); |
| 78 | + var dbParameters = serviceProvider.GetRequiredService<IKSqlDbParameters>(); |
| 79 | + var pullQueryParameters = serviceProvider.GetRequiredService<IPullQueryParameters>(); |
| 80 | + |
| 81 | + //Assert |
| 82 | + dbParameters.Should().NotBeNull(); |
| 83 | + pullQueryParameters.Should().NotBeNull(); |
| 84 | + } |
| 85 | + |
| 86 | + [Test] |
| 87 | + public void ApplyTo() |
| 88 | + { |
| 89 | + //Arrange |
| 90 | + var sc = new ServiceCollection(); |
| 91 | + var restApiClientOptions = new KSqlDBRestApiClientOptions |
| 92 | + { |
| 93 | + ShouldPluralizeFromItemName = false, |
| 94 | + }; |
| 95 | + sc.AddSingleton(restApiClientOptions); |
| 96 | + |
| 97 | + //Act |
| 98 | + sc.ApplyTo(serviceCollection); |
| 99 | + |
| 100 | + var serviceProvider = serviceCollection.BuildServiceProvider(); |
| 101 | + var receivedRestApiClientOptions = serviceProvider.GetRequiredService<KSqlDBRestApiClientOptions>(); |
| 102 | + |
| 103 | + //Assert |
| 104 | + receivedRestApiClientOptions.Should().NotBeNull(); |
| 105 | + receivedRestApiClientOptions.ShouldPluralizeFromItemName.Should().BeFalse(); |
55 | 106 | }
|
56 | 107 | }
|
57 | 108 | }
|
0 commit comments