-
Notifications
You must be signed in to change notification settings - Fork 103
/
CsProjAcceptanceTests.cs
54 lines (46 loc) · 2.03 KB
/
CsProjAcceptanceTests.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
using NUnit.Framework;
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;
namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance;
public abstract class CsProjAcceptanceTests : AcceptanceTests
{
protected abstract void AddTestsCs(IsolatedWorkspace workspace);
protected abstract string Framework { get; }
protected const string NoFilter = "";
protected IsolatedWorkspace CreateTestWorkspace(string framework)
{
var workspace = CreateWorkspace()
.AddProject("Test.csproj", $@"
<Project Sdk='Microsoft.NET.Sdk'>
<PropertyGroup>
<TargetFramework>{framework}</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include='Microsoft.NET.Test.Sdk' Version='*' />
<PackageReference Include='NUnit' Version='{NUnitVersion(framework)}' />
<PackageReference Include='NUnit3TestAdapter' Version='{NuGetPackageVersion}' />
</ItemGroup>
</Project>");
return workspace;
}
protected IsolatedWorkspace Build()
{
var workspace = CreateTestWorkspace(Framework);
AddTestsCs(workspace);
workspace.MsBuild(restore: true);
return workspace;
}
protected void Verify(int executed, int total, VSTestResult results)
{
TestContext.WriteLine(" ");
foreach (var error in results.RunErrors)
TestContext.WriteLine(error);
Assert.Multiple(() =>
{
Assert.That(results.Counters.Total, Is.EqualTo(total),
$"Total tests counter did not match expectation\n{results.ProcessRunResult.StdOut}");
Assert.That(results.Counters.Executed, Is.EqualTo(executed),
"Executed tests counter did not match expectation");
Assert.That(results.Counters.Passed, Is.EqualTo(executed), "Passed tests counter did not match expectation");
});
}
}