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

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

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

                // When
                // Then
                await using (ITestcontainersContainer 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());
                }
            }