-
Notifications
You must be signed in to change notification settings - Fork 1
/
FeatureBuilder.cs
83 lines (75 loc) · 3.13 KB
/
FeatureBuilder.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.TestManagement.Client;
using System.IO;
namespace tfs_cli
{
class FeatureBuilder : ITfsCliBuilder
{
private static string sep = Path.DirectorySeparatorChar.ToString();
private static string featuresDir = "features";
private static string featureHeader = "Feature: ";
private static string scenarioHeader = "Scenario: ";
private static string fileExtension = ".feature";
private static string prefix = " ";
private static string doublePrefix = " ";
private static string lb = Environment.NewLine;
private string tmp = Path.GetTempPath()+sep+featuresDir;
public string Finalize()
{
return "";
}
public void Append(ITestSuiteBase suite)
{
try
{
if (!Directory.Exists(tmp))
Directory.CreateDirectory(tmp);
TfsCliHelper.Debug(string.Format("TmpDir: \"{0}\"", tmp));
string featureName = tmp + sep + suite.Title + fileExtension;
TfsCliHelper.Debug(string.Format("NewFeature: \"{0}\"", featureName));
StreamWriter file = new StreamWriter(featureName);
file.WriteLine(featureHeader + suite.Title);
foreach (ITestSuiteEntry entry in suite.TestCases)
{
TfsCliHelper.Debug(string.Format("AddSuite: \"{0}\"", suite.Title));
Append(entry.TestCase, file);
}
file.Close();
}
catch (IOException e)
{
TfsCliHelper.ExitWithError(string.Format("Could not create feature files in TMP dir: {0}\nError: {1}", tmp, e.Message));
}
}
public void Header(string url, string project, string testplan){}
public string GetFeatureFilesPath(){
return tmp;
}
private void Append(ITestCase test, StreamWriter file)
{
TfsCliHelper.Debug(string.Format("AddTest: \"{0}\"", test.Title));
file.WriteLine(prefix + scenarioHeader + test.Title);
foreach (ITestAction action in test.Actions)
Append((ITestStep)action, file);
}
private void Append(ITestStep step, StreamWriter file)
{
string act = TfsCliHelper.toFeatureStep(TfsCliHelper.fromHtml(step.Title), doublePrefix, lb);
string er = TfsCliHelper.toFeatureStep(TfsCliHelper.fromHtml(step.ExpectedResult), doublePrefix, lb);
if (act != "")
{
TfsCliHelper.Debug(string.Format("AddAction: \"{0}\"", act));
file.WriteLine(doublePrefix + act);
}
if (er != "")
{
TfsCliHelper.Debug(string.Format("AddExpectedResult: \"{0}\"", er));
file.WriteLine(doublePrefix + er);
}
}
}
}