-
Notifications
You must be signed in to change notification settings - Fork 378
/
Copy pathPostActionTests.cs
155 lines (147 loc) · 6.55 KB
/
PostActionTests.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.TemplateEngine.TestHelper;
using Newtonsoft.Json.Linq;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Core;
using Microsoft.TemplateEngine.Core.Contracts;
using Xunit;
namespace Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests.TemplateConfigTests
{
public class PostActionTests : TestBase
{
[Theory(DisplayName = nameof(TestPostActionConditioning))]
[InlineData(true, true, 2, new[] { "Action1", "Default instructions (action 1)" }, new[] { "Action2", "Default instructions (action 2)" })]
[InlineData(true, false, 1, new[] { "Action1", "Default instructions (action 1)" }, null)]
[InlineData(false, true, 1, new[] { "Action2", "Default instructions (action 2)" }, null)]
[InlineData(false, false, 0, null, null)]
public void TestPostActionConditioning(bool condition1, bool condition2, int expectedActionCount, string[] firstResult, string[] secondResult)
{
SimpleConfigModel configModel = SimpleConfigModel.FromJObject(EngineEnvironmentSettings, TestTemplateJson);
IVariableCollection vc = new VariableCollection
{
["ActionOneCondition"] = condition1,
["ActionTwoCondition"] = condition2
};
List<IPostAction> postActions = PostAction.ListFromModel(EngineEnvironmentSettings, configModel.PostActionModel, vc);
Assert.Equal(expectedActionCount, postActions.Count);
if (firstResult != null && firstResult.Length > 0)
{
Assert.True(string.Equals(postActions[0].Description, firstResult[0]), $"expected '{firstResult[0]}', but got {postActions[0].Description}");
Assert.Equal(firstResult[1], postActions[0].ManualInstructions);
}
if (secondResult != null && secondResult.Length > 0)
{
Assert.True(string.Equals(postActions[1].Description, secondResult[0]), $"expected '{secondResult[0]}', but got {postActions[1].Description}");
Assert.Equal(secondResult[1], postActions[1].ManualInstructions);
}
}
[Theory(DisplayName = nameof(TestPostActionInstructionsConditioning))]
[InlineData(true, true, 2, "Windows", "Windows instructions (action 1)", "Windows instructions (action 2)")]
[InlineData(true, true, 2, "Linux", "Linux instructions (action 1)", "Linux instructions (action 2)")]
[InlineData(true, true, 2, "Mac", "Mac instructions (action 1)", "Mac instructions (action 2)")]
[InlineData(true, true, 2, "BeOS", "Default instructions (action 1)", "Default instructions (action 2)")]
[InlineData(true, false, 1, "Windows", "Windows instructions (action 1)", null)]
[InlineData(true, false, 1, "Linux", "Linux instructions (action 1)", null)]
[InlineData(true, false, 1, "Mac", "Mac instructions (action 1)", null)]
[InlineData(true, false, 1, "BeOS", "Default instructions (action 1)", null)]
[InlineData(false, true, 1, "Windows", "Windows instructions (action 2)", null)]
[InlineData(false, true, 1, "Linux", "Linux instructions (action 2)", null)]
[InlineData(false, true, 1, "Mac", "Mac instructions (action 2)", null)]
[InlineData(false, true, 1, "BeOS", "Default instructions (action 2)", null)]
public void TestPostActionInstructionsConditioning(bool condition1, bool condition2, int expectedActionCount, string operatingSystemValue, string firstInstruction, string secondInstruction)
{
SimpleConfigModel configModel = SimpleConfigModel.FromJObject(EngineEnvironmentSettings, TestTemplateJson);
IVariableCollection vc = new VariableCollection
{
["ActionOneCondition"] = condition1,
["ActionTwoCondition"] = condition2,
["OperatingSystemKind"] = operatingSystemValue
};
List<IPostAction> postActions = PostAction.ListFromModel(EngineEnvironmentSettings, configModel.PostActionModel, vc);
Assert.Equal(expectedActionCount, postActions.Count);
if (! string.IsNullOrEmpty(firstInstruction))
{
Assert.Equal(firstInstruction, postActions[0].ManualInstructions);
}
if (! string.IsNullOrEmpty(secondInstruction))
{
Assert.Equal(secondInstruction, postActions[1].ManualInstructions);
}
}
private static JObject TestTemplateJson
{
get
{
string configString = @"
{
""Author"": ""Microsoft"",
""Classifications"": ""UnitTest"",
""name"": ""Dotnet Unit Test Template"",
""groupIdentity"": ""Dotnet.Testing"",
""identity"": ""Dotnet.UnitTest.Template"",
""shortName"": ""test"",
""PostActions"": [
{
""Condition"": ""(ActionOneCondition)"",
""Description"": ""Action1"",
""ActionId"": ""7F0CDCFC-839A-4625-88F6-27590E6299EF"",
""ContinueOnError"": ""false"",
""Args"": {
""Foo"": ""Bar"",
""Baz"": ""Blah""
},
""ManualInstructions"": [
{
""Text"": ""Windows instructions (action 1)"",
""condition"": ""(OperatingSystemKind == \""Windows\"")""
},
{
""Text"": ""Linux instructions (action 1)"",
""condition"": ""(OperatingSystemKind == \""Linux\"")""
},
{
""Text"": ""Mac instructions (action 1)"",
""condition"": ""(OperatingSystemKind == \""Mac\"")""
},
{
""Text"": ""Default instructions (action 1)""
}
]
},
{
""Condition"": ""(ActionTwoCondition)"",
""Description"": ""Action2"",
""ActionId"": ""95858732-757E-42AD-8D63-8A4D8C35B829"",
""ContinueOnError"": ""false"",
""Args"": {
""Bar"": ""Foo"",
""Blah"": ""Baz"",
""X"": ""Y""
},
""ManualInstructions"": [
{
""Text"": ""Mac instructions (action 2)"",
""condition"": ""(OperatingSystemKind == \""Mac\"")""
},
{
""Text"": ""Linux instructions (action 2)"",
""condition"": ""(OperatingSystemKind == \""Linux\"")""
},
{
""Text"": ""Windows instructions (action 2)"",
""condition"": ""(OperatingSystemKind == \""Windows\"")""
},
{
""Text"": ""Default instructions (action 2)""
}
]
},
]
}";
return JObject.Parse(configString);
}
}
}
}