Exemplo n.º 1
0
        public void XmlDocumentationFileIsGenerated()
        {
            // create unique directories in the 'temp' folder
            var root = Temp.CreateDirectory();
            root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));

            var testLibDir = root.CreateDirectory("TestLibrary");

            // copy projects to the temp dir and restore them
            CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
            RunRestore(testLibDir.Path);

            // run compile
            var outputDir = Path.Combine(testLibDir.Path, "bin");
            var testProject = GetProjectPath(testLibDir);
            var buildCommand = new BuildCommand(testProject, output: outputDir);
            var result = buildCommand.ExecuteWithCapturedOutput();
            result.Should().Pass();

            // verify the output xml file
            var outputXml = Path.Combine(outputDir, "Debug", "dnxcore50", "TestLibrary.xml");
            Console.WriteLine("OUTPUT XML PATH: " + outputXml);
            Assert.True(File.Exists(outputXml));
            Assert.Contains("Gets the message from the helper", File.ReadAllText(outputXml));
        }
Exemplo n.º 2
0
        public void XmlDocumentationFileIsGenerated()
        {
            // create unique directories in the 'temp' folder
            var root = Temp.CreateDirectory();
            var testLibDir = root.CreateDirectory("TestLibrary");

            // copy projects to the temp dir and restore them
            CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
            RunRestore(testLibDir.Path);

            // run compile
            var outputDir = Path.Combine(testLibDir.Path, "bin");
            var testProject = GetProjectPath(testLibDir);
            var buildCommand = new BuildCommand(testProject, output: outputDir);
            var result = buildCommand.ExecuteWithCapturedOutput();
            result.Should().Pass();

            // Should have triggered some compiler warnings about missing XML doc comments
            Assert.True(result.StdErr.Contains("warning CS1591"));

            // verify the output xml file
            var outputXml = Path.Combine(outputDir, "TestLibrary.xml");
            Assert.True(File.Exists(outputXml));
            Assert.Contains("Gets the message from the helper", File.ReadAllText(outputXml));
        }
Exemplo n.º 3
0
 public void LibraryWithAnalyzer()
 {
     var root = Temp.CreateDirectory();
     var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer");
     
     CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer"), testLibDir);
     
     // run compile
     var outputDir = Path.Combine(testLibDir.Path, "bin");
     var testProject = GetProjectPath(testLibDir);
     var buildCmd = new BuildCommand(testProject, output: outputDir);
     var result = buildCmd.ExecuteWithCapturedOutput();
     result.Should().Pass();
     Assert.Contains("CA1018", result.StdOut);
 }
        public void It_builds_projects_with_Unicode_in_path()
        {
            var testInstance = TestAssetsManager
                .CreateTestInstance("TestAppWithUnicodéPath")
                .WithLockFiles();

            var testProjectDirectory = testInstance.TestRoot;

            var buildCommand = new BuildCommand("");
            buildCommand.WorkingDirectory = testProjectDirectory;

            buildCommand.ExecuteWithCapturedOutput()
                .Should()
                .Pass();
        }
Exemplo n.º 5
0
        protected CommandResult BuildProject(string projectFile, bool noDependencies = false, bool noIncremental = false, bool expectBuildFailure = false)
        {
            var buildCommand = new BuildCommand(projectFile, output: GetOutputDir(), framework: "dnxcore50", noIncremental: noIncremental, noDependencies : noDependencies);
            var result = buildCommand.ExecuteWithCapturedOutput();

            if (!expectBuildFailure)
            {
                result.Should().Pass();
                TestOutputExecutable(GetOutputExePath(), buildCommand.GetOutputExecutableName(), ExpectedOutput);
            }
            else
            {
                result.Should().Fail();
            }

            return result;
        }
