public void It_publishes_portable_apps_to_the_publish_folder_and_the_app_should_run()
        {
            var helloWorldAsset = _testAssetsManager
                                  .CopyTestAsset("HelloWorld")
                                  .WithSource()
                                  .Restore();

            var publishCommand = new PublishCommand(Stage0MSBuild, helloWorldAsset.TestRoot);
            var publishResult  = publishCommand.Execute();

            publishResult.Should().Pass();

            var publishDirectory = publishCommand.GetOutputDirectory();

            publishDirectory.Should().OnlyHaveFiles(new[] {
                "HelloWorld.dll",
                "HelloWorld.pdb",
                "HelloWorld.deps.json",
                "HelloWorld.runtimeconfig.json"
            });

            Command.Create(RepoInfo.DotNetHostPath, new[] { Path.Combine(publishDirectory.FullName, "HelloWorld.dll") })
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World!");
        }
Esempio n. 2
0
        public async Task RestartProcessOnFileChange()
        {
            var testAsset = _testAssetsManager.CopyTestAsset(AppName)
                            .WithSource()
                            .Path;

            using var app = new WatchableApp(testAsset, _output);

            await app.StartWatcherAsync(new[] { "--no-exit" });

            var processIdentifier = await app.GetProcessIdentifier();

            // Then wait for it to restart when we change a file
            var fileToChange = Path.Combine(app.SourceDirectory, "Program.cs");
            var programCs    = File.ReadAllText(fileToChange);

            File.WriteAllText(fileToChange, programCs);

            await app.HasRestarted();

            Assert.DoesNotContain(app.Process.Output, l => l.StartsWith("Exited with error code"));

            var processIdentifier2 = await app.GetProcessIdentifier();

            Assert.NotEqual(processIdentifier, processIdentifier2);
        }
