-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathGivenDotnetTestBuildsAndRunsTestBasedOnGlobbingFilter.cs
127 lines (99 loc) · 5.77 KB
/
GivenDotnetTestBuildsAndRunsTestBasedOnGlobbingFilter.cs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using CommandResult = Microsoft.DotNet.Cli.Utils.CommandResult;
namespace Microsoft.DotNet.Cli.Test.Tests
{
public class GivenDotnetTestBuildsAndRunsTestBasedOnGlobbingFilter : SdkTest
{
public GivenDotnetTestBuildsAndRunsTestBasedOnGlobbingFilter(ITestOutputHelper log) : base(log)
{
}
[Fact]
public void RunTestProjectWithFilterOfDll_ShouldReturnZeroAsExitCode()
{
TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectWithTests", Guid.NewGuid().ToString())
.WithSource();
new BuildCommand(testInstance)
.Execute()
.Should().Pass();
var binDirectory = new FileInfo($"{testInstance.Path}{Path.DirectorySeparatorChar}bin").Directory;
var binDirectoryLastWriteTime = binDirectory?.LastWriteTime;
CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
.WithWorkingDirectory(testInstance.Path)
.WithEnableTestingPlatform()
.Execute(TestingPlatformOptions.TestModulesFilterOption.Name, $"**/bin/**/Debug/{ToolsetInfo.CurrentTargetFramework}/TestProject.dll".Replace('/', Path.DirectorySeparatorChar));
// Assert that the bin folder hasn't been modified
Assert.Equal(binDirectoryLastWriteTime, binDirectory?.LastWriteTime);
if (!TestContext.IsLocalized())
{
Assert.Matches(RegexPatternHelper.GenerateProjectRegexPattern("TestProject", TestingConstants.Passed, true, TestingConstants.Debug), result.StdOut);
result.StdOut
.Should().Contain("Test run summary: Passed!")
.And.Contain("total: 2")
.And.Contain("succeeded: 1")
.And.Contain("failed: 0")
.And.Contain("skipped: 1");
}
result.ExitCode.Should().Be(ExitCodes.Success);
}
[Fact]
public void RunTestProjectsWithFilterOfDll_ShouldReturnOneAsExitCode()
{
TestAsset testInstance = _testAssetsManager.CopyTestAsset("MultiTestProjectSolutionWithTests", Guid.NewGuid().ToString())
.WithSource();
new BuildCommand(testInstance, "TestProject")
.Execute()
.Should().Pass();
new BuildCommand(testInstance, "OtherTestProject")
.Execute()
.Should().Pass();
var binDirectory = new FileInfo($"{testInstance.Path}{Path.DirectorySeparatorChar}bin").Directory;
var binDirectoryLastWriteTime = binDirectory?.LastWriteTime;
string filterExpression = $"**/bin/**/Debug/{ToolsetInfo.CurrentTargetFramework}/*TestProject.dll".Replace('/', Path.DirectorySeparatorChar);
CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
.WithWorkingDirectory(testInstance.Path)
.WithEnableTestingPlatform()
.Execute(TestingPlatformOptions.TestModulesFilterOption.Name, filterExpression);
// Assert that the bin folder hasn't been modified
Assert.Equal(binDirectoryLastWriteTime, binDirectory?.LastWriteTime);
if (!TestContext.IsLocalized())
{
Assert.Matches(RegexPatternHelper.GenerateProjectRegexPattern("TestProject", TestingConstants.Failed, true, TestingConstants.Debug), result.StdOut);
Assert.Matches(RegexPatternHelper.GenerateProjectRegexPattern("OtherTestProject", TestingConstants.Passed, true, TestingConstants.Debug), result.StdOut);
result.StdOut
.Should().Contain("Test run summary: Failed!")
.And.Contain("total: 5")
.And.Contain("succeeded: 2")
.And.Contain("failed: 1")
.And.Contain("skipped: 2");
}
result.ExitCode.Should().Be(ExitCodes.GenericFailure);
}
[Fact]
public void RunTestProjectWithFilterOfDllWithRootDirectory_ShouldReturnZeroAsExitCode()
{
TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectWithTests", Guid.NewGuid().ToString())
.WithSource();
new BuildCommand(testInstance)
.Execute()
.Should().Pass();
CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
.WithWorkingDirectory(testInstance.Path)
.WithEnableTestingPlatform()
.WithTraceOutput()
.Execute(TestingPlatformOptions.TestModulesFilterOption.Name, $"**/bin/**/Debug/{ToolsetInfo.CurrentTargetFramework}/TestProject.dll".Replace('/', Path.DirectorySeparatorChar),
TestingPlatformOptions.TestModulesRootDirectoryOption.Name, testInstance.TestRoot);
if (!TestContext.IsLocalized())
{
Assert.Matches(RegexPatternHelper.GenerateProjectRegexPattern("TestProject", TestingConstants.Passed, true, TestingConstants.Debug), result.StdOut);
result.StdOut
.Should().Contain("Test run summary: Passed!")
.And.Contain("total: 2")
.And.Contain("succeeded: 1")
.And.Contain("failed: 0")
.And.Contain("skipped: 1");
}
result.ExitCode.Should().Be(ExitCodes.Success);
}
}
}