Exemple #1
0
        public void BuildSolution_SupportedProjects_ContainerizesAndRuns(SolutionConfiguration solution)
        {
            ExecuteProcess(() =>
            {
                var appProject = solution.Projects.First(x => x.Name == "app1");
                var frameworks = appProject.PropertyGroup.TargetFrameworks?.Split(';') ?? new [] {appProject.PropertyGroup.TargetFramework };
                var isMultiTarget = frameworks.Length > 1;
                foreach (var framework in frameworks)
                {
                    var version = Regex.Replace(framework, @"[a-z\.]", string.Empty);
                    var dockerFile = !isMultiTarget ? "Dockerfile" : $"Dockerfile{version}";
                    solution.Generate(_testDir);

                    DotNetBuild(_ => _
                        .SetProjectFile(_testDir / "testapp.sln"));
                    DockerBuild(_ => _
                        .SetFile(_testDir / appProject.SlnRelativeDir / dockerFile)
                        .SetPath(_testDir)
                        .SetTag(TagName));
                    var result = DockerRun(_ => _
                            .SetRm(true)
                            .SetImage(TagName))
                        .EnsureOnlyStd()
                        .First()
                        .Text;
                    result.Should().Be("PASSED");
                }
            });
        }
Exemple #2
0
 public void BuildSolution_UnsupportedProjects_SkipDockerfileGeneration(SolutionConfiguration solution)
 {
     solution.Generate(_testDir);
     ExecuteProcess(() =>
     {
         var output = DotNetBuild(_ => _
                                  .SetVerbosity(DotNetVerbosity.Normal)
                                  .SetProjectFile(_testDir / "testapp.sln"))
                      .Flatten();
         output.Should().NotContain("GenerateDockerfile:", "GenerateDockerfile target ran on build, but should have been skipped");
         var dockerFilesGenerated = solution.Projects
                                    .Select(x => _testDir / x.Name / "Dockerfile")
                                    .Where(FileExists)
                                    .ToList();
         dockerFilesGenerated.Should().BeEmpty();
     });
 }
Exemple #3
0
        public void BuildSolution_SupportedProjects_ContainerizesAndRuns(SolutionConfiguration solution)
        {
            ExecuteProcess(() =>
            {
                var appProject    = solution.Projects.First(x => x.Name == "app1");
                var frameworks    = appProject.PropertyGroup.TargetFrameworks?.Split(';') ?? new [] { appProject.PropertyGroup.TargetFramework };
                var isMultiTarget = frameworks.Length > 1;
                foreach (var framework in frameworks)
                {
                    var version    = Regex.Replace(framework, @"[a-z\.]", string.Empty);
                    var dockerFile = !isMultiTarget ? "Dockerfile" : $"Dockerfile{version}";
                    solution.Generate(ContainerAppDir.HostPath);

                    // compile in docker
                    DockerRun(_ => _
                              .EnableRm()
                              .AddVolume(ContainerAppDir)
                              .SetImage(_setup.TestContainerSDKImage)
                              .SetCommand($"dotnet build {ContainerAppDir / "testapp.sln"}"));


                    DockerBuild(_ => _
                                .SetFile(_testDir / appProject.SlnRelativeDir / dockerFile)
                                .SetPath(_testDir)
                                .SetTag(TagName));
                    var result = DockerRun(_ => _
                                           .SetRm(true)
                                           .SetImage(TagName));
                    var stdOut = result
                                 .FirstOrDefault(x => x.Type == OutputType.Std)
                                 .Text;
                    var stdErr = string.Join("\n", result.Where(x => x.Type == OutputType.Err).Select(x => x.Text));
                    if (string.IsNullOrWhiteSpace(stdErr))
                    {
                        stdErr = null;
                    }
                    stdOut.Should().Be("PASSED", $"{stdErr} \n {stdOut}");
                    if (stdErr != null)
                    {
                        Logger.Warn($"Container emitted the following to error output \n {stdErr}");
                    }
                }
            });
        }
Exemple #4
0
 public void BuildSolution_UnsupportedProjects_SkipDockerfileGeneration(SolutionConfiguration solution)
 {
     solution.Generate(_testDir);
     ExecuteProcess(() =>
     {
         var output = DockerRun(_ => _
                                .EnableRm()
                                .AddVolume(ContainerAppDir)
                                .SetImage(_setup.TestContainerSDKImage)
                                .SetCommand($"dotnet build --verbosity normal {ContainerAppDir / "testapp.sln"}"))
                      .Flatten();
         output.Should().NotContain("GenerateDockerfile:", "GenerateDockerfile target ran on build, but should have been skipped");
         var dockerFilesGenerated = solution.Projects
                                    .Select(x => _testDir / x.Name / "Dockerfile")
                                    .Where(FileExists)
                                    .ToList();
         dockerFilesGenerated.Should().BeEmpty();
     });
 }
Exemple #5
0
        public void BuildSolution_SupportedProjects_ContainerizesAndRuns(SolutionConfiguration solution)
        {
            ExecuteProcess(() =>
            {
                var appProject = solution.Projects.First(x => x.Name == "app1");
                solution.Generate(_testDir);

                DotNetBuild(_ => _
                            .SetProjectFile(_testDir / "testapp.sln"));
                DockerBuild(_ => _
                            .SetFile(_testDir / appProject.SlnRelativeDir / "Dockerfile")
                            .SetPath(_testDir)
                            .SetTag(TagName));
                var result = DockerRun(_ => _
                                       .SetRm(true)
                                       .SetImage(TagName))
                             .EnsureOnlyStd()
                             .First()
                             .Text;
                result.Should().Be("PASSED");
            });
        }