public async Task TwoContainersWithSimilarNames_ShouldStartCorrectly()
        {
            // Arrange
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env-similar-names")
#if DEBUG
                              .AddMongoContainer("my-mongo-2", reuseContainer: true)
                              .AddMongoContainer("my-mongo", tag: "4.0", reuseContainer: true)
#else
                              .AddMongoContainer("my-mongo-2")
                              .AddMongoContainer("my-mongo", tag: "4.0")
#endif
                              .Build();

            // Act
            await environment.Up();

            // Assert
            var mongo  = environment.GetContainer <MongoContainer>("my-mongo");
            var mongo2 = environment.GetContainer <MongoContainer>("my-mongo-2");

            PrintMongoVersion(mongo);
            PrintMongoVersion(mongo2);

            await DisposeEnvironment(environment);
        }
        public async Task AddElasticSearchContainer_WhenContainerIsUp_ShouldPrintElasticSearchVersion()
        {
            // Arrange
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
#if DEBUG
                              .AddElasticsearchContainer("my-elastic", ports: new Dictionary <ushort, ushort> {
                [9200] = 9200
            }, reuseContainer: true)
#else
                              .AddElasticsearchContainer("my-elastic")
#endif
                              .Build();

            // Act
            await environment.Up();

            // Assert
            var elastic = environment.GetContainer <ElasticsearchContainer>("my-elastic");

            await PrintElasticsearchVersion(elastic);

            await DisposeEnvironment(environment);
        }
        public async Task AddMsSqlContainer_WhenContainerIsUp_ShouldPrintMsSqlVersion()
        {
            // Arrange
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
#if DEBUG
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0", environmentVariables: new Dictionary <string, string> {
                ["MSSQL_COLLATION"] = "SQL_Latin1_General_CP1_CS_AS"
            }, reuseContainer: true)
#else
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0")
#endif
                              .Build();

            // Act
            await environment.Up();

            // Assert
            var mssql = environment.GetContainer <MssqlContainer>("my-mssql");

            await PrintMssqlVersion(mssql);

            await DisposeEnvironment(environment);
        }
        public async Task AddMongoSingleReplicaSetContainer_WhenContainerIsUp_ShouldPrintMongoReplicaSetConfiguration()
        {
            // Arrange
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
                              .WithLogger(_logger)

                              // 27017 port is busy in AppVeyor
#if DEBUG
                              .AddMongoSingleReplicaSetContainer("my-mongo-replicaSet", reuseContainer: true, port: 37017)
#else
                              .AddMongoSingleReplicaSetContainer("my-mongo-replicaSet", port: 37017)
#endif
                              .Build();

            // Act
            await environment.Up();

            // Assert
            var mongo = environment.GetContainer <MongoSingleReplicaSetContainer>("my-mongo-replicaSet");

            await PrintMongoReplicaSetConfiguration(mongo);

            await DisposeEnvironment(environment);
        }
Example #5
0
        public async Task CreateDockerEnvironment()
        {
            // Create the environment using builder pattern
            var environment = new DockerEnvironmentBuilder()
                              .AddContainer("my-nginx", "nginx")
                              .AddElasticsearchContainer("my-elastic")
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0")
                              .Build();

            // Up it.
            await environment.Up();

            // Play with containers.
            var mssql = environment.GetContainer <MssqlContainer>("my-mssql");

            await PrintMssqlVersion(mssql);

            var elastic = environment.GetContainer <ElasticsearchContainer>("my-elastic");

            await PrintElasticsearchVersion(elastic);

            // Down it.
            await environment.Down();

            // Dispose (remove).
            environment.Dispose();
        }
Example #6
0
        public static async Task Main(string[] args)
        {
            await using var dockerEnvironment = new DockerEnvironmentBuilder()
                                                .AddMongoContainer("mongo")
                                                .Build();

            await dockerEnvironment.Up();

            var mongoContainer = dockerEnvironment.GetContainer <MongoContainer>("mongo");

            var host = CreateHostBuilder(args, mongoContainer.GetConnectionString()).Build();

            await InitializeDatabaseWithData(host);

            await host.RunAsync();

            await dockerEnvironment.Down();
        }
