public void CanUnzip_WithIncludeAndExcludeFilter() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); TransientTestFolder sub = source.CreateDirectory("sub"); testEnvironment.CreateFile(source, "file1.js", "file1"); testEnvironment.CreateFile(source, "file1.js.map", "file2"); testEnvironment.CreateFile(source, "file2.js", "file3"); testEnvironment.CreateFile(source, "readme.txt", "file4"); testEnvironment.CreateFile(sub, "subfile.js", "File5"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) }, Include = "*.js", Exclude = "*.js.map;sub\\*.js" }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "file1.js"), () => _mockEngine.Log); _mockEngine.Log.ShouldNotContain(Path.Combine(destination.Path, "file1.js.map"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "file2.js"), () => _mockEngine.Log); _mockEngine.Log.ShouldNotContain(Path.Combine(destination.Path, "readme.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldNotContain(Path.Combine(destination.Path, "sub", "subfile.js"), () => _mockEngine.Log); } }
public void LogsErrorIfExcludeContainsPropertyReferences() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); testEnvironment.CreateFile(source, "BE78A17D30144B549D21F71D5C633F7D.txt", "file1"); testEnvironment.CreateFile(source, "A04FF4B88DF14860B7C73A8E75A4FB76.txt", "file2"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) }, Exclude = "$(Include)" }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3938", () => _mockEngine.Log); } }
public void LogsErrorIfReadOnlyFileCannotBeOverwitten() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); TransientTestFile file1 = testEnvironment.CreateFile(source, "D6DFD219DACE48F8B86EFCDF98433333.txt", "file1"); new FileInfo(file1.Path).IsReadOnly = true; TransientZipArchive zipArchive = TransientZipArchive.Create(source, destination); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(source.Path), OverwriteReadOnlyFiles = false, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain($"D6DFD219DACE48F8B86EFCDF98433333.txt{ (NativeMethodsShared.IsMono ? "\"" : "'") } is denied", () => _mockEngine.Log); } }
public void CanOverwriteReadOnlyFile() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); TransientTestFile file1 = testEnvironment.CreateFile(source, "638AF4AE88A146E09CB69FE1CA7083DC.txt", "file1"); new FileInfo(file1.Path).IsReadOnly = true; TransientZipArchive zipArchive = TransientZipArchive.Create(source, destination); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(source.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("638AF4AE88A146E09CB69FE1CA7083DC", () => _mockEngine.Log); } }
public void CanUnzip_ExplicitDirectoryEntries() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); testEnvironment.CreateFile(source, "BE78A17D30144B549D21F71D5C633F7D.txt", "file1"); testEnvironment.CreateFile(source, "A04FF4B88DF14860B7C73A8E75A4FB76.txt", "file2"); TransientTestFolder emptyDir = source.CreateDirectory("emptyDir"); TransientTestFolder subDir = source.CreateDirectory("subDir"); subDir.CreateFile("F83E9633685494E53BEF3794EDEEE6A6.txt", "file3"); subDir.CreateFile("21D6D4596067723B3AC5DF9A8B3CBFE7.txt", "file4"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "BE78A17D30144B549D21F71D5C633F7D.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "A04FF4B88DF14860B7C73A8E75A4FB76.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "subdir", "F83E9633685494E53BEF3794EDEEE6A6.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "subdir", "21D6D4596067723B3AC5DF9A8B3CBFE7.txt"), () => _mockEngine.Log); Directory.Exists(Path.Combine(destination.Path, "emptyDir")); } }
public void TestOldNuget() { string msbuildExePath = Path.GetDirectoryName(RunnerUtilities.PathToCurrentlyRunningMsBuildExe); using TestEnvironment testEnvironment = TestEnvironment.Create(); TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: true); // The content of the solution isn't known to matter, but having a custom solution makes it easier to add requirements should they become evident. TransientTestFile sln = testEnvironment.CreateFile(folder, "test.sln", @" Microsoft Visual Studio Solution File, Format Version 12.00 \# Visual Studio 15 VisualStudioVersion = 15.0.26124.0 MinimumVisualStudioVersion = 15.0.26124.0 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal "); RunnerUtilities.RunProcessAndGetOutput(Path.Combine(msbuildExePath, "nuget", "NuGet.exe"), "restore " + sln.Path + " -MSBuildPath \"" + msbuildExePath + "\"", out bool success, outputHelper: _output); success.ShouldBeTrue(); }
public void SkipUnchangedFiles() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: true); DownloadFile downloadFile = new DownloadFile { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(folder.Path), HttpMessageHandler = new MockHttpMessageHandler((message, token) => new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("C197675A3CC64CAA80680128CF4578C9") { Headers = { LastModified = DateTimeOffset.UtcNow.AddDays(-1) } }, RequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://success/foo.txt") }), SkipUnchangedFiles = true, SourceUrl = "http://success/foo.txt" }; testEnvironment.CreateFile(folder, "foo.txt", "C197675A3CC64CAA80680128CF4578C9"); downloadFile.Execute().ShouldBeTrue(); _mockEngine.Log.ShouldContain("Did not download file from \"http://success/foo.txt\"", () => _mockEngine.Log); } }
public void CanBeCanceled() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: true); DownloadFile downloadFile = new DownloadFile { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(folder.Path), HttpMessageHandler = new MockHttpMessageHandler((message, token) => new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(new String('!', 10000000)), RequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://largedownload/foo.txt") }), SourceUrl = "http://largedownload/foo.txt" }; Task <bool> task = Task.Run(() => downloadFile.Execute()); downloadFile.Cancel(); task.Wait(TimeSpan.FromSeconds(1)).ShouldBeTrue(); task.Result.ShouldBeFalse(); } }
public void CanDownloadToFolder() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: false); DownloadFile downloadFile = new DownloadFile { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(folder.Path), HttpMessageHandler = new MockHttpMessageHandler((message, token) => new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("Success!"), RequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://success/foo.txt") }), SourceUrl = "http://success/foo.txt" }; downloadFile.Execute().ShouldBeTrue(); FileInfo file = new FileInfo(Path.Combine(folder.Path, "foo.txt")); file.Exists.ShouldBeTrue(() => file.FullName); File.ReadAllText(file.FullName).ShouldBe("Success!"); downloadFile.DownloadedFile.ItemSpec.ShouldBe(file.FullName); } }
public void CanUnzip() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); testEnvironment.CreateFile(source, "BE78A17D30144B549D21F71D5C633F7D.txt", "file1"); testEnvironment.CreateFile(source, "A04FF4B88DF14860B7C73A8E75A4FB76.txt", "file2"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "BE78A17D30144B549D21F71D5C633F7D.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "A04FF4B88DF14860B7C73A8E75A4FB76.txt"), () => _mockEngine.Log); } }
public void ParseSolutionFilter() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder src = testEnvironment.CreateFolder(Path.Combine(folder.Path, "src"), createFolder: true); TransientTestFile microsoftBuild = testEnvironment.CreateFile(src, "Microsoft.Build.csproj"); TransientTestFile msbuild = testEnvironment.CreateFile(src, "MSBuild.csproj"); TransientTestFile commandLineUnitTests = testEnvironment.CreateFile(src, "Microsoft.Build.CommandLine.UnitTests.csproj"); TransientTestFile tasksUnitTests = testEnvironment.CreateFile(src, "Microsoft.Build.Tasks.UnitTests.csproj"); // The important part of this .sln is that it has references to each of the four projects we just created. TransientTestFile sln = testEnvironment.CreateFile(folder, "Microsoft.Build.Dev.sln", @" Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27004.2009 MinimumVisualStudioVersion = 10.0.40219.1 Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""Microsoft.Build"", """ + Path.Combine("src", Path.GetFileName(microsoftBuild.Path)) + @""", ""{69BE05E2-CBDA-4D27-9733-44E12B0F5627}"" EndProject Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""MSBuild"", """ + Path.Combine("src", Path.GetFileName(msbuild.Path)) + @""", ""{6F92CA55-1D15-4F34-B1FE-56C0B7EB455E}"" EndProject Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""Microsoft.Build.CommandLine.UnitTests"", """ + Path.Combine("src", Path.GetFileName(commandLineUnitTests.Path)) + @""", ""{0ADDBC02-0076-4159-B351-2BF33FAA46B2}"" EndProject Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""Microsoft.Build.Tasks.UnitTests"", """ + Path.Combine("src", Path.GetFileName(tasksUnitTests.Path)) + @""", ""{CF999BDE-02B3-431B-95E6-E88D621D9CBF}"" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection EndGlobal "); TransientTestFile slnf = testEnvironment.CreateFile(folder, "Dev.slnf", @" { ""solution"": { ""path"": """ + sln.Path.Replace("\\", "\\\\") + @""", ""projects"": [ """ + Path.Combine("src", Path.GetFileName(microsoftBuild.Path) !).Replace("\\", "\\\\") + @""", """ + Path.Combine("src", Path.GetFileName(tasksUnitTests.Path) !).Replace("\\", "\\\\") + @""" ] } }"); SolutionFile sp = SolutionFile.Parse(slnf.Path); sp.ProjectShouldBuild(Path.Combine("src", Path.GetFileName(microsoftBuild.Path) !)).ShouldBeTrue(); sp.ProjectShouldBuild(Path.Combine("src", Path.GetFileName(tasksUnitTests.Path) !)).ShouldBeTrue(); (sp.ProjectShouldBuild(Path.Combine("src", Path.GetFileName(commandLineUnitTests.Path) !)) || sp.ProjectShouldBuild(Path.Combine("src", Path.GetFileName(msbuild.Path) !)) || sp.ProjectShouldBuild(Path.Combine("src", "notAProject.csproj"))) .ShouldBeFalse(); } }
public void InlineTaskWithAssembly() { using (TestEnvironment env = TestEnvironment.Create()) { TransientTestFolder folder = env.CreateFolder(createFolder: true); TransientTestFile assemblyProj = env.CreateFile(folder, "5106.csproj", @$ " <Project DefaultTargets=" "Build" "> <PropertyGroup> <TargetFrameworkVersion>{MSBuildConstants.StandardTestTargetFrameworkVersion}</TargetFrameworkVersion>
public void InvalidSolutionFilters(string slnfValue, string exceptionReason) { Assert.False(File.Exists("C:\\notAPath2\\MSBuild.Dev.sln")); using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: true); TransientTestFile sln = testEnvironment.CreateFile(folder, "Dev.sln"); TransientTestFile slnf = testEnvironment.CreateFile(folder, "Dev.slnf", slnfValue.Replace(@"C:\\notAPath\\MSBuild.Dev.sln", sln.Path.Replace("\\", "\\\\"))); InvalidProjectFileException e = Should.Throw <InvalidProjectFileException>(() => SolutionFile.Parse(slnf.Path)); e.HelpKeyword.ShouldBe(exceptionReason); } }
public void EmptyGlobalJson() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(); File.WriteAllText(Path.Combine(folder.FolderPath, GlobalJsonReader.GlobalJsonFileName), " { } "); MockSdkResolverContext context = new MockSdkResolverContext(Path.Combine(folder.FolderPath, "foo.proj")); GlobalJsonReader.GetMSBuildSdkVersions(context).ShouldBeNull(); } }
public void LogsErrorIfSourceFileDoesNotExist() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: false); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(folder.Path), SourceFiles = new ITaskItem[] { new TaskItem(Path.Combine(testEnvironment.DefaultTestDirectory.Path, "foo.zip")), } }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3932", () => _mockEngine.Log); } }
public void CanGetFileNameFromResponseHeader() { const string filename = "C6DDD10A99E149F78FA11F133127BF38.txt"; HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("Success!") { Headers = { ContentDisposition = new ContentDispositionHeaderValue(DispositionTypeNames.Attachment) { FileName = filename } } }, RequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://success/foo.txt") }; using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: false); DownloadFile downloadFile = new DownloadFile { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(folder.Path), DestinationFileName = new TaskItem(filename), HttpMessageHandler = new MockHttpMessageHandler((message, token) => response), SourceUrl = "http://success/foo.txt" }; downloadFile.Execute().ShouldBeTrue(); FileInfo file = new FileInfo(Path.Combine(folder.Path, filename)); file.Exists.ShouldBeTrue(() => file.FullName); File.ReadAllText(file.FullName).ShouldBe("Success!"); downloadFile.DownloadedFile.ItemSpec.ShouldBe(file.FullName); } }
public void LogsErrorIfDestinationExists() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: true); TransientTestFile file = testEnvironment.CreateFile("foo.zip", "foo"); ZipDirectory zipDirectory = new ZipDirectory { BuildEngine = _mockEngine, DestinationFile = new TaskItem(file.Path), SourceDirectory = new TaskItem(folder.Path) }; zipDirectory.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3942", () => _mockEngine.Log); } }
public void LogsErrorIfSourceFileCannotBeOpened() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: false); TransientTestFile file = testEnvironment.CreateFile("foo.txt", "foo"); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(folder.Path), SourceFiles = new ITaskItem[] { new TaskItem(file.Path), } }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3933", () => _mockEngine.Log); } }
public void CanOvewriteExistingFile() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder sourceFolder = testEnvironment.CreateFolder(createFolder: true); testEnvironment.CreateFile(sourceFolder, "F1C22D660B0D4DAAA296C1B980320B03.txt", "F1C22D660B0D4DAAA296C1B980320B03"); testEnvironment.CreateFile(sourceFolder, "AA825D1CB154492BAA58E1002CE1DFEB.txt", "AA825D1CB154492BAA58E1002CE1DFEB"); TransientTestFile file = testEnvironment.CreateFile(testEnvironment.DefaultTestDirectory, "test.zip", contents: "test"); ZipDirectory zipDirectory = new ZipDirectory { BuildEngine = _mockEngine, DestinationFile = new TaskItem(file.Path), Overwrite = true, SourceDirectory = new TaskItem(sourceFolder.Path) }; zipDirectory.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain(sourceFolder.Path, () => _mockEngine.Log); _mockEngine.Log.ShouldContain(file.Path, () => _mockEngine.Log); using (FileStream stream = new FileStream(file.Path, FileMode.Open, FileAccess.Read, FileShare.Read)) using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Read)) { archive.Entries .Select(i => i.FullName) .ToList() .ShouldBe( new List <string> { "F1C22D660B0D4DAAA296C1B980320B03.txt", "AA825D1CB154492BAA58E1002CE1DFEB.txt" }, ignoreOrder: true); } } }
public void CanZipDirectory() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder sourceFolder = testEnvironment.CreateFolder(createFolder: true); testEnvironment.CreateFile(sourceFolder, "6DE6060259C44DB6B145159376751C22.txt", "6DE6060259C44DB6B145159376751C22"); testEnvironment.CreateFile(sourceFolder, "CDA3DD8C25A54A7CAC638A444CB1EAD0.txt", "CDA3DD8C25A54A7CAC638A444CB1EAD0"); string zipFilePath = Path.Combine(testEnvironment.CreateFolder(createFolder: true).Path, "test.zip"); ZipDirectory zipDirectory = new ZipDirectory { BuildEngine = _mockEngine, DestinationFile = new TaskItem(zipFilePath), SourceDirectory = new TaskItem(sourceFolder.Path) }; zipDirectory.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain(sourceFolder.Path, () => _mockEngine.Log); _mockEngine.Log.ShouldContain(zipFilePath, () => _mockEngine.Log); using (FileStream stream = new FileStream(zipFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Read)) { archive.Entries .Select(i => i.FullName) .ToList() .ShouldBe( new List <string> { "6DE6060259C44DB6B145159376751C22.txt", "CDA3DD8C25A54A7CAC638A444CB1EAD0.txt" }, ignoreOrder: true); } } }
public void InlineTaskWithAssemblyPlatformAgnostic() { using (TestEnvironment env = TestEnvironment.Create()) { TransientTestFolder folder = env.CreateFolder(createFolder: true); string location = Assembly.GetExecutingAssembly().Location; TransientTestFile inlineTask = env.CreateFile(folder, "5106.proj", @$ " <Project> <UsingTask TaskName=" "MyInlineTask" " TaskFactory=" "RoslynCodeTaskFactory" " AssemblyFile=" "$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" "> <Task> <Reference Include=" "" + Path.Combine(Path.GetDirectoryName(location), "..", "..", "..", "Samples", "Dependency", #if DEBUG "Debug" #else "Release" #endif , "net472", "Dependency.dll") + @""" /> <Using Namespace=""Dependency"" /> <Code Type=""Fragment"" Language=""cs"" > <![CDATA[ Log.LogError(Alpha.GetString()); ]]> </Code> </Task> </UsingTask> <Target Name=""ToRun""> <MyInlineTask/> </Target> </Project> "); string output = RunnerUtilities.ExecMSBuild(inlineTask.Path, out bool success); success.ShouldBeTrue(output); output.ShouldContain("Alpha.GetString"); } }
public void RetryOnDownloadError() { const string content = "Foo"; bool hasThrown = false; using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: false); DownloadFile downloadFile = new DownloadFile() { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(folder.Path), HttpMessageHandler = new MockHttpMessageHandler((message, token) => new HttpResponseMessage(HttpStatusCode.OK) { Content = new MockHttpContent(content.Length, stream => { if (!hasThrown) { hasThrown = true; throw new WebException("Error", WebExceptionStatus.ReceiveFailure); } return(new MemoryStream(Encoding.Unicode.GetBytes(content)).CopyToAsync(stream)); }), RequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://success/foo.txt") }), Retries = 1, RetryDelayMilliseconds = 100, SourceUrl = "http://success/foo.txt" }; downloadFile.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3924", () => _mockEngine.Log); } }
public void SolutionFilterFiltersProjects(bool graphBuild) { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder classLibFolder = testEnvironment.CreateFolder(Path.Combine(folder.Path, "ClassLibrary"), createFolder: true); TransientTestFolder classLibSubFolder = testEnvironment.CreateFolder(Path.Combine(classLibFolder.Path, "ClassLibrary"), createFolder: true); TransientTestFile classLibrary = testEnvironment.CreateFile(classLibSubFolder, "ClassLibrary.csproj", @"<Project> <Target Name=""ClassLibraryTarget""> <Message Text=""ClassLibraryBuilt""/> </Target> </Project> "); TransientTestFolder simpleProjectFolder = testEnvironment.CreateFolder(Path.Combine(folder.Path, "SimpleProject"), createFolder: true); TransientTestFolder simpleProjectSubFolder = testEnvironment.CreateFolder(Path.Combine(simpleProjectFolder.Path, "SimpleProject"), createFolder: true); TransientTestFile simpleProject = testEnvironment.CreateFile(simpleProjectSubFolder, "SimpleProject.csproj", @"<Project DefaultTargets=""SimpleProjectTarget""> <Target Name=""SimpleProjectTarget""> <Message Text=""SimpleProjectBuilt""/> </Target> </Project> "); // Slashes here (and in the .slnf) are hardcoded as backslashes intentionally to support the common case. TransientTestFile solutionFile = testEnvironment.CreateFile(simpleProjectFolder, "SimpleProject.sln", @" Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29326.124 MinimumVisualStudioVersion = 10.0.40219.1 Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""SimpleProject"", ""SimpleProject\SimpleProject.csproj"", ""{79B5EBA6-5D27-4976-BC31-14422245A59A}"" EndProject Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""ClassLibrary"", ""..\ClassLibrary\ClassLibrary\ClassLibrary.csproj"", ""{8EFCCA22-9D51-4268-90F7-A595E11FCB2D}"" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {79B5EBA6-5D27-4976-BC31-14422245A59A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {79B5EBA6-5D27-4976-BC31-14422245A59A}.Debug|Any CPU.Build.0 = Debug|Any CPU {79B5EBA6-5D27-4976-BC31-14422245A59A}.Release|Any CPU.ActiveCfg = Release|Any CPU {79B5EBA6-5D27-4976-BC31-14422245A59A}.Release|Any CPU.Build.0 = Release|Any CPU {8EFCCA22-9D51-4268-90F7-A595E11FCB2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8EFCCA22-9D51-4268-90F7-A595E11FCB2D}.Debug|Any CPU.Build.0 = Debug|Any CPU {8EFCCA22-9D51-4268-90F7-A595E11FCB2D}.Release|Any CPU.ActiveCfg = Release|Any CPU {8EFCCA22-9D51-4268-90F7-A595E11FCB2D}.Release|Any CPU.Build.0 = Release|Any CPU {06A4DD1B-5027-41EF-B72F-F586A5A83EA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {06A4DD1B-5027-41EF-B72F-F586A5A83EA5}.Debug|Any CPU.Build.0 = Debug|Any CPU {06A4DD1B-5027-41EF-B72F-F586A5A83EA5}.Release|Any CPU.ActiveCfg = Release|Any CPU {06A4DD1B-5027-41EF-B72F-F586A5A83EA5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {DE7234EC-0C4D-4070-B66A-DCF1B4F0CFEF} EndGlobalSection EndGlobal "); TransientTestFile filterFile = testEnvironment.CreateFile(folder, "solutionFilter.slnf", @" { ""solution"": { // I'm a comment ""path"": "".\\SimpleProject\\SimpleProject.sln"", ""projects"": [ /* ""..\\ClassLibrary\\ClassLibrary\\ClassLibrary.csproj"", */ ""SimpleProject\\SimpleProject.csproj"", ] } } "); Directory.GetCurrentDirectory().ShouldNotBe(Path.GetDirectoryName(filterFile.Path)); if (graphBuild) { ProjectCollection projectCollection = testEnvironment.CreateProjectCollection().Collection; MockLogger logger = new(); projectCollection.RegisterLogger(logger); ProjectGraphEntryPoint entryPoint = new(filterFile.Path, new Dictionary <string, string>()); // We only need to construct the graph, since that tells us what would build if we were to build it. ProjectGraph graphFromSolution = new(entryPoint, projectCollection); logger.AssertNoErrors(); graphFromSolution.ProjectNodes.ShouldHaveSingleItem(); graphFromSolution.ProjectNodes.Single().ProjectInstance.ProjectFileLocation.LocationString.ShouldBe(simpleProject.Path); } else { SolutionFile solution = SolutionFile.Parse(filterFile.Path); ILoggingService mockLogger = CreateMockLoggingService(); ProjectInstance[] instances = SolutionProjectGenerator.Generate(solution, null, null, _buildEventContext, mockLogger); instances.ShouldHaveSingleItem(); // Check that dependencies are built, and non-dependencies in the .sln are not. MockLogger logger = new(output); instances[0].Build(targets: null, new List <ILogger> { logger }).ShouldBeTrue(); logger.AssertLogContains(new string[] { "SimpleProjectBuilt" }); logger.AssertLogDoesntContain("ClassLibraryBuilt"); } } }