Skip to content

Commit

Permalink
Reorganize files
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwest committed Nov 2, 2023
1 parent d501cd7 commit 2caf83c
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="RouteTests\testcases.json">
<LogicalName>RouteTests.testcases.json</LogicalName>
<EmbeddedResource Include="RouteTests\RoutingTestCases.json">
<LogicalName>RoutingTestCases.json</LogicalName>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="RouteTestData.cs" company="OpenTelemetry Authors">
// <copyright file="RoutingTestCases.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,16 +19,17 @@
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using RouteTests.TestApplication;

namespace RouteTests;

public static class RouteTestData
public static class RoutingTestCases
{
public static IEnumerable<object[]> GetTestCases()
{
var assembly = Assembly.GetExecutingAssembly();
var input = JsonSerializer.Deserialize<RouteTestCase[]>(
assembly.GetManifestResourceStream("RouteTests.testcases.json")!,
var input = JsonSerializer.Deserialize<TestCase[]>(
assembly.GetManifestResourceStream("RoutingTestCases.json")!,
new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Expand All @@ -37,7 +38,7 @@ public static IEnumerable<object[]> GetTestCases()
return GetArgumentsFromTestCaseObject(input!);
}

private static IEnumerable<object[]> GetArgumentsFromTestCaseObject(IEnumerable<RouteTestCase> input)
private static IEnumerable<object[]> GetArgumentsFromTestCaseObject(IEnumerable<TestCase> input)
{
var result = new List<object[]>();

Expand All @@ -55,7 +56,7 @@ private static IEnumerable<object[]> GetArgumentsFromTestCaseObject(IEnumerable<
return result;
}

public class RouteTestCase
public class TestCase
{
public string Name { get; set; } = string.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Text;
using System.Text.Json;
using Microsoft.AspNetCore.Builder;
using RouteTests.TestApplication;

namespace RouteTests;

Expand All @@ -27,7 +28,7 @@ public class RoutingTestFixture : IDisposable
private readonly Dictionary<TestApplicationScenario, WebApplication> apps = new();
private readonly HttpClient client = new();
private readonly RouteInfoDiagnosticObserver diagnostics = new();
private readonly List<TestResult> testResults = new();
private readonly List<RoutingTestResult> testResults = new();

public RoutingTestFixture()
{
Expand All @@ -54,7 +55,7 @@ public async Task MakeRequest(TestApplicationScenario scenario, string path)
await this.client.GetAsync(url).ConfigureAwait(false);
}

public void AddTestResult(TestResult testResult)
public void AddTestResult(RoutingTestResult testResult)
{
var app = this.apps[testResult.TestCase.TestApplicationScenario];
var baseUrl = app.Urls.First();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="TestResult.cs" company="OpenTelemetry Authors">
// <copyright file="RoutingTestResult.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,10 +18,11 @@

using System.Text.Json;
using System.Text.Json.Serialization;
using RouteTests.TestApplication;

namespace RouteTests;

public class TestResult
public class RoutingTestResult
{
private static readonly JsonSerializerOptions JsonSerializerOptions = new() { WriteIndented = true };

Expand All @@ -36,7 +37,7 @@ public class TestResult
public RouteInfo RouteInfo { get; set; } = new RouteInfo();

[JsonIgnore]
public RouteTestData.RouteTestCase TestCase { get; set; } = new RouteTestData.RouteTestCase();
public RoutingTestCases.TestCase TestCase { get; set; } = new RoutingTestCases.TestCase();

public override string ToString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public RoutingTests(RoutingTestFixture fixture)
this.fixture = fixture;
}

public static IEnumerable<object[]> TestData => RouteTestData.GetTestCases();
public static IEnumerable<object[]> TestData => RoutingTestCases.GetTestCases();

[Theory]
[MemberData(nameof(TestData))]
public async Task TestRoutes(RouteTestData.RouteTestCase testCase, bool useLegacyConventions)
public async Task TestRoutes(RoutingTestCases.TestCase testCase, bool useLegacyConventions)
{
var previousSetting = Environment.GetEnvironmentVariable("OTEL_SEMCONV_STABILITY_OPT_IN");
Environment.SetEnvironmentVariable("OTEL_SEMCONV_STABILITY_OPT_IN", useLegacyConventions ? null : "http");
Expand Down Expand Up @@ -134,7 +134,7 @@ public async Task TestRoutes(RouteTestData.RouteTestCase testCase, bool useLegac
Assert.Equal(testCase.ExpectedHttpRoute, metricHttpRoute);
}

var testResult = new TestResult
var testResult = new RoutingTestResult
{
IdealHttpRoute = testCase.ExpectedHttpRoute,
ActivityDisplayName = activity.DisplayName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Routing;

namespace RouteTests;
namespace RouteTests.TestApplication;

public class RouteInfo
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Diagnostics;

namespace RouteTests;
namespace RouteTests.TestApplication;

/// <summary>
/// This observer captures all the available route information for a request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using System.Text.Json;
using Microsoft.AspNetCore.Http;

namespace RouteTests;
namespace RouteTests.TestApplication;

public class RouteInfoMiddleware
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;

namespace RouteTests;
namespace RouteTests.TestApplication;

public enum TestApplicationScenario
{
Expand Down Expand Up @@ -52,9 +52,7 @@ public enum TestApplicationScenario
internal class TestApplicationFactory
{
private static readonly string AspNetCoreTestsPath = new FileInfo(typeof(RoutingTests)!.Assembly!.Location)!.Directory!.Parent!.Parent!.Parent!.FullName;
private static readonly string ContentRootPath = AspNetCoreTestsPath.EndsWith("RouteTests")
? AspNetCoreTestsPath
: Path.Combine(AspNetCoreTestsPath, "RouteTests");
private static readonly string ContentRootPath = Path.Combine(AspNetCoreTestsPath, "RouteTests", "TestApplication");

public static WebApplication? CreateApplication(TestApplicationScenario config)
{
Expand Down

0 comments on commit 2caf83c

Please sign in to comment.