Skip to content

Commit

Permalink
Merge pull request #1572 from nunit/port-1488
Browse files Browse the repository at this point in the history
Port issue 1488 to V4
  • Loading branch information
CharliePoole authored Dec 28, 2024
2 parents 0d536b0 + 21e5ff5 commit acef844
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
17 changes: 8 additions & 9 deletions package-tests.cake
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,11 @@ AddToBothLists(new PackageTest(
}
}));

// TODO: Bug fixed in V3 not yet ported
//StandardRunnerTests.Add(new PackageTest(
// 1, "AppContextBaseDirectory_NET80",
// "Test Setting the BaseDirectory to match test assembly location under .NET 8.0",
// "testdata/net8.0/AppContextTest.dll",
// new ExpectedResult("Passed")
// {
// Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("AppContextTest.dll", "netcore-8.0") }
// }));
StandardRunnerTests.Add(new PackageTest(
1, "AppContextBaseDirectory_NET80",
"Test Setting the BaseDirectory to match test assembly location under .NET 8.0",
"testdata/net8.0/AppContextTest.dll",
new ExpectedResult("Passed")
{
Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("AppContextTest.dll", "netcore-8.0") }
}));
21 changes: 21 additions & 0 deletions src/NUnitEngine/nunit.engine.core.tests/AppContextTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

using System;
using System.IO;
using NUnit.Framework;

namespace NUnit.Engine.Core.Tests
{
public class AppContextTest
{
[Test]
public void VerifyBasePath()
{
var expectedPath = Path.GetDirectoryName(GetType().Assembly.Location);
#if NETCORAPP
Assert.That(AppContext.GetData("APP_CONTEXT_BASE_DIRECTORY"), Is.EqualTo(expectedPath));
#endif
Assert.That(AppContext.BaseDirectory, Is.SamePath(expectedPath));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public TestAssemblyLoadContext(string testAssemblyPath)
_resolver = new TestAssemblyResolver(this, testAssemblyPath);
_basePath = Path.GetDirectoryName(testAssemblyPath);
_runtimeResolver = new AssemblyDependencyResolver(testAssemblyPath);
#if NET8_0_OR_GREATER
AppContext.SetData("APP_CONTEXT_BASE_DIRECTORY", _basePath);
#endif
}

protected override Assembly Load(AssemblyName name)
Expand Down

0 comments on commit acef844

Please sign in to comment.