Skip to content

Commit c6c1ff9

Browse files
Fix tests
Derive the right path for the test application now that the test binary is in a different location.
1 parent 060229c commit c6c1ff9

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

test/OpenTelemetry.Instrumentation.AspNetCore.Tests/OpenTelemetry.Instrumentation.AspNetCore.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@
4040
</EmbeddedResource>
4141
</ItemGroup>
4242

43+
<ItemGroup>
44+
<AssemblyMetadata Include="RouteTestsPath" Value="$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)/RouteTests'))" />
45+
</ItemGroup>
46+
4347
</Project>

test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestFixture.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Globalization;
5+
using System.Reflection;
56
using System.Text;
67
using Microsoft.AspNetCore.Builder;
78
using RouteTests.TestApplication;
@@ -90,8 +91,14 @@ private void GenerateReadme()
9091
sb.AppendLine("```");
9192
}
9293

94+
string routeTestsPath =
95+
typeof(TestApplicationFactory).Assembly
96+
.GetCustomAttributes()
97+
.OfType<AssemblyMetadataAttribute>()
98+
.FirstOrDefault((p) => p.Key is "RouteTestsPath")?.Value ?? ".";
99+
93100
var readmeFileName = $"README.net{Environment.Version.Major}.0.md";
94-
File.WriteAllText(Path.Combine("..", "..", "..", "RouteTests", readmeFileName), sb.ToString());
101+
File.WriteAllText(Path.Combine(routeTestsPath, readmeFileName), sb.ToString());
95102

96103
// Generates a link fragment that should comply with markdownlint rule MD051
97104
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md051.md
@@ -101,8 +108,7 @@ static string GenerateLinkFragment(TestApplicationScenario scenario, string name
101108
.Where(c => (!char.IsPunctuation(c) && c != '`') || c == '-')
102109
.Select(c => c switch
103110
{
104-
'-' => '-',
105-
' ' => '-',
111+
'-' or ' ' => '-',
106112
_ => char.ToLower(c, CultureInfo.InvariantCulture),
107113
})
108114
.ToArray();

test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/TestApplicationFactory.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Diagnostics;
5+
using System.Reflection;
56
using Microsoft.AspNetCore.Builder;
67
using Microsoft.AspNetCore.Diagnostics;
78
using Microsoft.AspNetCore.Http;
@@ -41,8 +42,13 @@ public enum TestApplicationScenario
4142

4243
internal class TestApplicationFactory
4344
{
44-
private static readonly string AspNetCoreTestsPath = new FileInfo(typeof(RoutingTests)!.Assembly!.Location)!.Directory!.Parent!.Parent!.Parent!.FullName;
45-
private static readonly string ContentRootPath = Path.Combine(AspNetCoreTestsPath, "RouteTests", "TestApplication");
45+
private static readonly string RouteTestsPath =
46+
typeof(TestApplicationFactory).Assembly
47+
.GetCustomAttributes()
48+
.OfType<AssemblyMetadataAttribute>()
49+
.FirstOrDefault((p) => p.Key is "RouteTestsPath")?.Value ?? ".";
50+
51+
private static readonly string ContentRootPath = Path.Combine(RouteTestsPath, "TestApplication");
4652

4753
public static WebApplication? CreateApplication(TestApplicationScenario config)
4854
{

0 commit comments

Comments
 (0)