From 03f5f7420b1245deb647eb1b8765ff19337f53ea Mon Sep 17 00:00:00 2001 From: "Zi Chen (from Dev Box)" Date: Mon, 5 Aug 2024 13:15:38 -0700 Subject: [PATCH] Cleanup --- .../DotnetTestBase.cs | 21 ++++++++++++------- .../Template/nuget.config | 6 ------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/test/Microsoft.Build.Sql.Tests/DotnetTestBase.cs b/test/Microsoft.Build.Sql.Tests/DotnetTestBase.cs index bb54929..12bb3ae 100644 --- a/test/Microsoft.Build.Sql.Tests/DotnetTestBase.cs +++ b/test/Microsoft.Build.Sql.Tests/DotnetTestBase.cs @@ -5,7 +5,6 @@ using System.Diagnostics; using System.IO; using System.Text; -using Microsoft.Isam.Esent.Interop; using Microsoft.SqlServer.Dac; using NUnit.Framework; using NUnit.Framework.Interfaces; @@ -41,8 +40,6 @@ protected string CurrentTestDataDirectory public void TestSetup() { EnvironmentSetup(); - - RunGenericDotnetCommand($"nuget list source", out _, out _); } [TearDown] @@ -50,6 +47,13 @@ public void TestTearDown() { try { + // Remove local nuget source + RunGenericDotnetCommand($"nuget remove source TestSource_{TestContext.CurrentContext.Test.Name}", out _, out string stdError); + if (!string.IsNullOrEmpty(stdError)) + { + Assert.Warn("Failed to remove local nuget source: " + stdError); + } + // Delete working directory unless test failed if (TestContext.CurrentContext.Result.Outcome == ResultState.Success && Directory.Exists(this.WorkingDirectory)) { @@ -81,7 +85,8 @@ protected void EnvironmentSetup() } // Copy SDK nuget package to Workingdirectory/pkg/ - TestUtils.CopyDirectoryRecursive("../../../pkg", Path.Combine(this.WorkingDirectory, "pkg")); + string localNugetSource = Path.Combine(this.WorkingDirectory, "pkg"); + TestUtils.CopyDirectoryRecursive("../../../pkg", localNugetSource); // Copy common project files from Template to WorkingDirectory TestUtils.CopyDirectoryRecursive("../../../Template", this.WorkingDirectory); @@ -91,6 +96,10 @@ protected void EnvironmentSetup() { TestUtils.CopyDirectoryRecursive(this.CurrentTestDataDirectory, this.WorkingDirectory); } + + // Add pkg folder as a nuget source + RunGenericDotnetCommand($"nuget add source \"{localNugetSource}\" --name TestSource_{TestContext.CurrentContext.Test.Name}", out _, out string stdError); + Assert.AreEqual("", stdError, "Failed to add local nuget source: " + stdError); } /// @@ -103,7 +112,7 @@ protected int RunGenericDotnetCommand(string dotnetCommandWithArgs, out string s ProcessStartInfo dotnetStartInfo = new ProcessStartInfo { FileName = TestUtils.GetDotnetPath(), - Arguments = $"{dotnetCommandWithArgs} --configfile nuget.config", + Arguments = $"{dotnetCommandWithArgs}", WorkingDirectory = this.WorkingDirectory, WindowStyle = ProcessWindowStyle.Hidden, RedirectStandardOutput = true, @@ -218,8 +227,6 @@ private int RunProcessWithOutputRedirect(ProcessStartInfo startInfo, out string stdError = threadShared_ReceivedErrors.ToString(); } - Console.WriteLine(stdOutput); - return dotnet.ExitCode; } diff --git a/test/Microsoft.Build.Sql.Tests/Template/nuget.config b/test/Microsoft.Build.Sql.Tests/Template/nuget.config index 4ac3b69..9f550ad 100644 --- a/test/Microsoft.Build.Sql.Tests/Template/nuget.config +++ b/test/Microsoft.Build.Sql.Tests/Template/nuget.config @@ -5,10 +5,4 @@ - - - - - - \ No newline at end of file