【发布时间】:2021-09-18 08:35:03
【问题描述】:
我一直在网上寻找一种方法来对我的处理器和初始化程序进行单元测试。到目前为止,我从另一篇文章中获得了以下代码设置,但我对如何进行有点迷茫。
public class TelemetryClientTests
{
private TelemetryClient telemetryClient;
private List<ITelemetry> sendItems;
[TestInitialize]
public void TestInit()
{
var httpContext = Substitute.For<IHttpContextAccessor>();
var configuration = new TelemetryConfiguration();
//this.sendItems = new List<ITelemetry>();
configuration.TelemetryChannel = new RequeteTelemtry();
configuration.InstrumentationKey = Guid.NewGuid().ToString();
configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
this.telemetryClient = new TelemetryClient(configuration);
}
/// <summary>
/// Ensure that context being propagated via async/await.
/// </summary>
[TestMethod]
public void ContextPropogatesThruAsyncAwait()
{
var task = this.TestAsync();
task.Wait();
}
}
我不确定应该在哪里添加远程处理器,以便 Application Inisight 知道我正在对其进行单元测试。如果有人知道怎么做,将不胜感激。
【问题讨论】:
标签: unit-testing azure-application-insights open-telemetry