MVC 中的 Application Insight 和来自另一个 C# 测试项目的测试

Application Insight in MVC and testing from another C# Test project

我有一个 MVC 应用程序,应用程序洞察力在该应用程序中运行良好。 ,我们有一个测试 C# class 项目,我从那里调用一个方法,该方法具有触发应用程序洞察事件的代码,但它抛出以下错误。,

Type 'Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector' could not be loaded

我将 MVC applicationInsight.cofig 文件复制到 C# 测试 Web 项目中,并在

中添加了条目
<httpmodules>
    <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpmodules>

应用程序 1 -> 测试项目 C# Class 项目

{

    Appinsight a = new Appinsight();
    a.Function1();
}

MVC 网络应用程序

Class Appinsight
{
  Funciton1()
  {
     TelemetryClient o = new TelemetryClient();
  }
}

如果它无法加载程序集,这意味着当您的测试项目运行时,无法找到某些应用见解 类。您需要确保无论您的测试代码来自 运行,所有部署到该网站的相同程序集也部署到测试代码来自 运行 的任何地方。