Esempio n. 3
0
        public void It_builds_nondesktop_library_successfully_on_all_platforms()
        {
            var testAsset = _testAssetsManager
                            .CopyTestAsset("CrossTargeting")
                            .WithSource()
                            .Restore("NetStandardAndNetCoreApp");

            var libraryProjectDirectory = Path.Combine(testAsset.TestRoot, "NetStandardAndNetCoreApp");

            var buildCommand = new BuildCommand(Stage0MSBuild, libraryProjectDirectory);

            buildCommand
            .Execute()
            .Should()
            .Pass();

            var outputDirectory = buildCommand.GetOutputDirectory(targetFramework: "");

            outputDirectory.Should().OnlyHaveFiles(new[] {
                "netcoreapp1.0/NetStandardAndNetCoreApp.dll",
                "netcoreapp1.0/NetStandardAndNetCoreApp.pdb",
                "netcoreapp1.0/NetStandardAndNetCoreApp.runtimeconfig.json",
                "netcoreapp1.0/NetStandardAndNetCoreApp.runtimeconfig.dev.json",
                "netcoreapp1.0/NetStandardAndNetCoreApp.deps.json",
                "netstandard1.5/NetStandardAndNetCoreApp.dll",
                "netstandard1.5/NetStandardAndNetCoreApp.pdb",
                "netstandard1.5/NetStandardAndNetCoreApp.deps.json"
            });
        }
        public void It_builds_the_project_successfully()
        {
            var testAsset = _testAssetsManager
                            .CopyTestAsset("AppWithLibrary")
                            .WithSource();

            testAsset.Restore("TestApp");
            testAsset.Restore("TestLibrary");

            VerifyAppBuilds(testAsset);
        }
        public void It_packs_nondesktop_library_successfully_on_all_platforms()
        {
            var testAsset = _testAssetsManager
                            .CopyTestAsset("CrossTargeting")
                            .WithSource()
                            .Restore("NetStandardAndNetCoreApp");

            var libraryProjectDirectory = Path.Combine(testAsset.TestRoot, "NetStandardAndNetCoreApp");

            new PackCommand(Stage0MSBuild, libraryProjectDirectory)
            .Execute()
            .Should()
            .Pass();

            var outputDirectory = new DirectoryInfo(Path.Combine(libraryProjectDirectory, "bin", "Debug"));

            outputDirectory.Should().OnlyHaveFiles(new[] {
                "NetStandardAndNetCoreApp.1.0.0.nupkg",
                "netcoreapp1.0/NetStandardAndNetCoreApp.dll",
                "netcoreapp1.0/NetStandardAndNetCoreApp.pdb",
                "netcoreapp1.0/NetStandardAndNetCoreApp.runtimeconfig.json",
                "netcoreapp1.0/NetStandardAndNetCoreApp.runtimeconfig.dev.json",
                "netcoreapp1.0/NetStandardAndNetCoreApp.deps.json",
                "netstandard1.5/NetStandardAndNetCoreApp.dll",
                "netstandard1.5/NetStandardAndNetCoreApp.pdb",
                "netstandard1.5/NetStandardAndNetCoreApp.deps.json"
            });
        }
        public void It_retrieves_strings_successfully()
        {
            var testAsset = _testAssetsManager
                            .CopyTestAsset("AllResourcesInSatellite")
                            .WithSource()
                            .Restore();

            var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot);

            buildCommand
            .Execute()
            .Should()
            .Pass();

            var outputDirectory = buildCommand.GetOutputDirectory(targetFramework: "netcoreapp1.0");

            outputDirectory.Should().OnlyHaveFiles(new[] {
                "AllResourcesInSatellite.dll",
                "AllResourcesInSatellite.pdb",
                "AllResourcesInSatellite.runtimeconfig.json",
                "AllResourcesInSatellite.runtimeconfig.dev.json",
                "AllResourcesInSatellite.deps.json",
                "en/AllResourcesInSatellite.resources.dll",
            });

            Command.Create(RepoInfo.DotNetHostPath, new[] { Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.dll") })
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World from en satellite assembly");
        }
Esempio n. 7
0
        public async Task LaunchesBrowserOnStart()
        {
            var expected  = "watch : Launching browser: https://localhost:5001/";
            var testAsset = _testAssetsManager.CopyTestAsset(AppName)
                            .WithSource()
                            .Path;

            using var app = new WatchableApp(testAsset, _logger);

            app.DotnetWatchArgs.Add("--verbose");

            await app.StartWatcherAsync();

            // Verify we launched the browser.
            await app.Process.GetOutputLineStartsWithAsync(expected, TimeSpan.FromMinutes(2));
        }
Esempio n. 8
0
        public void It_publishes_projects_with_simple_dependencies()
        {
            TestAsset simpleDependenciesAsset = _testAssetsManager
                                                .CopyTestAsset("SimpleDependencies")
                                                .WithSource()
                                                .Restore();

            PublishCommand publishCommand = new PublishCommand(Stage0MSBuild, simpleDependenciesAsset.TestRoot);

            publishCommand
            .Execute()
            .Should()
            .Pass();

            DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory();

            publishDirectory.Should().OnlyHaveFiles(new[] {
                "SimpleDependencies.dll",
                "SimpleDependencies.pdb",
                "SimpleDependencies.deps.json",
                "SimpleDependencies.runtimeconfig.json",
                "Newtonsoft.Json.dll",
                "System.Runtime.Serialization.Primitives.dll",
                "System.Collections.NonGeneric.dll",
            });

            string appPath = publishCommand.GetPublishedAppPath("SimpleDependencies");

            Command runAppCommand = Command.Create(
                RepoInfo.DotNetHostPath,
                new[] { appPath, "one", "two" });

            string expectedOutput =
                @"{
  ""one"": ""one"",
  ""two"": ""two""
}";

            runAppCommand
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining(expectedOutput);
        }
