|
1 | 1 | namespace Testcontainers.Tests; |
2 | 2 |
|
3 | | -public sealed class ConnectionStringProviderTests : IAsyncLifetime |
| 3 | +public static class ConnectionStringProviderTests |
4 | 4 | { |
5 | 5 | private const string ExpectedConnectionString = "connection string"; |
6 | 6 |
|
7 | | - private readonly ConnectionStringProvider _connectionStringProvider = new ConnectionStringProvider(); |
| 7 | + public sealed class Configured : IAsyncLifetime |
| 8 | + { |
| 9 | + private readonly ConnectionStringProvider _connectionStringProvider = new ConnectionStringProvider(); |
| 10 | + |
| 11 | + private readonly IContainer _container; |
8 | 12 |
|
9 | | - private readonly IContainer _container; |
| 13 | + public Configured() |
| 14 | + { |
| 15 | + _container = new ContainerBuilder() |
| 16 | + .WithImage(CommonImages.Alpine) |
| 17 | + .WithCommand(CommonCommands.SleepInfinity) |
| 18 | + .WithConnectionStringProvider(_connectionStringProvider) |
| 19 | + .Build(); |
| 20 | + } |
| 21 | + |
| 22 | + public async ValueTask InitializeAsync() |
| 23 | + { |
| 24 | + await _container.StartAsync() |
| 25 | + .ConfigureAwait(false); |
| 26 | + } |
| 27 | + |
| 28 | + public async ValueTask DisposeAsync() |
| 29 | + { |
| 30 | + await _container.DisposeAsync() |
| 31 | + .ConfigureAwait(false); |
| 32 | + } |
| 33 | + |
| 34 | + [Fact] |
| 35 | + public void GetConnectionStringReturnsExpectedValue() |
| 36 | + { |
| 37 | + Assert.True(_connectionStringProvider.IsConfigured, "Configure should have been called during container startup."); |
| 38 | + Assert.Equal(ExpectedConnectionString, _container.GetConnectionString()); |
| 39 | + Assert.Equal(ExpectedConnectionString, _container.GetConnectionString("name")); |
| 40 | + } |
| 41 | + } |
10 | 42 |
|
11 | | - public ConnectionStringProviderTests() |
| 43 | + public sealed class NotConfigured : IAsyncLifetime |
12 | 44 | { |
13 | | - _container = new ContainerBuilder() |
| 45 | + private readonly IContainer _container = new ContainerBuilder() |
14 | 46 | .WithImage(CommonImages.Alpine) |
15 | 47 | .WithCommand(CommonCommands.SleepInfinity) |
16 | | - .WithConnectionStringProvider(_connectionStringProvider) |
17 | 48 | .Build(); |
18 | | - } |
19 | 49 |
|
20 | | - public async ValueTask InitializeAsync() |
21 | | - { |
22 | | - await _container.StartAsync() |
23 | | - .ConfigureAwait(false); |
24 | | - } |
| 50 | + public async ValueTask InitializeAsync() |
| 51 | + { |
| 52 | + await _container.StartAsync() |
| 53 | + .ConfigureAwait(false); |
| 54 | + } |
25 | 55 |
|
26 | | - public async ValueTask DisposeAsync() |
27 | | - { |
28 | | - await _container.DisposeAsync() |
29 | | - .ConfigureAwait(false); |
30 | | - } |
| 56 | + public async ValueTask DisposeAsync() |
| 57 | + { |
| 58 | + await _container.DisposeAsync() |
| 59 | + .ConfigureAwait(false); |
| 60 | + } |
31 | 61 |
|
32 | | - [Fact] |
33 | | - public void GetConnectionStringReturnsExpectedValue() |
34 | | - { |
35 | | - Assert.True(_connectionStringProvider.IsConfigured, "Configure should have been called during container startup."); |
36 | | - Assert.Equal(ExpectedConnectionString, _container.GetConnectionString()); |
37 | | - Assert.Equal(ExpectedConnectionString, _container.GetConnectionString("name")); |
| 62 | + [Fact] |
| 63 | + public void GetConnectionStringThrowsException() |
| 64 | + { |
| 65 | + Assert.Throws<ConnectionStringProviderNotConfiguredException>(() => _container.GetConnectionString()); |
| 66 | + Assert.Throws<ConnectionStringProviderNotConfiguredException>(() => _container.GetConnectionString("name")); |
| 67 | + } |
38 | 68 | } |
39 | 69 |
|
40 | 70 | private sealed class ConnectionStringProvider : IConnectionStringProvider<IContainer, IContainerConfiguration> |
|
0 commit comments