Exemplo n.º 6
0
        public void WrappedProjectFilesResolvedCorrectly()
        {
            var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithWrapperProjectDependency")
                                                .WithBuildArtifacts()
                                                .WithLockFiles();

            var root = testInstance.TestRoot;

            // run compile
            var outputDir = Path.Combine(root, "bin");
            var testProject = ProjectUtils.GetProjectJson(root, "TestApp");
            var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
            var result = buildCommand.ExecuteWithCapturedOutput();
            result.Should().Pass();

            new DirectoryInfo(outputDir).Should()
                .HaveFiles(new [] { "TestLibrary.dll", "TestLibrary.pdb" });
        }
        public void TestRebuildWhenVersionSuffixChanged()
        {
            var testInstance = TestAssetsManager.CreateTestInstance("TestSimpleIncrementalApp")
                .WithLockFiles();

            // Build with Version Suffix 1
            var command = new BuildCommand(testInstance.TestRoot, versionSuffix: "1");
            var result = command.ExecuteWithCapturedOutput();

            // Verify the result
            result.Should().HaveCompiledProject("TestSimpleIncrementalApp", ".NETCoreApp,Version=v1.0");

            // Build with Version Suffix 2
            command = new BuildCommand(testInstance.TestRoot, versionSuffix: "2");
            result = command.ExecuteWithCapturedOutput();

            // Verify the result
            result.Should().HaveCompiledProject("TestSimpleIncrementalApp", ".NETCoreApp,Version=v1.0");
        }
Exemplo n.º 8
0
        protected CommandResult BuildProject(bool forceIncrementalUnsafe = false, bool expectBuildFailure = false)
        {
            var outputDir = GetBinDirectory();
            var intermediateOutputDir = Path.Combine(Directory.GetParent(outputDir).FullName, "obj", _mainProject);
            var mainProjectFile = GetProjectFile(_mainProject);

            var buildCommand = new BuildCommand(mainProjectFile, output: outputDir, tempOutput: intermediateOutputDir ,forceIncrementalUnsafe : forceIncrementalUnsafe);
            var result = buildCommand.ExecuteWithCapturedOutput();

            if (!expectBuildFailure)
            {
                result.Should().Pass();
                TestOutputExecutable(outputDir, buildCommand.GetOutputExecutableName(), _expectedOutput);
            }
            else
            {
                result.Should().Fail();
            }

            return result;
        }
Exemplo n.º 9
0
        public void SatelliteAssemblyIsGeneratedByDotnetBuild()
        {
            // create unique directories in the 'temp' folder
            var root = Temp.CreateDirectory();
            var testLibDir = root.CreateDirectory("TestProjectWithCultureSpecificResource");
            var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestProjectWithCultureSpecificResource");

            CopyProjectToTempDir(sourceTestLibDir, testLibDir);

            // run compile on a project with resources
            var outputDir = Path.Combine(testLibDir.Path, "bin");
            var testProject = GetProjectPath(testLibDir);
            var buildCmd = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
            var result = buildCmd.ExecuteWithCapturedOutput();
            result.Should().Pass();

            var generatedSatelliteAssemblyPath = Path.Combine(
                outputDir,
                "Debug",
                DefaultFramework,
                "fr",
                "TestProjectWithCultureSpecificResource.resources.dll");
            Assert.True(File.Exists(generatedSatelliteAssemblyPath), $"File {generatedSatelliteAssemblyPath} was not found.");
        }
Exemplo n.º 10
0
        public void ContentFilesAreCopied()
        {
            var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithContentPackage")
                                                .WithLockFiles();

            var root = testInstance.TestRoot;

            // run compile
            var outputDir = Path.Combine(root, "bin");
            var testProject = ProjectUtils.GetProjectJson(root, "TestAppWithContentPackage");
            var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
            var result = buildCommand.ExecuteWithCapturedOutput();
            result.Should().Pass();

            result = Command.Create(Path.Combine(outputDir, "AppWithContentPackage" + buildCommand.GetExecutableExtension()), new string [0])
                .CaptureStdErr()
                .CaptureStdOut()
                .Execute();
            result.Should().Pass();

            // verify the output xml file
            new DirectoryInfo(outputDir).Sub("scripts").Should()
                .Exist()
                .And.HaveFile("run.cmd");
            new DirectoryInfo(outputDir).Should()
                .HaveFile("config.xml");
            // verify embedded resources
            result.StdOut.Should().Contain("AppWithContentPackage.dnf.png");
            result.StdOut.Should().Contain("AppWithContentPackage.ui.png");
            // verify 'all' language files not included
            result.StdOut.Should().NotContain("AppWithContentPackage.dnf_all.png");
            result.StdOut.Should().NotContain("AppWithContentPackage.ui_all.png");
            // verify classes
            result.StdOut.Should().Contain("AppWithContentPackage.Foo");
            result.StdOut.Should().Contain("MyNamespace.Util");
        }