Esempio n. 9
0
        public void It_respects_opt_outs(string attributeToOptOut)
        {
            var testAsset = _testAssetsManager
                            .CopyTestAsset("HelloWorld", identifier: Path.DirectorySeparatorChar + attributeToOptOut)
                            .WithSource()
                            .Restore();

            var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot);

            buildCommand
            .Execute(
                "/p:Version=1.2.3-beta",
                "/p:FileVersion=4.5.6.7",
                "/p:AssemblyVersion=8.9.10.11",
                "/p:Company=TestCompany",
                "/p:Configuration=Release",
                "/p:Copyright=TestCopyright",
                "/p:Description=TestDescription",
                "/p:Product=TestProduct",
                "/p:AssemblyTitle=TestTitle",
                "/p:NeutralLanguage=fr",
                attributeToOptOut == "All" ?
                "/p:GenerateAssemblyInfo=false" :
                $"/p:Generate{attributeToOptOut}=false"
                )
            .Should()
            .Pass();

            var expectedInfo = new SortedDictionary <string, string>
            {
                { "AssemblyInformationalVersionAttribute", "1.2.3-beta" },
                { "AssemblyFileVersionAttribute", "4.5.6.7" },
                { "AssemblyVersionAttribute", "8.9.10.11" },
                { "AssemblyCompanyAttribute", "TestCompany" },
                { "AssemblyConfigurationAttribute", "Release" },
                { "AssemblyCopyrightAttribute", "TestCopyright" },
                { "AssemblyDescriptionAttribute", "TestDescription" },
                { "AssemblyProductAttribute", "TestProduct" },
                { "AssemblyTitleAttribute", "TestTitle" },
                { "NeutralResourcesLanguageAttribute", "fr" },
            };

            if (attributeToOptOut == "All")
            {
                expectedInfo.Clear();
            }
            else
            {
                expectedInfo.Remove(attributeToOptOut);
            }

            expectedInfo.Add("TargetFrameworkAttribute", ".NETCoreApp,Version=v1.0");

            var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netcoreapp1.0", "Release").FullName, "HelloWorld.dll");
            var actualInfo   = AssemblyInfo.Get(assemblyPath);

            actualInfo.Should().Equal(expectedInfo);
        }
        public void It_retrieves_strings_successfully()
        {
            var testAsset = _testAssetsManager
                            .CopyTestAsset("AllResourcesInSatellite")
                            .WithSource()
                            .Restore();

            var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot);

            buildCommand
            .Execute()
            .Should()
            .Pass();

            foreach (var targetFramework in new[] { "net46", "netcoreapp1.0" })
            {
                if (targetFramework == "net46" && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    continue;
                }

                var outputDirectory = buildCommand.GetOutputDirectory(targetFramework);

                var outputFiles = new List <string>
                {
                    "AllResourcesInSatellite.pdb",
                    "AllResourcesInSatellite.runtimeconfig.json",
                    "AllResourcesInSatellite.runtimeconfig.dev.json",
                    "en/AllResourcesInSatellite.resources.dll"
                };

                Command command;
                if (targetFramework == "net46")
                {
                    outputFiles.Add("AllResourcesInSatellite.exe");
                    command = Command.Create(Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.exe"), Array.Empty <string>());
                }
                else
                {
                    outputFiles.Add("AllResourcesInSatellite.dll");
                    outputFiles.Add("AllResourcesInSatellite.deps.json");
                    command = Command.Create(RepoInfo.DotNetHostPath, new[] { Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.dll") });
                }

                outputDirectory.Should().OnlyHaveFiles(outputFiles);


                command
                .CaptureStdOut()
                .Execute()
                .Should()
                .Pass()
                .And
                .HaveStdOutContaining("Hello World from en satellite assembly");
            }
        }
Esempio n. 11
0
        public async Task RunsWithDotnetWatchEnvVariable()
        {
            Assert.True(string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOTNET_WATCH")), "DOTNET_WATCH cannot be set already when this test is running");

            var testAsset = _testAssetsManager.CopyTestAsset(AppName)
                            .WithSource()
                            .Path;

            using var app = new WatchableApp(testAsset, _logger);

            await app.StartWatcherAsync();

            const string messagePrefix = "DOTNET_WATCH = ";
            var          message       = await app.Process.GetOutputLineStartsWithAsync(messagePrefix, TimeSpan.FromMinutes(2));

            var envValue = message.Substring(messagePrefix.Length);

            Assert.Equal("1", envValue);
        }
Esempio n. 12
0
        public async Task ChangeCompiledFile(bool usePollingWatcher)
        {
            var testAsset = _testAssetsManager.CopyTestAsset(AppName, identifier: usePollingWatcher.ToString())
                            .WithSource()
                            .Path;

            using var app = new WatchableApp(testAsset, _logger);

            app.UsePollingWatcher = usePollingWatcher;
            await app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);

            var types = await GetCompiledAppDefinedTypes(app).TimeoutAfter(DefaultTimeout);

            Assert.Equal(2, types);

            var fileToChange = Path.Combine(app.SourceDirectory, "include", "Foo.cs");
            var programCs    = File.ReadAllText(fileToChange);

            File.WriteAllText(fileToChange, programCs);

            await app.HasRestarted().TimeoutAfter(DefaultTimeout);

            types = await GetCompiledAppDefinedTypes(app).TimeoutAfter(DefaultTimeout);

            Assert.Equal(2, types);
        }
        public void It_builds_the_library_successfully()
        {
            var testAsset = _testAssetsManager
                            .CopyTestAsset("AppWithLibrary")
                            .WithSource()
                            .Restore(relativePath: "TestLibrary");

            var libraryProjectDirectory = Path.Combine(testAsset.TestRoot, "TestLibrary");

            var buildCommand = new BuildCommand(Stage0MSBuild, libraryProjectDirectory);

            buildCommand
            .Execute()
            .Should()
            .Pass();

            var outputDirectory = buildCommand.GetOutputDirectory("netstandard1.5");

            outputDirectory.Should().OnlyHaveFiles(new[] {
                "TestLibrary.dll",
                "TestLibrary.pdb",
                "TestLibrary.deps.json"
            });
        }
Esempio n. 14
0
        public void It_fails_to_build_if_no_rid_is_set()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }

            var testAsset = _testAssetsManager
                            .CopyTestAsset("DesktopMinusRid")
                            .WithSource()
                            .Restore();

            var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot);

            buildCommand
            .MSBuild
            .CreateCommandForTarget("build", buildCommand.FullPathProjectFile)
            .CaptureStdOut()
            .Execute()
            .Should()
            .Fail()
            .And
            .HaveStdOutContaining("RuntimeIdentifier must be set");
        }
