-
Notifications
You must be signed in to change notification settings - Fork 1
/
XmlBuilder.cs
86 lines (81 loc) · 3.2 KB
/
XmlBuilder.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
using Microsoft.TeamFoundation.TestManagement.Client;
using System;
using System.Text.RegularExpressions;
using System.Xml.Linq;
namespace tfs_cli
{
class XmlBuilder : ITfsCliBuilder
{
private XElement _root = new XElement("tests");
public string Finalize()
{
return _root.ToString();
}
public XElement DocRoot()
{
return _root;
}
public void Append(ITestSuiteBase suite)
{
TfsCliHelper.Debug(string.Format("AddSuite: \"{0}\"", suite.Title));
XElement xmlsuite = new XElement("testsuite");
xmlsuite.Add(
new XAttribute("id", suite.Id),
new XAttribute("title", suite.Title),
new XAttribute("description", suite.Description ?? ""),
new XAttribute("state", suite.State),
new XAttribute("type", suite.TestSuiteType),
new XAttribute("user_data", suite.UserData ?? "")
);
foreach (ITestSuiteEntry entry in suite.TestCases)
{
Append(entry.TestCase, xmlsuite);
}
_root.Add(xmlsuite);
}
public void Header(string url, string project, string testplan) {
_root.Add(
new XAttribute("url", url),
new XAttribute("project", project),
new XAttribute("testplan", testplan)
);
}
private void Append(ITestCase test, XElement root)
{
TfsCliHelper.Debug(string.Format("AddTest: \"{0}\"", test.Title));
XElement xmltest = new XElement("test");
xmltest.Add(
new XAttribute("id", test.Id),
new XAttribute("title", test.Title),
new XAttribute("description", TfsCliHelper.fromHtml(test.Description) ?? ""),
new XAttribute("state", test.State),
new XAttribute("priority", test.Priority),
new XAttribute("owner", test.OwnerName),
new XAttribute("reason", test.Reason),
new XAttribute("is_automated", test.IsAutomated),
new XAttribute("area", test.Area ?? "")
);
foreach (ITestAction action in test.Actions)
{
XElement a = new XElement("action");
ITestStep step = (ITestStep)action;
TfsCliHelper.Debug(string.Format("AddAction: \"{0}\"-\"{1}\"", TfsCliHelper.fromHtml(step.Title), TfsCliHelper.fromHtml(step.ExpectedResult)));
a.Add(
new XAttribute("id", action.Id),
new XAttribute("action", TfsCliHelper.fromHtml(step.Title)),
new XAttribute("expected_result", TfsCliHelper.fromHtml(step.ExpectedResult))
);
xmltest.Add(a);
}
/*
IEnumerator custom = test.CustomFields.GetEnumerator();
while (custom.MoveNext())
{
xmltest.Add("custom", custom.Current.ToString());
}
*/
// add this staff to root
root.Add(xmltest);
}
}
}