-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestDataIndex.tt
More file actions
151 lines (126 loc) · 5.59 KB
/
TestDataIndex.tt
File metadata and controls
151 lines (126 loc) · 5.59 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".generated.cs" #>
// ******************************************************************************
// © 2016 Sebastiaan Dammann - damsteen.nl
//
// File: : Test.cs
// Project : NUnitTestOrdering.Tests
// ******************************************************************************
<#
DirectoryInfo testDataDirectory = new DirectoryInfo(Path.GetDirectoryName(Host.TemplateFile));
string basePath = testDataDirectory.FullName + Path.DirectorySeparatorChar;
const string prefix = "TestData";
#>
// <autogenerated>
// This file is generated by <#=Path.GetFileName(Host.TemplateFile)#>. Any changes will be lost
// when the file is regenerated. Do not edit this file.
// </autogenerated>
namespace NUnitTestOrdering.Tests.IntegrationTests {
using System.Diagnostics.CodeAnalysis;
using System.Xml.Linq;
using NUnit.Framework;
using NUnitTestOrdering.Tests.TestData;
using Support;
<# foreach (var fixtureDirectory in testDataDirectory.GetDirectories()) {#>
[TestFixture]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public sealed partial class <#=fixtureDirectory#> {
<# foreach (var testDirectory in fixtureDirectory.GetDirectories()) { #>
[Test]
[TestCaseSource(typeof(NUnitVersionEnumerator), nameof(NUnitVersionEnumerator.GetTestCases), Category = TestCategory.IntegrationTest)]
public void <#=testDirectory.Name#>(NUnitVersion nunitVersion) {
// Given
var input = TestDataDirectories.<#=fixtureDirectory.Name#>.<#=testDirectory.Name#>();
string expectedResult = input.ReadResultsFile();
// When
string result;
XDocument rawResultsDocument;
using (TestRunner testRunner = new TestRunner(input, nunitVersion)) {
result = testRunner.Run();
rawResultsDocument = testRunner.TestResultsDocument;
}
// Then
Assert.That(result, Is.EqualTo(expectedResult));
if (rawResultsDocument != null) {
<#=testDirectory.Name#>_AssertResultsFile(new ResultsDocument(rawResultsDocument));
}
}
partial void <#=testDirectory.Name#>_AssertResultsFile(ResultsDocument testResults);
<# } #>
}
<# } #>
}
namespace NUnitTestOrdering.Tests.TestData {
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Text;
public class TestDataDirectory {
public string [] Files { get; set; }
public string ExpectedResultFile { get;set; }
public string ReadResultsFile() {
Assembly thisAssembly = this.GetType().Assembly;
StringBuilder resultsFile = new StringBuilder();
Stream stream = thisAssembly.GetManifestResourceStream(this.ExpectedResultFile);
if (stream == null) {
throw new InvalidOperationException("Unknown manifest resource stream " + this.ExpectedResultFile);
}
using (StreamReader sr = new StreamReader(stream)) {
string line;
while ((line = sr.ReadLine()) != null) {
if (line.Length == 0 || line[0] == '#') {
// Skip "comment" line
continue;
}
resultsFile.AppendLine(line);
}
}
if (resultsFile.Length == 0){
return String.Empty;
}
resultsFile.Remove(resultsFile.Length - Environment.NewLine.Length, Environment.NewLine.Length);
return resultsFile.ToString();
}
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static class TestDataDirectories {
private static readonly string ThisAssemblyName = typeof(TestDataDirectory).Assembly.GetName().Name;
<# foreach (var fixtureDirectory in testDataDirectory.GetDirectories()) {#>
public static class <#=fixtureDirectory.Name#> {
<# foreach (var testDirectory in fixtureDirectory.GetDirectories()) { #>
public static TestDataDirectory <#=testDirectory.Name#>() {
return new TestDataDirectory {
Files = new [] {
<# foreach (var file in testDirectory.GetFiles("*.cs")) { #>
<#
string fullFilePath = file.FullName;
fullFilePath = fullFilePath.Substring(basePath.Length);
string relFilePath = Path.Combine(prefix, fullFilePath);
string assemblyResourcePath = relFilePath.Replace(Path.DirectorySeparatorChar.ToString(), ".");
#>
ThisAssemblyName + "." + "<#=assemblyResourcePath#>",
<# } #>
ThisAssemblyName + "." + @"TestData.Common.cs"
},
<#
{
string resultsFile = Path.Combine(testDirectory.FullName, "ExpectedTestResult.txt");
string fullFilePath = resultsFile.Substring(basePath.Length);
string relFilePath = Path.Combine(prefix, fullFilePath);
string assemblyResourcePath = relFilePath.Replace(Path.DirectorySeparatorChar.ToString(), ".");
#>
ExpectedResultFile = ThisAssemblyName + ".<#=assemblyResourcePath#>"
<# }#>
};
}
<# } #>
}
<# } #>
}
}