Esempio n. 15
0
        internal static List <string> GetValuesFromTestLibrary(
            ITestOutputHelper log,
            TestAssetsManager testAssetsManager,
            string itemTypeOrPropertyName,
            Action <GetValuesCommand> setup         = null,
            string[] msbuildArgs                    = null,
            GetValuesCommand.ValueType valueType    = GetValuesCommand.ValueType.Item,
            [CallerMemberName] string callingMethod = "",
            Action <XDocument> projectChanges       = null)
        {
            msbuildArgs = msbuildArgs ?? Array.Empty <string>();

            string targetFramework = "netstandard1.5";

            var testAsset = testAssetsManager
                            .CopyTestAsset("AppWithLibrary", callingMethod)
                            .WithSource();

            if (projectChanges != null)
            {
                testAsset.WithProjectChanges(projectChanges);
            }

            testAsset.Restore(log, relativePath: "TestLibrary");

            var libraryProjectDirectory = Path.Combine(testAsset.TestRoot, "TestLibrary");

            var getValuesCommand = new GetValuesCommand(log, libraryProjectDirectory,
                                                        targetFramework, itemTypeOrPropertyName, valueType);

            if (setup != null)
            {
                setup(getValuesCommand);
            }

            getValuesCommand
            .Execute(msbuildArgs)
            .Should()
            .Pass();

            var itemValues = getValuesCommand.GetValues();

            return(itemValues);
        }
Esempio n. 16
0
        public async Task ProjectReferences_Graph()
        {
            // A->B,F,W(Watch=False)
            // B->C,E
            // C->D
            // D->E
            // F->E,G
            // G->E
            // W->U
            // Y->B,F,Z
            var testDirectory = _testAssets.CopyTestAsset("ProjectReferences_Graph")
                                .WithSource()
                                .Path;
            var projectA = Path.Combine(testDirectory, "A", "A.csproj");

            var output         = new OutputSink();
            var options        = GetWatchOptions();
            var filesetFactory = new MsBuildFileSetFactory(options, _reporter, projectA, output, waitOnError: false, trace: true);

            var fileset = await GetFileSet(filesetFactory);

            Assert.NotNull(fileset);

            _reporter.Output(string.Join(
                                 Environment.NewLine,
                                 output.Current.Lines.Select(l => "Sink output: " + l)));

            var includedProjects = new[] { "A", "B", "C", "D", "E", "F", "G" };

            AssertEx.EqualFileList(
                testDirectory,
                includedProjects
                .Select(p => $"{p}/{p}.csproj"),
                fileset
                );

            // ensure each project is only visited once for collecting watch items
            Assert.All(includedProjects,
                       projectName =>
                       Assert.Single(output.Current.Lines,
                                     line => line.Contains($"Collecting watch items from '{projectName}'"))
                       );
        }
