-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathCustomWebApplicationFactory.cs
More file actions
52 lines (46 loc) · 2.15 KB
/
CustomWebApplicationFactory.cs
File metadata and controls
52 lines (46 loc) · 2.15 KB
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
using System.Diagnostics;
using Azure.Core.Pipeline;
using Azure.Monitor.OpenTelemetry.Exporter;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace IntegrationTests.Tests
{
public class CustomWebApplicationFactory<TStartup>
: WebApplicationFactory<TStartup> where TStartup : class
{
internal TelemetryCollector Telemetry { get; } = new TelemetryCollector();
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
Activity.ForceDefaultIdFormat = true;
builder.ConfigureServices(services =>
{
services.AddLogging(loggingBuilder =>
loggingBuilder.AddFilter(
"Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager",
LogLevel.None)
.AddFilter(
"IntegrationTests.WebApp.Controllers.HomeController",
LogLevel.Warning));
services.AddSingleton<TelemetryCollector>(_ => this.Telemetry);
services.AddSingleton<HttpPipelineTransport>(provider =>
new RecordingTransport(provider.GetRequiredService<TelemetryCollector>()));
services.AddOptions<AzureMonitorExporterOptions>()
.Configure<HttpPipelineTransport>((options, transport) =>
{
options.Transport = transport;
options.DisableOfflineStorage = true;
});
services.AddApplicationInsightsTelemetry(options =>
{
options.AddAutoCollectedMetricExtractor = false;
options.EnableQuickPulseMetricStream = false;
options.ConnectionString = "InstrumentationKey=ikey";
options.SamplingRatio = 1.0f; // 100% telemetry flow in tests
});
});
}
}
}