コード例 #1
0
            public async Task RandomHostPortBindings()
            {
                // Given
                var testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                            .WithImage("nginx")
                                            .WithPortBinding(80, true);

                // When
                // Then
                await using (IDockerContainer testcontainer = testcontainersBuilder.Build())
                {
                    await testcontainer.StartAsync();

                    Assert.NotEqual(0, testcontainer.GetMappedPublicPort(80));
                }
            }
            public async Task QueryContainerInformationOfNotCreatedContainer()
            {
                // Given
                var testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                            .WithImage("nginx");

                // When
                // Then
                await using (IDockerContainer testcontainer = testcontainersBuilder.Build())
                {
                    Assert.Throws <InvalidOperationException>(() => testcontainer.Name);
                    Assert.Throws <InvalidOperationException>(() => testcontainer.IpAddress);
                    Assert.Throws <InvalidOperationException>(() => testcontainer.MacAddress);
                    Assert.Throws <InvalidOperationException>(() => testcontainer.GetMappedPublicPort(0));
                    await Assert.ThrowsAsync <InvalidOperationException>(() => testcontainer.StopAsync());
                }
            }