Skip to content

Commit 7fca82f

Browse files
committed
adding client tests, verified passing
* Got rid of the optional CLI-based config overrides as these are not reliable or consistent across different test providers (MSTest vs XUnit) * Replaced the various CMD files representing pre-defined testing scenarios with a single, parameter-driven POSH script * Tested all the test cases against a freshly deployed and configured *classic* DSC Pull Server v2 -- setup as per the *install steps* of the AppVeyor setup
1 parent 38cb5af commit 7fca82f

File tree

6 files changed

+961
-0
lines changed

6 files changed

+961
-0
lines changed

TugDSC.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TugDSC.Configuration-tests"
3333
EndProject
3434
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TugDSC.Client.CLIApp", "src\TugDSC.Client.CLIApp\TugDSC.Client.CLIApp.csproj", "{66F0098E-71A2-4145-87C1-7251CA25A667}"
3535
EndProject
36+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "client", "client", "{3FC7F219-6BFC-45F2-95D2-9DFC16566565}"
37+
EndProject
38+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TugDSC.Client.CLIApp-tests", "test\client\TugDSC.Client.CLIApp-tests\TugDSC.Client.CLIApp-tests.csproj", "{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}"
39+
EndProject
3640
Global
3741
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3842
Debug|Any CPU = Debug|Any CPU
@@ -154,6 +158,18 @@ Global
154158
{66F0098E-71A2-4145-87C1-7251CA25A667}.Release|x64.Build.0 = Release|x64
155159
{66F0098E-71A2-4145-87C1-7251CA25A667}.Release|x86.ActiveCfg = Release|x86
156160
{66F0098E-71A2-4145-87C1-7251CA25A667}.Release|x86.Build.0 = Release|x86
161+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
162+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
163+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Debug|x64.ActiveCfg = Debug|x64
164+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Debug|x64.Build.0 = Debug|x64
165+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Debug|x86.ActiveCfg = Debug|x86
166+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Debug|x86.Build.0 = Debug|x86
167+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
168+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Release|Any CPU.Build.0 = Release|Any CPU
169+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Release|x64.ActiveCfg = Release|x64
170+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Release|x64.Build.0 = Release|x64
171+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Release|x86.ActiveCfg = Release|x86
172+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB}.Release|x86.Build.0 = Release|x86
157173
EndGlobalSection
158174
GlobalSection(NestedProjects) = preSolution
159175
{97DECA03-C0C3-4F41-A0FE-F51CA949D501} = {BA29CE93-33EE-419B-A855-DA934573FA83}
@@ -170,5 +186,6 @@ Global
170186
{7D05444A-BF9C-4E5A-BAC5-F0895F339328} = {BAD7D8A3-4841-42A4-8033-F2D39AE34AD4}
171187
{66F0098E-71A2-4145-87C1-7251CA25A667} = {BA29CE93-33EE-419B-A855-DA934573FA83}
172188
{3FC7F219-6BFC-45F2-95D2-9DFC16566565} = {76F0F40C-622E-453C-A012-6A26C1F97F41}
189+
{45EA7E4A-BE09-4CA7-AC8C-8AAB356032BB} = {3FC7F219-6BFC-45F2-95D2-9DFC16566565}
173190
EndGlobalSection
174191
EndGlobal
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
using System;
2+
using System.Linq;
3+
using System.Net.Http;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
using Newtonsoft.Json;
6+
using TugDSC.Client;
7+
using TugDSC.Testing.MSTest;
8+
9+
namespace TugDSC.Client.CLIApp
10+
{
11+
[TestClass]
12+
public class ClassicPullServerProtocolCompatibilityReportTests : ProtocolCompatibilityTestsBase
13+
{
14+
[ClassInitialize]
15+
public new static void ClassInit(TestContext ctx)
16+
{
17+
ProtocolCompatibilityTestsBase.ClassInit(ctx);
18+
}
19+
20+
[TestMethod]
21+
public void TestSendReport()
22+
{
23+
var config = BuildConfig(newAgentId: true);
24+
using (var client = new DscPullClient(config))
25+
{
26+
client.DisableReportAdditionalData = _testConfig.adjust_for_wmf_50;
27+
client.RegisterDscAgent().Wait();
28+
client.SendReport("SimpleInventoryDefaults",
29+
overrides: new Model.SendReportBody
30+
{
31+
NodeName = "MY_NAME",
32+
IpAddress = "::1;127.0.01",
33+
}).Wait();
34+
client.SendReport("DetailedStatusDefaults",
35+
statusData: new[] { "STATUS" }).Wait();
36+
client.SendReport("ErrorDefaults",
37+
errors: new[] { "ERROR" }).Wait();
38+
}
39+
}
40+
41+
[TestMethod]
42+
public void TestSendReport_BadEmptyBody()
43+
{
44+
var config = BuildConfig();
45+
using (var client = new DscPullClient(config))
46+
{
47+
client.DisableReportAdditionalData = _testConfig.adjust_for_wmf_50;
48+
Assert.That.ThrowsWhen<AggregateException>(
49+
condition: (ex) =>
50+
ex.InnerException is HttpRequestException
51+
&& ex.InnerException.Message.Contains(
52+
"Response status code does not indicate success: 400 (Bad Request)"),
53+
action: () =>
54+
client.SendReport(null).Wait(),
55+
message:
56+
"Throws HTTP exception for bad request (400)");
57+
}
58+
}
59+
60+
[TestMethod]
61+
public void TestSendReport_BadMissingJobId()
62+
{
63+
var config = BuildConfig();
64+
using (var client = new DscPullClient(config))
65+
{
66+
client.DisableReportAdditionalData = _testConfig.adjust_for_wmf_50;
67+
Assert.That.ThrowsWhen<AggregateException>(
68+
condition: (ex) =>
69+
ex.InnerException is HttpRequestException
70+
&& ex.InnerException.Message.Contains(
71+
"Response status code does not indicate success: 400 (Bad Request)"),
72+
action: () =>
73+
client.SendReport(new BadSendReportBody()).Wait(),
74+
message:
75+
"Throws HTTP exception for bad request (400)");
76+
}
77+
}
78+
79+
[TestMethod]
80+
public void TestSendReport_BadDateFormat()
81+
{
82+
var report = new Model.SendReportBody
83+
{
84+
JobId = Guid.NewGuid(),
85+
StartTime = "NOW",
86+
EndTime = "THEN",
87+
OperationType = "FOO",
88+
ReportFormatVersion = "BAR",
89+
};
90+
91+
var config = BuildConfig();
92+
using (var client = new DscPullClient(config))
93+
{
94+
client.DisableReportAdditionalData = _testConfig.adjust_for_wmf_50;
95+
Assert.That.ThrowsWhen<AggregateException>(
96+
condition: (ex) =>
97+
ex.InnerException is HttpRequestException
98+
&& ex.InnerException.Message.Contains(
99+
"Response status code does not indicate success: 500 (Internal Server Error)"),
100+
action: () =>
101+
client.SendReport(report).Wait(),
102+
message:
103+
"Throws HTTP exception for internal server error (500)");
104+
}
105+
}
106+
107+
[TestMethod]
108+
public void TestGetReports_Single()
109+
{
110+
var reportDateFormat = CLASSIC_SERVER_REPORT_DATE_FORMAT;
111+
if (_testConfig.adjust_for_wmf_50)
112+
reportDateFormat = CLASSIC_SERVER_REPORT_DATE_FORMAT_ALT;
113+
114+
var config = BuildConfig(newAgentId: true);
115+
var report = new Model.SendReportBody
116+
{
117+
JobId = Guid.NewGuid(),
118+
OperationType = "FOO",
119+
RefreshMode = Model.DscRefreshMode.Pull,
120+
Status = "BAR",
121+
ReportFormatVersion = "Spooky",
122+
ConfigurationVersion = "Scary",
123+
//StartTime = DateTime.Now.ToString(Model.SendReportBody.REPORT_DATE_FORMAT),
124+
StartTime = DateTime.Now.ToString(reportDateFormat),
125+
//EndTime = DateTime.Now.ToString(Model.SendReportBody.REPORT_DATE_FORMAT),
126+
EndTime = DateTime.Now.ToString(reportDateFormat),
127+
RebootRequested = Model.DscTrueFalse.False,
128+
StatusData = new[] { "STATUS-DATA" },
129+
Errors = new[] { "ERRORS" },
130+
AdditionalData = new[]
131+
{
132+
new Model.SendReportBody.AdditionalDataItem { Key = "1", Value = "ONE", },
133+
new Model.SendReportBody.AdditionalDataItem { Key = "2", Value = "TWO", },
134+
},
135+
};
136+
137+
using (var client = new DscPullClient(config))
138+
{
139+
client.DisableReportAdditionalData = _testConfig.adjust_for_wmf_50;
140+
client.RegisterDscAgent().Wait();
141+
client.SendReport(report).Wait();
142+
143+
var sr = client.GetReports().Result;
144+
Assert.IsNotNull(sr, "Reports not null");
145+
var srArr = sr.ToArray();
146+
Assert.AreEqual(1, srArr.Length, "Reports length is exactly 1");
147+
148+
// Unfortunate kludge to deal with broken DscService on WMF 5.1
149+
// See https://github.com/PowerShell/PowerShell/issues/2921
150+
if (_testConfig.adjust_for_wmf_50)
151+
report.AdditionalData = Model.SendReportBody.AdditionalDataItem.EMPTY_ITEMS;
152+
153+
var ser1 = JsonConvert.SerializeObject(report);
154+
var ser2 = JsonConvert.SerializeObject(srArr[0]);
155+
Assert.AreEqual(ser1, ser2, "Submitted and retrieved reports are the same");
156+
157+
sr = client.GetReports().Result;
158+
Assert.IsNotNull(sr, "All reports not null");
159+
srArr = sr.ToArray();
160+
Assert.AreEqual(1, srArr.Length, "All reports length is exactly 1");
161+
}
162+
}
163+
164+
[TestMethod]
165+
public void TestGetReports_Multi()
166+
{
167+
var strArr1 = new[] { "STATUS-1" };
168+
var strArr2 = new[] { "STATUS-2" };
169+
var strArr3 = new[] { "ERROR-1" };
170+
var strArr4 = new[] { "ERROR-2" };
171+
172+
var config = BuildConfig(newAgentId: true);
173+
using (var client = new DscPullClient(config))
174+
{
175+
client.DisableReportAdditionalData = _testConfig.adjust_for_wmf_50;
176+
client.RegisterDscAgent().Wait();
177+
client.SendReport(operationType: "1", statusData: strArr1).Wait();
178+
client.SendReport(operationType: "2", statusData: strArr2).Wait();
179+
client.SendReport(operationType: "3", errors: strArr3).Wait();
180+
client.SendReport(operationType: "4", errors: strArr4).Wait();
181+
182+
var sr = client.GetReports().Result;
183+
Assert.IsNotNull(sr, "All reports not null");
184+
var srArr = sr.ToArray();
185+
Assert.AreEqual(4, srArr.Length, "All reports length");
186+
187+
var srArrOrd = srArr.OrderBy(x => x.OperationType).ToArray();
188+
CollectionAssert.AreEqual(strArr1, srArrOrd[0].StatusData);
189+
CollectionAssert.AreEqual(strArr2, srArrOrd[1].StatusData);
190+
CollectionAssert.AreEqual(strArr3, srArrOrd[2].Errors);
191+
CollectionAssert.AreEqual(strArr4, srArrOrd[3].Errors);
192+
}
193+
}
194+
195+
public class BadSendReportBody : Model.SendReportBody
196+
{
197+
public new string JobId
198+
{ get; set; }
199+
200+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
201+
public new string OperationType
202+
{ get; set; }
203+
204+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
205+
public new string ReportFormatVersion
206+
{ get; set; }
207+
208+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
209+
public new string StartTime
210+
{ get; set; }
211+
212+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
213+
public new string Errors
214+
{ get; set; }
215+
216+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
217+
public new string StatusData
218+
{ get; set; }
219+
220+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
221+
public new string AdditionalData
222+
{ get; set; }
223+
}
224+
}
225+
}

0 commit comments

Comments
 (0)