通过这篇文章,我找到了一种获取斜杠后字符串最后一部分的方法。
我需要对此进行稍微修改:
我可以使用一个正则表达式来匹配“倒数第二个反斜杠之后的所有内容”。
我重写了原来的内容以使用反斜杠,如下所示:
([^\\]+$)
Run Code Online (Sandbox Code Playgroud)
我编写了这段代码并进行了测试
public static string TrimTrail(this string value, string pattern)
{
var regEx = new Regex(pattern);
var result = regEx.Match(value);
return result.Value;
}
[Test]
public void TestOfTrimmingTrail()
{
//Arrange
var stringToTest = @"0001 Lorem ipsum dolor sit\011 tortor neque\ 0111\interdum magn";
var pattern = @"([^\\]+$)";
//Act
var result = stringToTest.TrimTrail(pattern);
//Assert
Assert.AreEqual(" 0111\\interdum magn", result);
}
Run Code Online (Sandbox Code Playgroud)
但由于我一直无法弄清楚“倒数第二个”要求,所以它只返回
Expected string length 19 but was 13. Strings differ at index 0.
Expected: " 0111\\interdum magn"
But …Run Code Online (Sandbox Code Playgroud) 我希望能够在我的测试代码中访问测试的持续时间.我一直在看TestContextNUnit 中的类,但是当我发现信息与"FullName"相关时,我无法确定在何处访问测试的持续时间.
[TearDown]
public void TearDown()
{
Console.WriteLine(TestContext.CurrentContext.Test.FullName);
}
Run Code Online (Sandbox Code Playgroud)
除了测试的全名,我可以访问Properties字典,但在所有情况下,只有值是"_CATEGORIES"条目.
我如何完成我想做的事情?
谢谢 :-)
我们正在努力应对 429 HTTP 异常(来自 SharePoint Online 或 Microsoft Graph),我想利用 Polly 和 Castle.Windsor 来处理这个问题。
我的代码是(摘录)
在我的 Castle.Windsor 容器中注册 Polly 的东西:
_container.Register(Component.For<IRepository>()
.ImplementedBy<Repository>()
.DependsOn(Dependency.OnValue<ImportSettings>(_importSettings))
.Interceptors(InterceptorReference.ForKey("throttle")).Anywhere
.LifestyleTransient());
_container.Register(Component.For<WaitAndRetryInterceptor<WebException>>().LifeStyle.Singleton
.Named("throttle"));
Run Code Online (Sandbox Code Playgroud)
我的波莉的东西:
public class WaitAndRetryInterceptor<T> : IInterceptor where T : WebException
{
private readonly RetryPolicy _policy;
public void Intercept(IInvocation invocation)
{
var dictionary = new Dictionary<string, object> {{"methodName", invocation.Method.Name}};
_policy.Execute(invocation.Proceed, dictionary);
}
public WaitAndRetryInterceptor()
{
_policy =
Policy
.Handle<T>()
.WaitAndRetry(new[]
{
TimeSpan.FromSeconds(16), TimeSpan.FromSeconds(32), TimeSpan.FromSeconds(64),
TimeSpan.FromSeconds(128), TimeSpan.FromSeconds(256), TimeSpan.FromSeconds(512)
});
}
}
Run Code Online (Sandbox Code Playgroud)
所以这个实现满足了我的需求 - 但它非常保守。因此,我尝试实现对抛出的 429 异常的直接支持 …
我有一个 .net core 项目,在 Azure DevOps 中设置了管道(YAML、多阶段)管道。我们有一堆在管道运行时执行的单元测试 - 一切都很好。
然而,我们希望更深入地了解我们的代码覆盖率。所以我们这样配置我们的任务
- task: DotNetCoreCLI@2
displayName: Run UnitTests
enabled: true
inputs:
command: test
projects: '**/PM.UnitTests.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
Run Code Online (Sandbox Code Playgroud)
结果是这样的
我们现在可以在管道结果中看到这一点:
可以在 Visual Studio 等中下载并分析该 .coverage 文件。
然而,我们真的希望能够直接在 Azure Pipelines 中看到结果。我们有一个 Typescript 项目来执行此操作。结果是这样的:

遗憾的是,我根本不知道如何将其应用到 .net core 项目。
Q1:.net core 项目是否有可能获得相同的体验……以及如何获得?
此外,我们希望能够对用于计算代码覆盖率百分比的代码部分进行过滤。
问题 2:是否正确理解这是使用.runsettings文件完成的?
谢谢 :-)
/杰斯珀
作为参考,这是我的测试 .net core 解决方案中的完整 YAML 管道。解决方案超级简单——一个.net core类库和一个.net core测试类库
pool:
vmImage: vs2017-win2016
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
feedsToUse: 'select'
vstsFeed: 'd12c137f-dac4-4ea7-bc39-59bd2b784537' …Run Code Online (Sandbox Code Playgroud) code-coverage .net-core azure-pipelines azure-pipelines-yaml