Example #7
0
        static async Task Execute()
        {
            using (var environment = new DockerEnvironmentBuilder()
                                     .AddContainer(
                       "postgres",
                       "postgres", "10.7",
                       environmentVariables: new Dictionary <string, string>
            {
                { "POSTGRES_USER", "otdev" },
                { "POSTGRES_PASSWORD", "letmein" },
                { "POSTGRES_DB", "offersdb" }
            })
                                     .Build())
            {
                await environment.Up();

                var container = environment.GetContainer("postgres");

                Console.WriteLine("Container Info");
                Console.WriteLine(JsonConvert.SerializeObject(container, Formatting.Indented));
                var connectionString = $"Database=offersdb; User Id=otdev; Password=letmein;Server=localhost; Port={container.Ports.First().Value};";
                Console.WriteLine(connectionString);

                using (var conn = new NpgsqlConnection(connectionString))
                {
                    conn.Execute("CREATE TABLE Data ( id integer primary key, name text );");
                    conn.Open();
                    using (var trx = conn.BeginTransaction())
                    {
                        conn.Execute("CREATE INDEX CONCURRENTLY ix_name ON Data (name)");
                    }
                    conn.Execute("INSERT INTO Data (id, name) VALUES (1, 'Test')");
                    var data = conn.Query <TestData>("select * from Test");
                    foreach (var item in data)
                    {
                        Console.WriteLine(JsonConvert.SerializeObject(item, Formatting.Indented));
                    }
                }

                await environment.Down();
            }
        }
Example #8
0
        public async Task Test1()
        {
            // Arrange database and selenuim containers
            var infrastructure = new DockerEnvironmentBuilder()
                                 .SetName("env")
                                 .AddMssqlContainer("mssql", "saPassword123")
                                 .AddContainer("webdriver", "selenium/standalone-chrome", "3.141.59-antimony")
                                 .Build();

            await infrastructure.Up();

            // Arrange container with the app inside
            var app = new DockerEnvironmentBuilder()
                      .SetName("app")
                      .AddContainer("app", "dockertestui", "latest", new Dictionary <string, string>
            {
                ["ConnectionStrings__SampleDB"] = GetConnectionString(infrastructure)
            }, containerWaiter: new FuncContainerWaiter(CheckAppReadiness))
                      .Build();

            await app.Up();

            // Connect to remote Chrome driver
            using (var driver = new RemoteWebDriver(
                       new Uri(GetChromeDriverUrl(infrastructure)),
                       new ChromeOptions {
            }))
            {
                // Go to home page and get all <tr> elements to count
                driver.Navigate().GoToUrl(GetAppUrl(app));
                var trs = driver.FindElementByTagName("tbody").FindElements(By.TagName("tr"));

                // Assert
                Assert.Equal(15, trs.Count);
            }

            // Cleanup
            app.Dispose();
            infrastructure.Dispose();
        }
Example #9
0
        public async Task AddKafkaContainer_WhenContainerIsUp_ShouldPrintKafkaVersion()
        {
            // Arrange
            var environment = new DockerEnvironmentBuilder()
                              .SetName("test-env")
#if DEBUG
                              .AddKafkaContainer("my-kafka", reuseContainer: true)
#else
                              .AddKafkaContainer("my-kafka")
#endif
                              .Build();

            // Act
            await environment.Up();

            // Assert
            var kafka = environment.GetContainer <KafkaContainer>("my-kafka");

            PrintKafkaVersion(kafka);

            await DisposeEnvironment(environment);
        }
