aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-06-12 06:53:48 -0700
committerRob Mensching <rob@firegiant.com>2020-06-12 08:26:18 -0700
commitb123126f6c3511259e4520cc7151e9dce9c534bc (patch)
tree7b8c92826fd09759f755f36ee634b91afd46fe94 /src
parent71e3338346841dcd31f18dd715cfa106b2a6e548 (diff)
downloadwix-b123126f6c3511259e4520cc7151e9dce9c534bc.tar.gz
wix-b123126f6c3511259e4520cc7151e9dce9c534bc.tar.bz2
wix-b123126f6c3511259e4520cc7151e9dce9c534bc.zip
Extract common code to base class and use common mock messaging
Diffstat (limited to 'src')
-rw-r--r--src/test/WixToolsetTest.Converters/BaseConverterFixture.cs47
-rw-r--r--src/test/WixToolsetTest.Converters/ConverterFixture.cs95
-rw-r--r--src/test/WixToolsetTest.Converters/Mocks/MockMessaging.cs1
3 files changed, 69 insertions, 74 deletions
diff --git a/src/test/WixToolsetTest.Converters/BaseConverterFixture.cs b/src/test/WixToolsetTest.Converters/BaseConverterFixture.cs
new file mode 100644
index 00000000..e8eeb459
--- /dev/null
+++ b/src/test/WixToolsetTest.Converters/BaseConverterFixture.cs
@@ -0,0 +1,47 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolsetTest.Converters
4{
5 using System;
6 using System.IO;
7 using System.Text;
8 using System.Xml.Linq;
9 using Xunit;
10
11 public abstract class BaseConverterFixture
12 {
13 protected static string UnformattedDocumentString(XDocument document)
14 {
15 var sb = new StringBuilder();
16
17 using (var writer = new StringWriter(sb))
18 {
19 document.Save(writer, SaveOptions.DisableFormatting);
20 }
21
22 return sb.ToString();
23 }
24
25 protected static string[] UnformattedDocumentLines(XDocument document)
26 {
27 var sb = new StringBuilder();
28
29 using (var writer = new StringWriter(sb))
30 {
31 document.Save(writer, SaveOptions.DisableFormatting);
32 }
33
34 return sb.ToString().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
35 }
36
37 protected static void CompareLineByLine(string[] expectedLines, string[] actualLines)
38 {
39 for (var i = 0; i < expectedLines.Length; ++i)
40 {
41 Assert.True(actualLines.Length > i, $"{i}: Expected file longer than actual file");
42 Assert.Equal($"{i}: {expectedLines[i]}", $"{i}: {actualLines[i]}");
43 }
44 Assert.True(expectedLines.Length == actualLines.Length, "Actual file longer than expected file");
45 }
46 }
47}
diff --git a/src/test/WixToolsetTest.Converters/ConverterFixture.cs b/src/test/WixToolsetTest.Converters/ConverterFixture.cs
index c6037787..7a39b0c6 100644
--- a/src/test/WixToolsetTest.Converters/ConverterFixture.cs
+++ b/src/test/WixToolsetTest.Converters/ConverterFixture.cs
@@ -3,16 +3,12 @@
3namespace WixToolsetTest.Converters 3namespace WixToolsetTest.Converters
4{ 4{
5 using System; 5 using System;
6 using System.IO;
7 using System.Text;
8 using System.Xml.Linq; 6 using System.Xml.Linq;
9 using WixToolset.Converters; 7 using WixToolset.Converters;
10 using WixToolset.Data; 8 using WixToolsetTest.Converters.Mocks;
11 using WixToolset.Extensibility;
12 using WixToolset.Extensibility.Services;
13 using Xunit; 9 using Xunit;
14 10
15 public class ConverterFixture 11 public class ConverterFixture : BaseConverterFixture
16 { 12 {
17 private static readonly XNamespace Wix4Namespace = "http://wixtoolset.org/schemas/v4/wxs"; 13 private static readonly XNamespace Wix4Namespace = "http://wixtoolset.org/schemas/v4/wxs";
18 14
@@ -32,7 +28,7 @@ namespace WixToolsetTest.Converters
32 28
33 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 29 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
34 30
35 var messaging = new DummyMessaging(); 31 var messaging = new MockMessaging();
36 var converter = new Wix3Converter(messaging, 2, null, null); 32 var converter = new Wix3Converter(messaging, 2, null, null);
37 33
38 var errors = converter.ConvertDocument(document); 34 var errors = converter.ConvertDocument(document);
@@ -54,7 +50,7 @@ namespace WixToolsetTest.Converters
54 50
55 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 51 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
56 52
57 var messaging = new DummyMessaging(); 53 var messaging = new MockMessaging();
58 var converter = new Wix3Converter(messaging, 4, null, null); 54 var converter = new Wix3Converter(messaging, 4, null, null);
59 55
60 var errors = converter.ConvertDocument(document); 56 var errors = converter.ConvertDocument(document);
@@ -87,7 +83,7 @@ namespace WixToolsetTest.Converters
87 83
88 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 84 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
89 85
90 var messaging = new DummyMessaging(); 86 var messaging = new MockMessaging();
91 var converter = new Wix3Converter(messaging, 4, null, null); 87 var converter = new Wix3Converter(messaging, 4, null, null);
92 88
93 var errors = converter.ConvertDocument(document); 89 var errors = converter.ConvertDocument(document);
@@ -123,7 +119,7 @@ namespace WixToolsetTest.Converters
123 119
124 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 120 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
125 121
126 var messaging = new DummyMessaging(); 122 var messaging = new MockMessaging();
127 var converter = new Wix3Converter(messaging, 4, null, null); 123 var converter = new Wix3Converter(messaging, 4, null, null);
128 124
129 var conversions = converter.ConvertDocument(document); 125 var conversions = converter.ConvertDocument(document);
@@ -161,7 +157,7 @@ namespace WixToolsetTest.Converters
161 157
162 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 158 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
163 159
164 var messaging = new DummyMessaging(); 160 var messaging = new MockMessaging();
165 var converter = new Wix3Converter(messaging, 4, null, null); 161 var converter = new Wix3Converter(messaging, 4, null, null);
166 162
167 var conversions = converter.ConvertDocument(document); 163 var conversions = converter.ConvertDocument(document);
@@ -195,7 +191,7 @@ namespace WixToolsetTest.Converters
195 191
196 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 192 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
197 193
198 var messaging = new DummyMessaging(); 194 var messaging = new MockMessaging();
199 var converter = new Wix3Converter(messaging, 2, null, null); 195 var converter = new Wix3Converter(messaging, 2, null, null);
200 196
201 var errors = converter.ConvertDocument(document); 197 var errors = converter.ConvertDocument(document);
@@ -231,7 +227,7 @@ namespace WixToolsetTest.Converters
231 227
232 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 228 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
233 229
234 var messaging = new DummyMessaging(); 230 var messaging = new MockMessaging();
235 var converter = new Wix3Converter(messaging, 2, null, null); 231 var converter = new Wix3Converter(messaging, 2, null, null);
236 232
237 var errors = converter.ConvertDocument(document); 233 var errors = converter.ConvertDocument(document);
@@ -255,7 +251,7 @@ namespace WixToolsetTest.Converters
255 251
256 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 252 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
257 253
258 var messaging = new DummyMessaging(); 254 var messaging = new MockMessaging();
259 var converter = new Wix3Converter(messaging, 2, null, null); 255 var converter = new Wix3Converter(messaging, 2, null, null);
260 var errors = converter.ConvertDocument(document); 256 var errors = converter.ConvertDocument(document);
261 Assert.Equal(0, errors); 257 Assert.Equal(0, errors);
@@ -278,7 +274,7 @@ namespace WixToolsetTest.Converters
278 274
279 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 275 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
280 276
281 var messaging = new DummyMessaging(); 277 var messaging = new MockMessaging();
282 var converter = new Wix3Converter(messaging, 2, null, null); 278 var converter = new Wix3Converter(messaging, 2, null, null);
283 279
284 var errors = converter.ConvertDocument(document); 280 var errors = converter.ConvertDocument(document);
@@ -307,7 +303,7 @@ namespace WixToolsetTest.Converters
307 303
308 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 304 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
309 305
310 var messaging = new DummyMessaging(); 306 var messaging = new MockMessaging();
311 var converter = new Wix3Converter(messaging, 2, null, null); 307 var converter = new Wix3Converter(messaging, 2, null, null);
312 308
313 var errors = converter.ConvertDocument(document); 309 var errors = converter.ConvertDocument(document);
@@ -340,7 +336,7 @@ namespace WixToolsetTest.Converters
340 336
341 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 337 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
342 338
343 var messaging = new DummyMessaging(); 339 var messaging = new MockMessaging();
344 var converter = new Wix3Converter(messaging, 2, null, null); 340 var converter = new Wix3Converter(messaging, 2, null, null);
345 341
346 var errors = converter.ConvertDocument(document); 342 var errors = converter.ConvertDocument(document);
@@ -370,7 +366,7 @@ namespace WixToolsetTest.Converters
370 366
371 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 367 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
372 368
373 var messaging = new DummyMessaging(); 369 var messaging = new MockMessaging();
374 var converter = new Wix3Converter(messaging, 2, null, null); 370 var converter = new Wix3Converter(messaging, 2, null, null);
375 371
376 var errors = converter.ConvertDocument(document); 372 var errors = converter.ConvertDocument(document);
@@ -399,7 +395,7 @@ namespace WixToolsetTest.Converters
399 395
400 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 396 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
401 397
402 var messaging = new DummyMessaging(); 398 var messaging = new MockMessaging();
403 var converter = new Wix3Converter(messaging, 2, null, null); 399 var converter = new Wix3Converter(messaging, 2, null, null);
404 400
405 var errors = converter.ConvertDocument(document); 401 var errors = converter.ConvertDocument(document);
@@ -438,7 +434,7 @@ namespace WixToolsetTest.Converters
438 434
439 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 435 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
440 436
441 var messaging = new DummyMessaging(); 437 var messaging = new MockMessaging();
442 var converter = new Wix3Converter(messaging, 2, null, null); 438 var converter = new Wix3Converter(messaging, 2, null, null);
443 439
444 var errors = converter.ConvertDocument(document); 440 var errors = converter.ConvertDocument(document);
@@ -467,7 +463,7 @@ namespace WixToolsetTest.Converters
467 463
468 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 464 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
469 465
470 var messaging = new DummyMessaging(); 466 var messaging = new MockMessaging();
471 var converter = new Wix3Converter(messaging, 2, null, null); 467 var converter = new Wix3Converter(messaging, 2, null, null);
472 468
473 var errors = converter.ConvertDocument(document); 469 var errors = converter.ConvertDocument(document);
@@ -495,7 +491,7 @@ namespace WixToolsetTest.Converters
495 491
496 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 492 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
497 493
498 var messaging = new DummyMessaging(); 494 var messaging = new MockMessaging();
499 var converter = new Wix3Converter(messaging, 2, null, null); 495 var converter = new Wix3Converter(messaging, 2, null, null);
500 496
501 var errors = converter.ConvertDocument(document); 497 var errors = converter.ConvertDocument(document);
@@ -523,7 +519,7 @@ namespace WixToolsetTest.Converters
523 519
524 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 520 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
525 521
526 var messaging = new DummyMessaging(); 522 var messaging = new MockMessaging();
527 var converter = new Wix3Converter(messaging, 2, null, null); 523 var converter = new Wix3Converter(messaging, 2, null, null);
528 524
529 var errors = converter.ConvertDocument(document); 525 var errors = converter.ConvertDocument(document);
@@ -551,7 +547,7 @@ namespace WixToolsetTest.Converters
551 547
552 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 548 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
553 549
554 var messaging = new DummyMessaging(); 550 var messaging = new MockMessaging();
555 var converter = new Wix3Converter(messaging, 2, null, null); 551 var converter = new Wix3Converter(messaging, 2, null, null);
556 552
557 var errors = converter.ConvertDocument(document); 553 var errors = converter.ConvertDocument(document);
@@ -579,7 +575,7 @@ namespace WixToolsetTest.Converters
579 575
580 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 576 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
581 577
582 var messaging = new DummyMessaging(); 578 var messaging = new MockMessaging();
583 var converter = new Wix3Converter(messaging, 2, null, null); 579 var converter = new Wix3Converter(messaging, 2, null, null);
584 580
585 var errors = converter.ConvertDocument(document); 581 var errors = converter.ConvertDocument(document);
@@ -613,7 +609,7 @@ namespace WixToolsetTest.Converters
613 609
614 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); 610 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
615 611
616 var messaging = new DummyMessaging(); 612 var messaging = new MockMessaging();
617 var converter = new Wix3Converter(messaging, 2, null, null); 613 var converter = new Wix3Converter(messaging, 2, null, null);
618 614
619 var errors = converter.ConvertDocument(document); 615 var errors = converter.ConvertDocument(document);
@@ -623,52 +619,5 @@ namespace WixToolsetTest.Converters
623 Assert.Equal(6, errors); 619 Assert.Equal(6, errors);
624 Assert.Equal(expected, actual); 620 Assert.Equal(expected, actual);
625 } 621 }
626
627 private static string UnformattedDocumentString(XDocument document)
628 {
629 var sb = new StringBuilder();
630
631 using (var writer = new StringWriter(sb))
632 {
633 document.Save(writer, SaveOptions.DisableFormatting);
634 }
635
636 return sb.ToString();
637 }
638
639 private class DummyMessaging : IMessaging
640 {
641 public bool EncounteredError { get; set; }
642
643 public int LastErrorNumber { get; set; }
644
645 public bool ShowVerboseMessages { get; set; }
646
647 public bool SuppressAllWarnings { get; set; }
648
649 public bool WarningsAsError { get; set; }
650
651 public void ElevateWarningMessage(int warningNumber)
652 {
653 }
654
655 public string FormatMessage(Message message) => String.Empty;
656
657 public void SetListener(IMessageListener listener)
658 {
659 }
660
661 public void SuppressWarningMessage(int warningNumber)
662 {
663 }
664
665 public void Write(Message message)
666 {
667 }
668
669 public void Write(string message, bool verbose = false)
670 {
671 }
672 }
673 } 622 }
674} 623}
diff --git a/src/test/WixToolsetTest.Converters/Mocks/MockMessaging.cs b/src/test/WixToolsetTest.Converters/Mocks/MockMessaging.cs
index 8f7d4100..77821a1c 100644
--- a/src/test/WixToolsetTest.Converters/Mocks/MockMessaging.cs
+++ b/src/test/WixToolsetTest.Converters/Mocks/MockMessaging.cs
@@ -4,7 +4,6 @@ namespace WixToolsetTest.Converters.Mocks
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.Text;
8 using WixToolset.Data; 7 using WixToolset.Data;
9 using WixToolset.Extensibility; 8 using WixToolset.Extensibility;
10 using WixToolset.Extensibility.Services; 9 using WixToolset.Extensibility.Services;