Exemplo n.º 11
0
        public void EmbeddedResourcesAreCopied()
        {
            var testInstance = TestAssetsManager.CreateTestInstance("EndToEndTestApp")
                                                .WithLockFiles()
                                                .WithBuildArtifacts();

            var root = testInstance.TestRoot;

            // run compile
            var outputDir = Path.Combine(root, "bin");
            var testProject = ProjectUtils.GetProjectJson(root, "EndToEndTestApp");
            var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
            var result = buildCommand.ExecuteWithCapturedOutput();
            result.Should().Pass();

            var objDirInfo = new DirectoryInfo(Path.Combine(root, "obj", "Debug", DefaultFramework));
            objDirInfo.Should().HaveFile("EndToEndTestApp.resource1.resources");
            objDirInfo.Should().HaveFile("myresource.resources");
            objDirInfo.Should().HaveFile("EndToEndTestApp.defaultresource.resources");
        }
Exemplo n.º 12
0
        public void CopyToOutputFilesAreCopied()
        {
            var testInstance = TestAssetsManager.CreateTestInstance("EndToEndTestApp")
                                                .WithLockFiles()
                                                .WithBuildArtifacts();

            var root = testInstance.TestRoot;

            // run compile
            var outputDir = Path.Combine(root, "bin");
            var testProject = ProjectUtils.GetProjectJson(root, "EndToEndTestApp");
            var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
            var result = buildCommand.ExecuteWithCapturedOutput();
            result.Should().Pass();

            var outputDirInfo = new DirectoryInfo(Path.Combine(outputDir, "copy"));
            outputDirInfo.Should().HaveFile("file.txt");
            outputDirInfo.Should().NotHaveFile("fileex.txt");
        }
Exemplo n.º 13
0
        public void MultipleFrameworks_ShouldHaveValidTargetFrameworkAttribute(string frameworkName, bool shouldHaveTargetFrameworkAttribute, bool windowsOnly)
        {
            var framework = NuGetFramework.Parse(frameworkName);

            var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithMultipleFrameworks")
                                                .WithLockFiles();

            var cmd = new BuildCommand(Path.Combine(testInstance.TestRoot, Project.FileName), framework: framework.GetShortFolderName());

            if (windowsOnly && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // on non-windows platforms, desktop frameworks will not build
                cmd.ExecuteWithCapturedOutput().Should().Fail();
            }
            else
            {
                cmd.ExecuteWithCapturedOutput().Should().Pass();

                var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", framework.GetShortFolderName(), "TestLibraryWithMultipleFrameworks.dll");
                var targetFramework = PeReaderUtils.GetAssemblyAttributeValue(output, "TargetFrameworkAttribute");

                if (shouldHaveTargetFrameworkAttribute)
                {
                    targetFramework.Should().NotBeNull();
                    targetFramework.Should().BeEquivalentTo(framework.DotNetFrameworkName);
                }
                else
                {
                    targetFramework.Should().BeNull();
                }
            }
        }
Exemplo n.º 14
0
        public void SettingVersionSuffixFlag_ShouldStampAssemblyInfoInOutputAssembly()
        {
            var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithConfiguration")
                                                .WithLockFiles();

            var cmd = new BuildCommand(Path.Combine(testInstance.TestRoot, Project.FileName), framework: DefaultFramework, versionSuffix: "85");
            cmd.ExecuteWithCapturedOutput().Should().Pass();

            var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", DefaultFramework, "TestLibraryWithConfiguration.dll");
            var informationalVersion = PeReaderUtils.GetAssemblyAttributeValue(output, "AssemblyInformationalVersionAttribute");

            informationalVersion.Should().NotBeNull();
            informationalVersion.Should().BeEquivalentTo("1.0.0-85");
        }