Example #10
0
        public async Task CreateDockerEnvironment()
        {
            // Create the environment using builder pattern
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
                              .AddContainer("my-nginx", "nginx")
#if DEBUG
                              .AddElasticsearchContainer("my-elastic", reuseContainer: true)
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0", environmentVariables: new Dictionary <string, string> {
                ["MSSQL_COLLATION"] = "SQL_Latin1_General_CP1_CS_AS"
            }, reuseContainer: true)
#else
                              .AddElasticsearchContainer("my-elastic")
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0")
#endif
                              .Build();

            // Up it.
            await environment.Up();

            // Play with containers.
            var mssql = environment.GetContainer <MssqlContainer>("my-mssql");

            await PrintMssqlVersion(mssql);

            var elastic = environment.GetContainer <ElasticsearchContainer>("my-elastic");

            await PrintElasticsearchVersion(elastic);

#if !DEBUG
            // Down it.
            await environment.Down();

            // Dispose (remove).
            environment.Dispose();
#endif
        }
        public async Task AddFtpContainer_WhenContainerIsUp_ShouldPrintFtpServerType()
        {
            // Arrange
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
#if DEBUG
                              .AddFtpContainer(
                "my-ftp",
                "superuser",
                "test",
                ports: Enumerable.Range(30000, 10).ToDictionary(p => (ushort)p, p => (ushort)p).MergeDictionaries(new Dictionary <ushort, ushort> {
                [21] = 21
            }),
                reuseContainer: true)
#else
                              .AddFtpContainer(
                "my-ftp",
                "superuser",
                "test",
                ports: Enumerable.Range(30000, 10)
                .ToDictionary(p => (ushort)p, p => (ushort)p).MergeDictionaries(new Dictionary <ushort, ushort>
            {
                [21] = 21
            }))
#endif
                              .Build();

            // Act
            await environment.Up();

            // Assert
            var ftp = environment.GetContainer <FtpContainer>("my-ftp");

            await PrintFtpServerType(ftp);

            await DisposeEnvironment(environment);
        }
        public async Task AddMariaDbContainer_WhenContainerIsUp_ShouldPrintMariaDbVersion()
        {
            // Arrange
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
#if DEBUG
                              .AddMariaDBContainer("my-maria", "my-secret-pw", reuseContainer: true)
#else
                              .AddMariaDBContainer("my-maria", "my-secret-pw")
#endif
                              .Build();

            // Act
            await environment.Up();

            // Assert
            var maria = environment.GetContainer <MariaDBContainer>("my-maria");

            await PrintMariaDBVersion(maria);

            await DisposeEnvironment(environment);
        }
        public async Task AddPostgresContainer_WhenContainerIsUp_ShouldPrintPostgresDbVersion()
        {
            // Arrange
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
#if DEBUG
                              .AddPostgresContainer("my-postgres", reuseContainer: true)
#else
                              .AddPostgresContainer("my-postgres")
#endif
                              .Build();

            // Act
            await environment.Up();

            // Assert
            var postgres = environment.GetContainer <PostgresContainer>("my-postgres");

            await PrintPostgresDbVersion(postgres);

            await DisposeEnvironment(environment);
        }
        public async Task AddFromDockerFileContainer_WhenContainerIsUp_ShouldPrintReturnedHtml()
        {
            // Arrange
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
#if DEBUG
                              .AddFromDockerfile("from-file", "Dockerfile", containerWaiter: new HttpContainerWaiter("/", httpPort: 8080), reuseContainer: true)
#else
                              .AddFromDockerfile("from-file", "Dockerfile", containerWaiter: new HttpContainerWaiter("/", httpPort: 8080))
#endif
                              .Build();

            // Act
            await environment.Up();

            // Assert
            var staticFilesContainer = environment.GetContainer("from-file");

            await PrintReturnedHtml(staticFilesContainer);

            await DisposeEnvironment(environment);
        }
        public async Task AddMailContainer_WhenContainerIsUp_ShouldPrintSmtpCapabilities()
        {
            // Arrange
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
#if DEBUG
                              .AddMailContainer("my-mail", reuseContainer: true)
#else
                              .AddMailContainer("my-mail")
#endif
                              .Build();

            // Act
            await environment.Up();

            // Assert
            var mail = environment.GetContainer <MailContainer>("my-mail");

            await PrintSmtpCapabilities(mail);

            await DisposeEnvironment(environment);
        }
        public async Task AddMongoContainer_WhenContainerIsUp_ShouldPrintMongoVersion()
        {
            // Arrange
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
#if DEBUG
                              .AddMongoContainer("my-mongo", reuseContainer: true)
#else
                              .AddMongoContainer("my-mongo")
#endif
                              .Build();

            // Act
            await environment.Up();

            // Assert
            var mongo = environment.GetContainer <MongoContainer>("my-mongo");

            PrintMongoVersion(mongo);

            await DisposeEnvironment(environment);
        }
        public async Task CreateDockerEnvironment()
        {
            // Create the environment using builder pattern
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
                              .AddContainer("my-nginx", "nginx")
#if DEBUG
                              .AddElasticsearchContainer("my-elastic", ports: new Dictionary <ushort, ushort> {
                [9200] = 9200
            }, reuseContainer: true)
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0", environmentVariables: new Dictionary <string, string> {
                ["MSSQL_COLLATION"] = "SQL_Latin1_General_CP1_CS_AS"
            }, reuseContainer: true)
                              .AddMariaDBContainer("my-maria", "my-secret-pw", reuseContainer: true)
                              .AddMongoContainer("my-mongo", reuseContainer: true)
                              .AddMailContainer("my-mail", reuseContainer: true)
                              .AddFtpContainer("my-ftp", "superuser", "test", ports: Enumerable.Range(30000, 10).ToDictionary(p => (ushort)p, p => (ushort)p).MergeDictionaries(new Dictionary <ushort, ushort> {
                [21] = 21
            }), reuseContainer: true)
                              .AddFromDockerfile("from-file", "Dockerfile", containerWaiter: new HttpContainerWaiter("/", httpPort: 8080), reuseContainer: true)
                              .AddPostgresContainer("my-postgres", reuseContainer: true)
