小编Dev*_*Dev的帖子

数据收集器“代码覆盖率”未能提供初始化信息

我正在尝试使用构建管道创建代码覆盖率报告。我Visual Studio code在构建管道中添加了类型任务并启用了代码覆盖率。

当构建被触发时。我越来越 :

Data collector 'Code Coverage' message: Data collector 'Code Coverage' failed to provide initialization information. Error: System.TypeInitializationException: The type initializer for 'Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop' threw an exception. ---> Microsoft.VisualStudio.Diagnostics.Common.InvariantException: Failed to load IntelliTrace Profiler binary or failed to locate functions.
Run Code Online (Sandbox Code Playgroud)

---> System.ComponentModel.Win32Exception: The system cannot find the path specified
Run Code Online (Sandbox Code Playgroud)

这是运行测试并且所有测试都通过了。但是我无法查看代码覆盖率报告。它创建的报告仅包含有关测试的信息

我们在何处指定路径的任何输入都将很有用。

unit-testing code-coverage build azure-pipelines

13
推荐指数
2
解决办法
4876
查看次数

C#调试和发布模式

如何查找是处于调试模式还是发布模式?有没有其他方法可以找到它?

    #if(DEBUG)
{
       Console.WriteLine("Debug mode");
       //Or Things to do in debug mode
}
    #else
{
       Console.WriteLine("Release mode");
       //Or Things to do in Release mode- May be to change the text, image 
}
#endif
Run Code Online (Sandbox Code Playgroud)

c#

4
推荐指数
1
解决办法
5491
查看次数

xml的流利断言

我有一个表单的 xml 文件:

<Level1>
   <Level2>
        <Level3>
             <Level4 attr1 = "123.4" attr2 = ""> </Level4>
        </Level3>
   </Level2>
<Level1> 
Run Code Online (Sandbox Code Playgroud)

我正在使用 XUnit 检查 xml 的结构。

[Fact]
public void Xml_Check()
{
    var doc = XDocument.Load("test.xml");
    doc.Should().HaveRoot("Level1");
    doc.Should().HaveElement("Level2");
    doc.Should().HaveElement("Level3");  //Erroring on this line
}
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:预期 XML 文档<Level1>...</Level1>具有带有子“Level3”的根元素,但未找到此类子元素。它试图将 Level3 视为 Level1 而不是 Level2 的孩子。

如何获取Level3并检查Level4中是否存在某些属性?有没有办法检查属性值的类型?

c# xml unit-testing xunit fluent-assertions

3
推荐指数
1
解决办法
282
查看次数

Polly断路器模式-用于测试连接线

我正在尝试使用Polly测试连接字符串是否为null。如果为空,我想使用CircuitBreaker尝试三遍,并且该消息应该在控制台窗口中输出。

Policy policy = null;

// Break the circuit after the specified number of exceptions
// and keep circuit broken for the specified duration.
policy = Policy
               .Handle<NullReferenceException>()
               .CircuitBreaker(3, TimeSpan.FromSeconds(30)); 
try
   {
     string connected = policy.Execute(() => repository.GetConnectionString());
   }

catch (Exception ex)
      {
         Console.WriteLine("{0}",ex.Message);               
      }     
Run Code Online (Sandbox Code Playgroud)

和GetConnectionString方法是:

public string GetConnectionString()
    {
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = ConfigurationManager.ConnectionStrings["Test1"].ConnectionString;
        return conn.ConnectionString;
    }
Run Code Online (Sandbox Code Playgroud)

为了对此进行测试,我在App.config中更改了连接字符串名称。

但是,它似乎没有处理NullReference Exception。

当我调试应用程序时-它将打开未找到的CircuitBreakerEngine.cs并仅打印“对象引用未设置为对象的实例”。

预期的:从断路异常中打印未将对象引用设置为对象实例三次的消息

c# circuit-breaker polly

1
推荐指数
1
解决办法
4899
查看次数

嵌套在 JSON 对象数组中的 JSON 对象数组

我有一个 JSON 格式的对象数组

var employees = 
[
  {
    "employee1": "employee1",
    "Details": [
      {
        "title": "Software Engineer",
        "EmployeeId": 451
      }
    ]
  },
  {
    "employee2": "employee2",
    "Details": []
  },
  {
    "employee3": "employee3",
    "Details": [
      {
        "title": "Test analyst",
        "EmployeeId": 453
      }
    ]
  },
  {
    "employee4": "employee4",
    "Details": [
      {
        "title": "Software engineer",
        "EmployeeId": 487
      },
      {
        "title": "Architect",
        "EmployeeId": 500
      }
    ]
  }
]
Run Code Online (Sandbox Code Playgroud)

获取 EmployeeId 的最佳方式是什么?

预期输出:

[451,453,487,500]
Run Code Online (Sandbox Code Playgroud)

当我使用时:

console.log(Object.assign({}, ...employees).Details.map(t=>t.EmployeeId))
Run Code Online (Sandbox Code Playgroud)

它返回的结果为:

[487,500]
Run Code Online (Sandbox Code Playgroud)

有没有办法在结果中连接其他员工 ID?

javascript arrays json object node.js

1
推荐指数
1
解决办法
1368
查看次数