public void It_builds_and_runs() { var testAsset = _testAssetsManager .CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib") .WithSource(); // build projects separately with BuildProjectReferences=false to simulate VS build behavior new BuildCommand(testAsset, "NETCoreCppCliTest") .Execute("-p:Platform=x64") .Should() .Pass(); new BuildCommand(testAsset, "CSConsoleApp") .Execute(new string[] { "-p:Platform=x64", "-p:BuildProjectReferences=false" }) .Should() .Pass(); var exe = Path.Combine( //find the platform directory new DirectoryInfo(Path.Combine(testAsset.TestRoot, "CSConsoleApp", "bin")).GetDirectories().Single().FullName, "Debug", "net5.0", "CSConsoleApp.exe"); var runCommand = new RunExeCommand(Log, exe); runCommand .Execute() .Should() .Pass() .And .HaveStdOutContaining("Hello, World!"); }
public void It_runs_single_file_apps(string targetFramework, bool selfContained, string bundleOption) { var testProject = new TestProject() { Name = "SingleFileTest", TargetFrameworks = targetFramework, IsExe = true, }; testProject.AdditionalProperties.Add("SelfContained", $"{selfContained}"); var testAsset = _testAssetsManager.CreateTestProject( testProject, identifier: targetFramework + "_" + selfContained + "_" + bundleOption); var publishCommand = new PublishCommand(testAsset); publishCommand.Execute(PublishSingleFile, RuntimeIdentifier, bundleOption) .Should() .Pass(); var publishDir = GetPublishDirectory(publishCommand, targetFramework).FullName; var singleFilePath = Path.Combine(publishDir, $"{testProject.Name}{Constants.ExeSuffix}"); var command = new RunExeCommand(Log, singleFilePath); command.Execute() .Should() .Pass() .And .HaveStdOutContaining("Hello World"); }
public void DependentUponTest(string targetFramework, bool isExe) { var testProject = new TestProject { Name = "HelloWorld", IsSdkProject = true, TargetFrameworks = targetFramework, IsExe = isExe, SourceFiles = { ["Program.cs"] = @" using System; namespace SomeNamespace { public static class SomeClass { public static void Main(string[] args) { var resourceManager = new global::System.Resources.ResourceManager(""SomeNamespace.SomeClass"", typeof(SomeClass).Assembly); Console.WriteLine(resourceManager.GetString(""SomeString"")); } } } ", }, EmbeddedResources = { ["Program.resx"] = @" <root> <data name=""SomeString"" xml:space=""preserve""> <value>Hello world from a resource!</value> </data> </root> ", } }; var testAsset = _testAssetsManager .CreateTestProject(testProject, identifier: targetFramework + isExe); var buildCommand = new BuildCommand( Log, Path.Combine(testAsset.TestRoot, testProject.Name)); buildCommand .Execute() .Should() .Pass(); var outputDirectory = buildCommand.GetOutputDirectory(targetFramework); var runCommand = new RunExeCommand(Log, Path.Combine(outputDirectory.FullName, "HelloWorld.exe")); runCommand .Execute() .Should() .Pass() .And.HaveStdOutContaining("Hello world from a resource!"); }
public void When_referenced_by_csharp_project_it_publishes_and_runs() { var testAsset = _testAssetsManager .CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib") .WithSource(); new PublishCommand(Log, Path.Combine(testAsset.TestRoot, "CSConsoleApp")) .Execute(new string[] { "-p:Platform=x64" }) .Should() .Pass(); var exe = Path.Combine( //find the platform directory new DirectoryInfo(Path.Combine(testAsset.TestRoot, "CSConsoleApp", "bin")).GetDirectories().Single().FullName, "Debug", "netcoreapp3.1", "publish", "CSConsoleApp.exe"); var runCommand = new RunExeCommand(Log, exe); runCommand .Execute() .Should() .Pass() .And .HaveStdOutContaining("Hello, World!"); }
public void Incremental_add_single_file() { var testProject = new TestProject() { Name = "SingleFileTest", TargetFrameworks = "net5.0", IsExe = true, }; testProject.AdditionalProperties.Add("SelfContained", $"{true}"); var testAsset = _testAssetsManager.CreateTestProject(testProject); var cmd = new PublishCommand(testAsset); var singleFilePath = Path.Combine(GetPublishDirectory(cmd).FullName, $"SingleFileTest{Constants.ExeSuffix}"); cmd.Execute(RuntimeIdentifier).Should().Pass(); var time1 = File.GetLastWriteTimeUtc(singleFilePath); WaitForUtcNowToAdvance(); cmd.Execute(PublishSingleFile, RuntimeIdentifier).Should().Pass(); var time2 = File.GetLastWriteTimeUtc(singleFilePath); time2.Should().BeAfter(time1); var exeCommand = new RunExeCommand(Log, singleFilePath); exeCommand.Execute() .Should() .Pass() .And .HaveStdOutContaining("Hello World"); }
public void It_can_use_implicitly_defined_compilation_constants(string targetFramework, string[] expectedOutput, string targetPlatformIdentifier = null, string targetPlatformVersion = null) { var testProj = new TestProject() { Name = "CompilationConstants", TargetFrameworks = targetFramework, IsExe = true, IsSdkProject = true }; if (targetPlatformIdentifier != null) { testProj.AdditionalProperties["TargetPlatformIdentifier"] = targetPlatformIdentifier; testProj.AdditionalProperties["TargetPlatformVersion"] = targetPlatformVersion; } var testAsset = _testAssetsManager.CreateTestProject(testProj); File.WriteAllText(Path.Combine(testAsset.Path, testProj.Name, $"{testProj.Name}.cs"), @" using System; class Program { static void Main(string[] args) { #if NETCOREAPP Console.WriteLine(""NETCOREAPP""); #endif #if NETCOREAPP2_1 Console.WriteLine(""NETCOREAPP2_1""); #endif #if NETCOREAPP3_1 Console.WriteLine(""NETCOREAPP3_1""); #endif #if NET Console.WriteLine(""NET""); #endif #if NET5_0 Console.WriteLine(""NET5_0""); #endif #if WINDOWS Console.WriteLine(""WINDOWS""); #endif #if IOS Console.WriteLine(""IOS""); #endif } }"); var buildCommand = new BuildCommand(Log, Path.Combine(testAsset.Path, testProj.Name)); buildCommand .Execute() .Should() .Pass(); var runCommand = new RunExeCommand(Log, Path.Combine(buildCommand.GetOutputDirectory(targetFramework).FullName, $"{testProj.Name}.exe")); var stdOut = runCommand.Execute().StdOut.Split(Environment.NewLine.ToCharArray()).Where(line => !string.IsNullOrWhiteSpace(line)); stdOut.Should().BeEquivalentTo(expectedOutput); }
public async Task PathToProgram_is_correctly_parsed(RunExeCommand sut, CommandHandlerSpy commandHandler, string program) { sut.Handler = commandHandler; await sut.InvokeAsync($"exe {program}"); Assert.That(commandHandler.InvocationContext.ParseResult.ValueForArgument(sut.Arguments.First() as Argument <FileInfo>).ToString(), Is.EqualTo(program)); }
public async Task Token_option_is_null_when_not_added(RunExeCommand sut, CommandHandlerSpy commandHandler, string program) { sut.Handler = commandHandler; await sut.InvokeAsync($"exe {program}"); Assert.That(commandHandler.InvocationContext.ParseResult.ValueForOption(CommonOptions.TokenOption), Is.Null); }
public async Task Token_option_is_correctly_parsed_when_added(RunExeCommand sut, CommandHandlerSpy commandHandler, string program, string token) { sut.Handler = commandHandler; await sut.InvokeAsync($"exe {program} --token {token}"); Assert.That(commandHandler.InvocationContext.ParseResult.ValueForOption(CommonOptions.TokenOption), Is.EqualTo(token)); }
public async Task FilePrefix_option_is_correctly_parsed(RunExeCommand sut, CommandHandlerSpy commandHandler, string program, string filePrefix) { sut.Handler = commandHandler; await sut.InvokeAsync($"exe {program} --prefix {filePrefix}"); Assert.That(commandHandler.InvocationContext.ParseResult.ValueForOption(CommonOptions.FilePrefixOption), Is.EqualTo(filePrefix)); }
public async Task Bucket_option_is_correctly_parsed(RunExeCommand sut, CommandHandlerSpy commandHandler, string program, string bucket) { sut.Handler = commandHandler; await sut.InvokeAsync($"exe {program} --bucket {bucket}"); Assert.That(commandHandler.InvocationContext.ParseResult.ValueForOption(CommonOptions.BucketNameOption), Is.EqualTo(bucket)); }
public void User_can_get_bundle_info_before_bundling() { var testProject = new TestProject() { Name = "SingleFileTest", TargetFrameworks = ToolsetInfo.CurrentTargetFramework, IsExe = true, }; testProject.AdditionalProperties.Add("SelfContained", "true"); var testAsset = _testAssetsManager.CreateTestProject(testProject) .WithProjectChanges(project => VerifyPrepareForBundle(project)); var publishCommand = new PublishCommand(testAsset); var singleFilePath = Path.Combine(GetPublishDirectory(publishCommand, ToolsetInfo.CurrentTargetFramework).FullName, $"SingleFileTest{Constants.ExeSuffix}"); publishCommand .Execute(PublishSingleFile, RuntimeIdentifier) .Should() .Pass(); var command = new RunExeCommand(Log, singleFilePath); command.Execute() .Should() .Pass() .And .HaveStdOutContaining("Hello World"); void VerifyPrepareForBundle(XDocument project) { var ns = project.Root.Name.Namespace; var targetName = "CheckPrepareForBundleData"; var target = new XElement(ns + "Target", new XAttribute("Name", targetName), new XAttribute("BeforeTargets", "GenerateSingleFileBundle"), new XAttribute("DependsOnTargets", "PrepareForBundle")); project.Root.Add(target); // <Error Condition = "'@(FilesToBundle->AnyHaveMetadataValue('RelativePath', 'System.Private.CoreLib.dll'))' != 'true'" Text="System.Private.CoreLib.dll is not in FilesToBundle list"> target.Add( new XElement(ns + "Error", new XAttribute("Condition", "'@(FilesToBundle->AnyHaveMetadataValue('RelativePath', 'System.Private.CoreLib.dll'))' != 'true'"), new XAttribute("Text", "System.Private.CoreLib.dll is not in FilesToBundle list"))); var host = $"SingleFileTest{Constants.ExeSuffix}"; // <Error Condition="'$(AppHostFile)' != 'SingleFileTest.exe'" Text="AppHostFile expected to be: 'SingleFileTest.exe' actually: '$(AppHostFile)'" /> target.Add( new XElement(ns + "Error", new XAttribute("Condition", $"'$(AppHostFile)' != '{host}'"), new XAttribute("Text", $"AppHostFile expected to be: '{host}' actually: '$(AppHostFile)'"))); } }
private void RunTest(bool referencedExeShouldRun, [CallerMemberName] string callingMethod = null) { var testProjectInstance = _testAssetsManager.CreateTestProject(MainProject, callingMethod: callingMethod, identifier: MainSelfContained.ToString() + "_" + ReferencedSelfContained.ToString()); string outputDirectory; if (TestWithPublish) { var publishCommand = new PublishCommand(testProjectInstance); publishCommand.Execute() .Should() .Pass(); outputDirectory = publishCommand.GetOutputDirectory(MainProject.TargetFrameworks, runtimeIdentifier: MainProject.RuntimeIdentifier).FullName; } else { var buildCommand = new BuildCommand(testProjectInstance); buildCommand.Execute() .Should() .Pass(); outputDirectory = buildCommand.GetOutputDirectory(MainProject.TargetFrameworks, runtimeIdentifier: MainProject.RuntimeIdentifier).FullName; } var mainExePath = Path.Combine(outputDirectory, MainProject.Name + Constants.ExeSuffix); var referencedExePath = Path.Combine(outputDirectory, ReferencedProject.Name + Constants.ExeSuffix); new RunExeCommand(Log, mainExePath) .Execute() .Should() .Pass() .And .HaveStdOut("Main project"); var referencedExeResult = new RunExeCommand(Log, referencedExePath) .Execute(); if (referencedExeShouldRun) { referencedExeResult .Should() .Pass() .And .HaveStdOut("Referenced project"); } else { referencedExeResult .Should() .Fail(); } }
public void It_supports_composite_r2r(bool extractAll) { // the test fails once in a while on OSX, but dumps are not very informative, // so enabling this for non-OSX platforms, hoping to get a better crash dump // if you see this failing on Linux, please preserve the dump. if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { var projName = "SingleFileTest"; if (extractAll) { projName += "Extracted"; } var testProject = new TestProject() { Name = projName, TargetFrameworks = ToolsetInfo.CurrentTargetFramework, IsExe = true, }; var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(testAsset); var extraArgs = new List <string>() { PublishSingleFile, ReadyToRun, ReadyToRunComposite, RuntimeIdentifier }; if (extractAll) { extraArgs.Add(IncludeAllContent); } publishCommand .Execute(extraArgs.ToArray()) .Should() .Pass(); var publishDir = GetPublishDirectory(publishCommand, targetFramework: ToolsetInfo.CurrentTargetFramework).FullName; var singleFilePath = Path.Combine(publishDir, $"{testProject.Name}{Constants.ExeSuffix}"); var command = new RunExeCommand(Log, singleFilePath); command.Execute() .Should() .Pass() .And .HaveStdOutContaining("Hello World"); } }
public void COMReferenceBuildsAndRuns(bool embedInteropTypes) { var targetFramework = "netcoreapp3.0"; var testProject = new TestProject { Name = "UseComReferences", IsSdkProject = true, TargetFrameworks = targetFramework, IsExe = true, SourceFiles = { ["Program.cs"] = @" class Program { static void Main(string[] args) { System.Console.WriteLine(typeof(VSLangProj.VSProject)); } } ", } }; var reference = new XElement("ItemGroup", new XElement("COMReference", new XAttribute("Include", "VSLangProj.dll"), new XElement("Guid", "49a1950e-3e35-4595-8cb9-920c64c44d67"), new XElement("VersionMajor", "7"), new XElement("VersionMinor", "0"), new XElement("WrapperTool", "tlbimp"), new XElement("Lcid", "0"), new XElement("Isolated", "false"), new XElement("EmbedInteropTypes", embedInteropTypes))); var testAsset = _testAssetsManager .CreateTestProject(testProject, identifier: embedInteropTypes.ToString()) .WithProjectChanges(doc => doc.Root.Add(reference)); var buildCommand = new BuildCommand(testAsset); buildCommand.Execute().Should().Pass(); var outputDirectory = buildCommand.GetOutputDirectory(targetFramework); var runCommand = new RunExeCommand(Log, outputDirectory.File("UseComReferences.exe").FullName); runCommand.Execute().Should().Pass(); }
public void It_handles_native_dependencies_and_platform_target( string identifier, string platformTarget, bool useNativeCode, string expectedProgramOutput) { foreach (bool multiTarget in new[] { false, true }) { var testAsset = _testAssetsManager .CopyTestAsset("DesktopMinusRid", identifier: Path.DirectorySeparatorChar + identifier + (multiTarget ? "Multi" : "")) .WithSource() .WithProjectChanges(project => { var ns = project.Root.Name.Namespace; var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); propertyGroup.Add(new XElement(ns + "UseNativeCode", useNativeCode)); if (platformTarget != null) { propertyGroup.Add(new XElement(ns + "PlatformTarget", platformTarget)); } if (multiTarget) { propertyGroup.Element(ns + "TargetFramework").Remove(); propertyGroup.Add(new XElement(ns + "TargetFrameworks", "net46;netcoreapp1.1")); } }) .Restore(Log); var buildCommand = new BuildCommand(Log, testAsset.TestRoot); buildCommand .Execute() .Should() .Pass(); var exe = Path.Combine(buildCommand.GetOutputDirectory("net46").FullName, "DesktopMinusRid.exe"); var runCommand = new RunExeCommand(Log, exe); runCommand .Execute() .Should() .Pass() .And .HaveStdOutContaining(expectedProgramOutput); } }
public void It_supports_composite_r2r(bool extractAll) { var projName = "SingleFileTest"; if (extractAll) { projName += "Extracted"; } var testProject = new TestProject() { Name = projName, TargetFrameworks = ToolsetInfo.CurrentTargetFramework, IsExe = true, }; var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(testAsset); var extraArgs = new List <string>() { PublishSingleFile, ReadyToRun, ReadyToRunComposite, RuntimeIdentifier }; if (extractAll) { extraArgs.Add(IncludeAllContent); } publishCommand .Execute(extraArgs.ToArray()) .Should() .Pass(); var publishDir = GetPublishDirectory(publishCommand, targetFramework: ToolsetInfo.CurrentTargetFramework).FullName; var singleFilePath = Path.Combine(publishDir, $"{testProject.Name}{Constants.ExeSuffix}"); var command = new RunExeCommand(Log, singleFilePath); command.Execute() .Should() .Pass() .And .HaveStdOutContaining("Hello World"); }
public void Warnings_are_generated_even_with_analyzers_disabled(string targetFramework) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { var projectName = "WarningAppWithPublishAotAnalyzersDisabled"; var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); // PublishAot enables the EnableAotAnalyzer, EnableTrimAnalyzer and EnableSingleFileAnalyzer // only if they don't have a predefined value var testProject = CreateTestProjectWithAnalysisWarnings(targetFramework, projectName, true); testProject.AdditionalProperties["PublishAot"] = "true"; testProject.AdditionalProperties["EnableAotAnalyzer"] = "false"; testProject.AdditionalProperties["EnableTrimAnalyzer"] = "false"; testProject.AdditionalProperties["EnableSingleFileAnalyzer"] = "false"; testProject.AdditionalProperties["SuppressTrimAnalysisWarnings"] = "false"; testProject.AdditionalProperties["RuntimeIdentifier"] = rid; var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand .Execute() .Should().Pass() .And.HaveStdOutContaining("warning IL3050") .And.HaveStdOutContaining("warning IL2026"); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid); var publishedExe = Path.Combine(publishDirectory.FullName, $"{testProject.Name}{Constants.ExeSuffix}"); // The exe exist and should be native File.Exists(publishedExe).Should().BeTrue(); IsNativeImage(publishedExe).Should().BeTrue(); var command = new RunExeCommand(Log, publishedExe) .Execute().Should().Pass() .And.HaveStdOutContaining("Hello world"); } }
private void AssertValidShim(string testRoot, string nugetPackage) { using (var nupkgReader = new PackageArchiveReader(nugetPackage)) { IEnumerable <NuGetFramework> supportedFrameworks = nupkgReader.GetSupportedFrameworks(); supportedFrameworks.Should().NotBeEmpty(); var simulateToolPathRoot = Path.Combine(testRoot, "temp", Path.GetRandomFileName()); foreach (NuGetFramework framework in supportedFrameworks) { string[] portableAppContent = { "consoledemo.runtimeconfig.json", "consoledemo.deps.json", "consoledemo.dll", "Newtonsoft.Json.dll" }; CopyPackageAssetToToolLayout(portableAppContent, nupkgReader, simulateToolPathRoot, framework); string shimPath = Path.Combine(simulateToolPathRoot, $"{_customToolCommandName}.exe"); nupkgReader.ExtractFile( $"tools/{framework.GetShortFolderName()}/any/shims/win-x64/{_customToolCommandName}.exe", shimPath, null); var command = new RunExeCommand(Log, shimPath) { WorkingDirectory = simulateToolPathRoot }; command.Execute().Should() .Pass() .And .HaveStdOutContaining("Hello World from Global Tool"); } } }
public void ItPublishesFrameworkDependentWithRid(string args) { var testAppName = "MSBuildTestApp"; var rid = EnvironmentInfo.GetCompatibleRid(); var outputDirectory = PublishApp(testAppName, rid, args); outputDirectory.Should().OnlyHaveFiles(new[] { $"{testAppName}{Constants.ExeSuffix}", $"{testAppName}.dll", $"{testAppName}.pdb", $"{testAppName}.deps.json", $"{testAppName}.runtimeconfig.json", }); var outputProgram = Path.Combine(outputDirectory.FullName, $"{testAppName}{Constants.ExeSuffix}"); var command = new RunExeCommand(Log, outputProgram); command.Execute() .Should() .Pass() .And .HaveStdOutContaining("Hello World"); }
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" }; 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.dll"); outputFiles.Add("AllResourcesInSatellite.deps.json"); outputFiles.Add("AllResourcesInSatellite.runtimeconfig.json"); outputFiles.Add("AllResourcesInSatellite.runtimeconfig.dev.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_appends_rid_to_outdir_correctly(string identifier, string rid, bool useAppendOption, bool shouldAppend) { foreach (bool multiTarget in new[] { false, true }) { var testAsset = _testAssetsManager .CopyTestAsset("DesktopMinusRid", identifier: Path.DirectorySeparatorChar + identifier + (multiTarget ? "Multi" : "")) .WithSource() .WithProjectChanges(project => { var ns = project.Root.Name.Namespace; var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); propertyGroup.Add(new XElement(ns + "RuntimeIdentifier", rid)); propertyGroup.Add(new XElement(ns + "AppendRuntimeIdentifierToOutputPath", useAppendOption.ToString())); if (multiTarget) { propertyGroup.Element(ns + "RuntimeIdentifier").Add(new XAttribute("Condition", "'$(TargetFramework)' == 'net46'")); propertyGroup.Element(ns + "TargetFramework").Remove(); propertyGroup.Add(new XElement(ns + "TargetFrameworks", "net46;netcoreapp1.1")); } }); var buildCommand = new BuildCommand(testAsset); buildCommand .Execute() .Should() .Pass(); var publishCommand = new PublishCommand(testAsset); publishCommand .Execute(multiTarget ? new[] { "/p:TargetFramework=net46" } : Array.Empty <string>()) .Should() .Pass(); string expectedOutput; switch (rid) { case "": expectedOutput = "Native code was not used (MSIL)"; break; case "win7-x86": expectedOutput = "Native code was not used (X86)"; break; case "win7-x64": expectedOutput = "Native code was not used (Amd64)"; break; default: throw new ArgumentOutOfRangeException(nameof(rid)); } var outputDirectory = buildCommand.GetOutputDirectory("net46", runtimeIdentifier: shouldAppend ? rid : ""); var publishDirectory = publishCommand.GetOutputDirectory("net46", runtimeIdentifier: rid); foreach (var directory in new[] { outputDirectory, publishDirectory }) { var exe = Path.Combine(directory.FullName, "DesktopMinusRid.exe"); var runCommand = new RunExeCommand(Log, exe); runCommand .Execute() .Should() .Pass() .And .HaveStdOutContaining(expectedOutput); } } }
public void Constructor_adds_options(string optionName, RunExeCommand sut) { Assert.That(sut.Options, Has.Exactly(1).InstanceOf <Option <string> >().With.Property(nameof(Option.Name)).EqualTo(optionName)); }
void Conflicts_are_resolved_when_publishing(bool selfContained, bool ridSpecific, [CallerMemberName] string callingMethod = "") { if (selfContained && !ridSpecific) { throw new ArgumentException("Self-contained apps must be rid specific"); } var targetFramework = "netcoreapp2.0"; if (!EnvironmentInfo.SupportsTargetFramework(targetFramework)) { return; } var rid = ridSpecific ? EnvironmentInfo.GetCompatibleRid(targetFramework) : null; TestProject testProject = new TestProject() { Name = selfContained ? "SelfContainedWithConflicts" : (ridSpecific ? "RidSpecificSharedConflicts" : "PortableWithConflicts"), IsSdkProject = true, TargetFrameworks = targetFramework, RuntimeIdentifier = rid, IsExe = true, }; string outputMessage = $"Hello from {testProject.Name}!"; testProject.AdditionalProperties["CopyLocalLockFileAssemblies"] = "true"; testProject.SourceFiles["Program.cs"] = @" using System; public static class Program { public static void Main() { TestConflictResolution(); Console.WriteLine(""" + outputMessage + @"""); } " + ConflictResolutionAssets.ConflictResolutionTestMethod + @" } "; var testProjectInstance = _testAssetsManager.CreateTestProject(testProject, testProject.Name) .WithProjectChanges(p => { var ns = p.Root.Name.Namespace; var itemGroup = new XElement(ns + "ItemGroup"); p.Root.Add(itemGroup); foreach (var dependency in ConflictResolutionAssets.ConflictResolutionDependencies) { itemGroup.Add(new XElement(ns + "PackageReference", new XAttribute("Include", dependency.Item1), new XAttribute("Version", dependency.Item2))); } if (!selfContained && ridSpecific) { var propertyGroup = new XElement(ns + "PropertyGroup"); p.Root.Add(propertyGroup); propertyGroup.Add(new XElement(ns + "SelfContained", "false")); } }) .Restore(Log, testProject.Name); var publishCommand = new PublishCommand(Log, Path.Combine(testProjectInstance.TestRoot, testProject.Name)); var publishResult = publishCommand.Execute(); publishResult.Should().Pass(); var publishDirectory = publishCommand.GetOutputDirectory( targetFramework: targetFramework, runtimeIdentifier: rid ?? string.Empty); var outputDirectory = publishDirectory.Parent; DependencyContext dependencyContext; using (var depsJsonFileStream = File.OpenRead(Path.Combine(publishDirectory.FullName, $"{testProject.Name}.deps.json"))) { dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream); } dependencyContext.Should() .HaveNoDuplicateRuntimeAssemblies(rid ?? "") .And .HaveNoDuplicateNativeAssets(rid ?? "") .And .OnlyHavePackagesWithPathProperties(); TestCommand runCommand; if (selfContained) { var selfContainedExecutable = testProject.Name + Constants.ExeSuffix; string selfContainedExecutableFullPath = Path.Combine(publishDirectory.FullName, selfContainedExecutable); var libPrefix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "" : "lib"; var filesPublished = new[] { selfContainedExecutable, $"{testProject.Name}.dll", $"{testProject.Name}.pdb", $"{testProject.Name}.deps.json", $"{testProject.Name}.runtimeconfig.json", $"{libPrefix}coreclr{FileConstants.DynamicLibSuffix}", $"{libPrefix}hostfxr{FileConstants.DynamicLibSuffix}", $"{libPrefix}hostpolicy{FileConstants.DynamicLibSuffix}", $"mscorlib.dll", $"System.Private.CoreLib.dll", }; outputDirectory.Should().HaveFiles(filesPublished); publishDirectory.Should().HaveFiles(filesPublished); dependencyContext.Should() .OnlyHaveRuntimeAssembliesWhichAreInFolder(rid, publishDirectory.FullName) .And .OnlyHaveNativeAssembliesWhichAreInFolder(rid, publishDirectory.FullName, testProject.Name); runCommand = new RunExeCommand(Log, selfContainedExecutableFullPath); } else { var filesPublished = new[] { $"{testProject.Name}.dll", $"{testProject.Name}.pdb", $"{testProject.Name}.deps.json", $"{testProject.Name}.runtimeconfig.json" }; outputDirectory.Should().HaveFiles(filesPublished); publishDirectory.Should().HaveFiles(filesPublished); dependencyContext.Should() .OnlyHaveRuntimeAssemblies(rid ?? "", testProject.Name); runCommand = new DotnetCommand(Log, Path.Combine(publishDirectory.FullName, $"{testProject.Name}.dll")); } runCommand .Execute() .Should() .Pass() .And .HaveStdOutContaining(outputMessage); }
public void COMReferenceBuildsAndRuns(bool embedInteropTypes) { var targetFramework = "netcoreapp3.0"; var testProject = new TestProject { Name = "UseMediaPlayer", IsSdkProject = true, TargetFrameworks = targetFramework, IsExe = true, SourceFiles = { ["Program.cs"] = @" using MediaPlayer; class Program { static void Main(string[] args) { var mediaPlayer = (IMediaPlayer2)new MediaPlayerClass(); } } ", } }; if (embedInteropTypes) { testProject.SourceFiles.Add("MediaPlayerClass.cs", @" using System.Runtime.InteropServices; namespace MediaPlayer { [ComImport] [Guid(""22D6F312-B0F6-11D0-94AB-0080C74C7E95"")] class MediaPlayerClass { } } "); } var reference = new XElement("ItemGroup", new XElement("COMReference", new XAttribute("Include", "MediaPlayer.dll"), new XElement("Guid", "22d6f304-b0f6-11d0-94ab-0080c74c7e95"), new XElement("VersionMajor", "1"), new XElement("VersionMinor", "0"), new XElement("WrapperTool", "tlbimp"), new XElement("Lcid", "0"), new XElement("Isolated", "false"), new XElement("EmbedInteropTypes", embedInteropTypes))); var testAsset = _testAssetsManager .CreateTestProject(testProject, identifier: embedInteropTypes.ToString()) .WithProjectChanges(doc => doc.Root.Add(reference)); var buildCommand = new BuildCommand(testAsset); buildCommand.Execute().Should().Pass(); var outputDirectory = buildCommand.GetOutputDirectory(targetFramework); var runCommand = new RunExeCommand(Log, outputDirectory.File("UseMediaPlayer.exe").FullName); runCommand.Execute().Should().Pass(); }
public void Constructor_adds_Path_argument(RunExeCommand sut) { Assert.That(sut.Arguments, Has.Exactly(1).InstanceOf <Argument <FileInfo> >().With.Property(nameof(Argument.Name)).EqualTo(nameof(RunCommandArguments.PathToProgram))); }