Esempio n. 17
0
        public async Task ConsoleCancelKey()
        {
            var console   = new TestConsole(_output);
            var testAsset = _testAssetsManager.CopyTestAsset(AppName)
                            .WithSource()
                            .Path;

            using var watchableApp = new WatchableApp(testAsset, _output);
            using var app          = new Program(console, testAsset);

            var run = app.RunAsync(new[] { "run" });

            await console.CancelKeyPressSubscribed.TimeoutAfter(TimeSpan.FromSeconds(30));

            console.ConsoleCancelKey();

            var exitCode = await run.TimeoutAfter(TimeSpan.FromSeconds(30));

            Assert.Contains("Shutdown requested. Press Ctrl+C again to force exit.", console.GetOutput());
            Assert.Equal(0, exitCode);
        }
Esempio n. 18
0
        public async Task ChangeFileInDependency()
        {
            var testAssetsManager = new TestAssetsManager(_logger);

            var testAsset = testAssetsManager.CopyTestAsset("WatchAppWithProjectDeps")
                            .WithSource()
                            .Path;

            var projectDir    = Path.Combine(testAsset, "AppWithDeps");
            var dependencyDir = Path.Combine(testAsset, "Dependency");

            using var app = new WatchableApp(projectDir, _logger);
            await app.StartWatcherAsync();

            var fileToChange = Path.Combine(dependencyDir, "Foo.cs");
            var programCs    = File.ReadAllText(fileToChange);

            File.WriteAllText(fileToChange, programCs);

            await app.HasRestarted();
        }
        public void It_packs_successfully()
        {
            var testAsset = _testAssetsManager
                            .CopyTestAsset("HelloWorld")
                            .WithSource()
                            .Restore();

            new PackCommand(Stage0MSBuild, testAsset.TestRoot)
            .Execute()
            .Should()
            .Pass();

            var outputDirectory = new DirectoryInfo(Path.Combine(testAsset.TestRoot, "bin", "Debug"));

            outputDirectory.Should().OnlyHaveFiles(new[] {
                "HelloWorld.1.0.0.nupkg",
                "netcoreapp1.0/HelloWorld.dll",
                "netcoreapp1.0/HelloWorld.pdb",
                "netcoreapp1.0/HelloWorld.deps.json",
                "netcoreapp1.0/HelloWorld.runtimeconfig.json",
                "netcoreapp1.0/HelloWorld.runtimeconfig.dev.json",
            });
        }
        public void It_builds_solusuccessfully()
        {
            var testAsset = _testAssetsManager
                .CopyTestAsset("x64SolutionBuild")
                .WithSource()
                .Restore();


            var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot, "x64SolutionBuild.sln");
            buildCommand
                .Execute()
                .Should()
                .Pass();

            buildCommand.GetOutputDirectory("netcoreapp1.0", Path.Combine("x64", "Debug"))
                .Should()
                .OnlyHaveFiles(new[] {
                    "x64SolutionBuild.runtimeconfig.dev.json",
                    "x64SolutionBuild.runtimeconfig.json",
                    "x64SolutionBuild.deps.json",
                    "x64SolutionBuild.dll",
                    "x64SolutionBuild.pdb"
                });
        }
        internal static void TestSatelliteResources(
            ITestOutputHelper log,
            TestAssetsManager testAssetsManager,
            Action <XDocument> projectChanges       = null,
            Action <BuildCommand> setup             = null,
            [CallerMemberName] string callingMethod = null)
        {
            var testAsset = testAssetsManager
                            .CopyTestAsset("AllResourcesInSatellite", callingMethod)
                            .WithSource();

            if (projectChanges != null)
            {
                testAsset = testAsset.WithProjectChanges(projectChanges);
            }

            testAsset = testAsset.Restore(log);

            var buildCommand = new BuildCommand(log, testAsset.TestRoot);

            if (setup != null)
            {
                setup(buildCommand);
            }

            buildCommand
            .Execute()
            .Should()
            .Pass();

            foreach (var targetFramework in new[] { "net46", "netcoreapp1.1" })
            {
                if (targetFramework == "net46" && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    continue;
                }

                var outputDirectory = buildCommand.GetOutputDirectory(targetFramework);

                var outputFiles = new List <string>
                {
                    "AllResourcesInSatellite.pdb",
                    "en/AllResourcesInSatellite.resources.dll"
                };

                Command command;
                if (targetFramework == "net46")
                {
                    outputFiles.Add("AllResourcesInSatellite.exe");
                    command = Command.Create(Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.exe"), Array.Empty <string>());
                }
                else
                {
                    outputFiles.Add("AllResourcesInSatellite.dll");
                    outputFiles.Add("AllResourcesInSatellite.deps.json");
                    outputFiles.Add("AllResourcesInSatellite.runtimeconfig.json");
                    outputFiles.Add("AllResourcesInSatellite.runtimeconfig.dev.json");
                    command = Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath, new[] { Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.dll") });
                }

                outputDirectory.Should().OnlyHaveFiles(outputFiles);

                command
                .CaptureStdOut()
                .Execute()
                .Should()
                .Pass()
                .And
                .HaveStdOutContaining("Hello World from en satellite assembly");
            }
        }
Esempio n. 22
0
        internal static void TestSatelliteResources(
            ITestOutputHelper log,
            TestAssetsManager testAssetsManager,
            Action <XDocument> projectChanges       = null,
            Action <BuildCommand> setup             = null,
            [CallerMemberName] string callingMethod = null)
        {
            var testAsset = testAssetsManager
                            .CopyTestAsset("AllResourcesInSatellite", callingMethod)
                            .WithSource();

            if (projectChanges != null)
            {
                testAsset = testAsset.WithProjectChanges(projectChanges);
            }

            var buildCommand = new BuildCommand(testAsset);

            if (setup != null)
            {
                setup(buildCommand);
            }

            buildCommand
            .Execute()
            .Should()
            .Pass();

            foreach (var targetFramework in new[] { "net46", ToolsetInfo.CurrentTargetFramework })
            {
                if (targetFramework == "net46" && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    continue;
                }

                var outputDirectory = buildCommand.GetOutputDirectory(targetFramework);

                var outputFiles = new List <string>
                {
                    "AllResourcesInSatellite.pdb",
                    "en/AllResourcesInSatellite.resources.dll"
                };

                TestCommand command;
                if (targetFramework == "net46")
                {
                    outputFiles.Add("AllResourcesInSatellite.exe");
                    outputFiles.Add("AllResourcesInSatellite.exe.config");
                    command = new RunExeCommand(log, Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.exe"));
                }
                else
                {
                    outputFiles.Add($"AllResourcesInSatellite{EnvironmentInfo.ExecutableExtension}");
                    outputFiles.Add("AllResourcesInSatellite.dll");
                    outputFiles.Add("AllResourcesInSatellite.deps.json");
                    outputFiles.Add("AllResourcesInSatellite.runtimeconfig.json");
                    command = new DotnetCommand(log, Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.dll"));
                }

                outputDirectory.Should().OnlyHaveFiles(outputFiles);

                command
                .Execute()
                .Should()
                .Pass()
                .And
                .HaveStdOutContaining("Hello World from en satellite assembly");
            }
        }
        public void It_publishes_the_project_with_a_refs_folder_and_correct_deps_file()
        {
            var testAsset = _testAssetsManager
                            .CopyTestAsset("CompilationContext", "PreserveCompilationContext")
                            .WithSource()
                            .WithProjectChanges(project =>
            {
                //  Workaround for https://github.com/dotnet/sdk/issues/367

                var ns            = XNamespace.Get("http://schemas.microsoft.com/developer/msbuild/2003");
                var propertyGroup = project.Root.Elements(ns + "PropertyGroup").FirstOrDefault();
                propertyGroup.Should().NotBeNull();

                propertyGroup.Add(new XElement(ns + "DisableImplicitFrameworkReferences", "true"));
            });

            testAsset.Restore("TestApp");
            testAsset.Restore("TestLibrary");

            var appProjectDirectory = Path.Combine(testAsset.TestRoot, "TestApp");

            foreach (var targetFramework in new[] { "net46", "netcoreapp1.0" })
            {
                var publishCommand = new PublishCommand(Stage0MSBuild, appProjectDirectory);

                if (targetFramework == "net46" && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    continue;
                }

                publishCommand
                .Execute($"/p:TargetFramework={targetFramework}")
                .Should()
                .Pass();

                var publishDirectory = publishCommand.GetOutputDirectory(targetFramework, runtimeIdentifier: "win7-x86");

                publishDirectory.Should().HaveFiles(new[] {
                    targetFramework == "net46" ? "TestApp.exe" : "TestApp.dll",
                    "TestLibrary.dll",
                    "Newtonsoft.Json.dll"
                });

                var refsDirectory = new DirectoryInfo(Path.Combine(publishDirectory.FullName, "refs"));
                // Should have compilation time assemblies
                refsDirectory.Should().HaveFile("System.IO.dll");
                // Libraries in which lib==ref should be deduped
                refsDirectory.Should().NotHaveFile("TestLibrary.dll");
                refsDirectory.Should().NotHaveFile("Newtonsoft.Json.dll");

                using (var depsJsonFileStream = File.OpenRead(Path.Combine(publishDirectory.FullName, "TestApp.deps.json")))
                {
                    var dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream);

                    string[] expectedDefines;
                    if (targetFramework == "net46")
                    {
                        expectedDefines = new[] { "DEBUG", "TRACE", "NET46" };
                    }
                    else
                    {
                        expectedDefines = new[] { "DEBUG", "TRACE", "NETCOREAPP1_0" };
                    }

                    dependencyContext.CompilationOptions.Defines.Should().BeEquivalentTo(expectedDefines);
                    dependencyContext.CompilationOptions.LanguageVersion.Should().Be("");
                    dependencyContext.CompilationOptions.Platform.Should().Be("x86");
                    dependencyContext.CompilationOptions.Optimize.Should().Be(false);
                    dependencyContext.CompilationOptions.KeyFile.Should().Be("");
                    dependencyContext.CompilationOptions.EmitEntryPoint.Should().Be(true);
                    dependencyContext.CompilationOptions.DebugType.Should().Be("portable");

                    dependencyContext.CompileLibraries.Count.Should().Be(targetFramework == "net46" ? 53 : 149);

                    // Ensure P2P references are specified correctly
                    var testLibrary = dependencyContext
                                      .CompileLibraries
                                      .FirstOrDefault(l => string.Equals(l.Name, "testlibrary", StringComparison.OrdinalIgnoreCase));

                    testLibrary.Assemblies.Count.Should().Be(1);
                    testLibrary.Assemblies[0].Should().Be("TestLibrary.dll");

                    // Ensure framework references are specified correctly
                    if (targetFramework == "net46")
                    {
                        var mscorlibLibrary = dependencyContext
                                              .CompileLibraries
                                              .FirstOrDefault(l => string.Equals(l.Name, "mscorlib", StringComparison.OrdinalIgnoreCase));
                        mscorlibLibrary.Assemblies.Count.Should().Be(1);
                        mscorlibLibrary.Assemblies[0].Should().Be(".NETFramework/v4.6/mscorlib.dll");

                        var systemCoreLibrary = dependencyContext
                                                .CompileLibraries
                                                .FirstOrDefault(l => string.Equals(l.Name, "system.core", StringComparison.OrdinalIgnoreCase));
                        systemCoreLibrary.Assemblies.Count.Should().Be(1);
                        systemCoreLibrary.Assemblies[0].Should().Be(".NETFramework/v4.6/System.Core.dll");
                    }
                }
            }
        }
        public void It_builds_the_project_successfully()
        {
            var testAsset = _testAssetsManager
                            .CopyTestAsset("AppWithLibrary")
                            .WithSource();

            testAsset.Restore("TestApp");
            testAsset.Restore("TestLibrary");

            var appProjectDirectory = Path.Combine(testAsset.TestRoot, "TestApp");

            var buildCommand = new BuildCommand(Stage0MSBuild, appProjectDirectory);

            buildCommand
            .Execute()
            .Should()
            .Pass();

            var outputDirectory = buildCommand.GetOutputDirectory("netcoreapp1.0");

            outputDirectory.Should().OnlyHaveFiles(new[] {
                "TestApp.dll",
                "TestApp.pdb",
                "TestApp.deps.json",
                "TestApp.runtimeconfig.json",
                "TestApp.runtimeconfig.dev.json",
                "TestLibrary.dll",
                "TestLibrary.pdb",
            });

            Command.Create(RepoInfo.DotNetHostPath, new[] { Path.Combine(outputDirectory.FullName, "TestApp.dll") })
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("This string came from the test library!");

            var appInfo = FileVersionInfo.GetVersionInfo(Path.Combine(outputDirectory.FullName, "TestApp.dll"));

            appInfo.CompanyName.Should().Be("Test Authors");
            appInfo.FileVersion.Should().Be("1.2.3.0");
            appInfo.FileDescription.Should().Be("Test AssemblyTitle");
            appInfo.LegalCopyright.Should().Be("Copyright (c) Test Authors");
            appInfo.ProductName.Should().Be("Test Product");

            // This check is blocked from working on non-Windows by https://github.com/dotnet/corefx/issues/11163
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                appInfo.ProductVersion.Should().Be("1.2.3-beta");
            }

            var libInfo = FileVersionInfo.GetVersionInfo(Path.Combine(outputDirectory.FullName, "TestLibrary.dll"));

            libInfo.CompanyName.Trim().Should().Be("TestLibrary");
            libInfo.FileVersion.Should().Be("42.43.44.45");
            libInfo.FileDescription.Should().Be("TestLibrary");
            libInfo.LegalCopyright.Trim().Should().BeEmpty();
            libInfo.ProductName.Should().Be("TestLibrary");

            // This check is blocked from working on non-Windows by https://github.com/dotnet/corefx/issues/11163
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                libInfo.ProductVersion.Should().Be("42.43.44.45-alpha");
            }
        }
        public void It_publishes_the_project_correctly()
        {
            TestAsset testAsset = _testAssetsManager
                                  .CopyTestAsset("KitchenSink")
                                  .WithSource();

            testAsset.Restore("TestApp");
            testAsset.Restore("TestLibrary");

            var appProjectDirectory = Path.Combine(testAsset.TestRoot, "TestApp");

            PublishCommand publishCommand = new PublishCommand(Stage0MSBuild, appProjectDirectory);

            publishCommand
            .Execute()
            .Should()
            .Pass();

            DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory();

            publishDirectory.Should().OnlyHaveFiles(new[] {
                "TestApp.dll",
                "TestApp.pdb",
                "TestApp.deps.json",
                "TestApp.runtimeconfig.json",
                "TestLibrary.dll",
                "TestLibrary.pdb",
                "Newtonsoft.Json.dll",
                "System.Runtime.Serialization.Primitives.dll",
                "CompileCopyToOutput.cs",
                "Resource1.resx",
                "ContentAlways.txt",
                "ContentPreserveNewest.txt",
                "NoneCopyOutputAlways.txt",
                "NoneCopyOutputPreserveNewest.txt",
                "CopyToOutputFromProjectReference.txt",
                "da/TestApp.resources.dll",
                "da/TestLibrary.resources.dll",
                "de/TestApp.resources.dll",
                "de/TestLibrary.resources.dll",
                "fr/TestApp.resources.dll",
                "fr/TestLibrary.resources.dll",
                "System.Spatial.dll",
                "de/System.Spatial.resources.dll",
                "es/System.Spatial.resources.dll",
                "fr/System.Spatial.resources.dll",
                "it/System.Spatial.resources.dll",
                "ja/System.Spatial.resources.dll",
                "ko/System.Spatial.resources.dll",
                "ru/System.Spatial.resources.dll",
                "zh-Hans/System.Spatial.resources.dll",
                "zh-Hant/System.Spatial.resources.dll"
            });

            using (var depsJsonFileStream = File.OpenRead(Path.Combine(publishDirectory.FullName, "TestApp.deps.json")))
            {
                var dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream);

                // Ensure Newtonsoft.Json doesn't get excluded from the deps.json file.
                // TestLibrary has a hard dependency on Newtonsoft.Json.
                // TestApp has a PrivateAssets=All dependency on Microsoft.Extensions.DependencyModel, which depends on Newtonsoft.Json.
                // This verifies that P2P references get walked correctly when doing PrivateAssets exclusion.
                VerifyDependency(dependencyContext, "Newtonsoft.Json", "lib/netstandard1.0/");

                // Verify P2P references get created correctly in the .deps.json file.
                VerifyDependency(dependencyContext, "TestLibrary", "",
                                 "da", "de", "fr");

                // Verify package reference with satellites gets created correctly in the .deps.json file
                VerifyDependency(dependencyContext, "System.Spatial", "lib/portable-net45+wp8+win8+wpa/",
                                 "de", "es", "fr", "it", "ja", "ko", "ru", "zh-Hans", "zh-Hant");
            }
        }