#else
                              .AddElasticsearchContainer("my-elastic")
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0")
                              .AddMariaDBContainer("my-maria", "my-secret-pw")
                              .AddMongoContainer("my-mongo")
                              .AddMailContainer("my-mail")
                              .AddFromDockerfile("from-file", "Dockerfile", containerWaiter: new HttpContainerWaiter("/", httpPort: 8080))
                              .AddFtpContainer("my-ftp", "superuser", "test", ports: Enumerable.Range(30000, 10).ToDictionary(p => (ushort)p, p => (ushort)p).MergeDictionaries(new Dictionary <ushort, ushort> {
                [21] = 21
            }))
                              .AddPostgresContainer("my-postgres")
#endif
                              .Build();

            // Up it.
            await environment.Up();

            // Play with containers.
            var mssql = environment.GetContainer <MssqlContainer>("my-mssql");

            await PrintMssqlVersion(mssql);

            var elastic = environment.GetContainer <ElasticsearchContainer>("my-elastic");

            await PrintElasticsearchVersion(elastic);

            var mongo = environment.GetContainer <MongoContainer>("my-mongo");

            PrintMongoVersion(mongo);

            var staticFilesContainer = environment.GetContainer("from-file");

            await PrintReturnedHtml(staticFilesContainer);

            var maria = environment.GetContainer <MariaDBContainer>("my-maria");

            await PrintMariaDBVersion(maria);

            var ftp = environment.GetContainer <FtpContainer>("my-ftp");

            await PrintFtpServerType(ftp);

            var mail = environment.GetContainer <MailContainer>("my-mail");

            await PrintSmtpCapabilities(mail);

            var postgres = environment.GetContainer <PostgresContainer>("my-postgres");

            await PrintPostgresDbVersion(postgres);

#if !DEBUG
            // Down it.
            await environment.Down();

            // Dispose (remove).
            environment.Dispose();
#endif
        }