Exemplo n.º 15
0
        public void CanSetOutputAssemblyNameForLibraries()
        {
            var testInstance =
                TestAssetsManager
                    .CreateTestInstance("LibraryWithOutputAssemblyName")
                    .WithLockFiles();

            var root = testInstance.TestRoot;
            var outputDir = Path.Combine(root, "bin");
            var testProject = ProjectUtils.GetProjectJson(root, "LibraryWithOutputAssemblyName");
            var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultLibraryFramework);
            var result = buildCommand.ExecuteWithCapturedOutput();
            result.Should().Pass();

            new DirectoryInfo(outputDir).Should().HaveFiles(new [] { "MyLibrary.dll" });
        }
Exemplo n.º 16
0
        public void UnresolvedReferenceCausesBuildToFailAndNotProduceOutput()
        {
            var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects");
            var testInstance = testAssetsManager.CreateTestInstance("TestProjectWithUnresolvedDependency")
                                                .WithLockFiles();

            var restoreResult = new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.Execute();
            restoreResult.Should().Fail();
            new DirectoryInfo(testInstance.TestRoot).Should().HaveFile("project.lock.json");

            var buildCmd = new BuildCommand(testInstance.TestRoot);
            var buildResult = buildCmd.ExecuteWithCapturedOutput();
            buildResult.Should().Fail();

            buildResult.StdErr.Should().Contain("The dependency ThisIsNotARealDependencyAndIfSomeoneGoesAndAddsAProjectWithThisNameIWillFindThemAndPunishThem could not be resolved.");

            var outputDir = new DirectoryInfo(Path.Combine(testInstance.TestRoot, "bin", "Debug", "netcoreapp1.0"));
            outputDir.GetFiles().Length.Should().Be(0);
        }
Exemplo n.º 17
0
        public void SettingVersionInEnvironment_ShouldStampAssemblyInfoInOutputAssembly()
        {
            var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithConfiguration")
                                                .WithLockFiles();

            var cmd = new BuildCommand(Path.Combine(testInstance.TestRoot, Project.FileName), framework: DefaultLibraryFramework);
            cmd.Environment["DOTNET_BUILD_VERSION"] = "85";
            cmd.Environment["DOTNET_ASSEMBLY_FILE_VERSION"] = "345";
            cmd.ExecuteWithCapturedOutput().Should().Pass();

            var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", DefaultLibraryFramework, "TestLibraryWithConfiguration.dll");
            var informationalVersion = PeReaderUtils.GetAssemblyAttributeValue(output, "AssemblyInformationalVersionAttribute");
            var fileVersion = PeReaderUtils.GetAssemblyAttributeValue(output, "AssemblyFileVersionAttribute");

            informationalVersion.Should().NotBeNull();
            informationalVersion.Should().BeEquivalentTo("1.0.0-85");

            fileVersion.Should().NotBeNull();
            fileVersion.Should().BeEquivalentTo("1.0.0.345");
        }
Exemplo n.º 18
0
        public void CanSetOutputAssemblyNameForApps()
        {
            var testInstance =
                TestAssetsManager
                    .CreateTestInstance("AppWithOutputAssemblyName")
                    .WithLockFiles();

            var root = testInstance.TestRoot;
            var outputDir = Path.Combine(root, "bin");
            var testProject = ProjectUtils.GetProjectJson(root, "AppWithOutputAssemblyName");
            var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
            var result = buildCommand.ExecuteWithCapturedOutput();
            result.Should().Pass();

            new DirectoryInfo(outputDir).Should().HaveFiles(
                new [] { "MyApp.dll", "MyApp" + buildCommand.GetExecutableExtension(),
                    "MyApp.runtimeconfig.json", "MyApp.deps.json" });
        }