Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zijchen committed Aug 5, 2024
1 parent 7987621 commit 03f5f74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
21 changes: 14 additions & 7 deletions test/Microsoft.Build.Sql.Tests/DotnetTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,15 +40,20 @@ protected string CurrentTestDataDirectory
public void TestSetup()
{
EnvironmentSetup();

RunGenericDotnetCommand($"nuget list source", out _, out _);
}

[TearDown]
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))
{
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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,
Expand Down Expand Up @@ -218,8 +227,6 @@ private int RunProcessWithOutputRedirect(ProcessStartInfo startInfo, out string
stdError = threadShared_ReceivedErrors.ToString();
}

Console.WriteLine(stdOutput);

return dotnet.ExitCode;
}

Expand Down
6 changes: 0 additions & 6 deletions test/Microsoft.Build.Sql.Tests/Template/nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@
<!-- Overrides default Nuget cache folder to make sure we are using the correct package. -->
<add key="globalPackagesFolder" value="./pkg/cache" />
</config>
<packageSources>
<clear />
<!-- only 1 feed is allowed. Add new feeds as upstream sources to sqlds_ssms in ADO -->
<add key="SQLDS-SSMS" value="https://msdata.pkgs.visualstudio.com/DefaultCollection/_packaging/SQLDS_SSMS/nuget/v3/index.json" />
<add key="local" value="./pkg" />
</packageSources>
</configuration>

0 comments on commit 03f5f74

Please sign in to comment.