-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathOwinIISTests.cs
58 lines (47 loc) · 2.06 KB
/
OwinIISTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NETFRAMEWORK
using System.Net.Http;
using IntegrationTests.Helpers;
using Xunit.Abstractions;
namespace IntegrationTests;
public class OwinIISTests
{
public OwinIISTests(ITestOutputHelper output)
{
Output = output;
}
private ITestOutputHelper Output { get; }
[Fact]
[Trait("Category", "EndToEnd")]
[Trait("Containers", "Windows")]
public async Task SubmitsTraces()
{
Assert.True(EnvironmentTools.IsWindowsAdministrator(), "This test requires Windows Administrator privileges.");
// Using "*" as host requires Administrator. This is needed to make the mock collector endpoint
// accessible to the Windows docker container where the test application is executed by binding
// the endpoint to all network interfaces. In order to do that it is necessary to open the port
// on the firewall.
using var collector = new MockSpansCollector(Output, host: "*");
using var fwPort = FirewallHelper.OpenWinPort(collector.Port, Output);
collector.Expect("OpenTelemetry.Instrumentation.AspNet.Telemetry");
Dictionary<string, string> environmentVariables = new()
{
["OTEL_EXPORTER_OTLP_ENDPOINT"] = $"http://{DockerNetworkHelper.IntegrationTestsGateway}:{collector.Port}"
};
var webPort = TcpPortProvider.GetOpenPort();
await using var container = await IISContainerTestHelper.StartContainerAsync("testapplication-owin-iis-netframework", webPort, environmentVariables, Output);
await CallWebEndpoint(webPort);
collector.AssertExpectations();
}
private async Task CallWebEndpoint(int webPort)
{
var client = new HttpClient();
var response = await client.GetAsync($"http://localhost:{webPort}/test/");
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
var content = await response.Content.ReadAsStringAsync();
Output.WriteLine("Response:");
Output.WriteLine(content);
}
}
#endif