main
cs 160 lines 5.88 KB
Raw
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
3 namespace WixToolsetTest.CoreIntegration
4 {
5 using System.IO;
6 using System.Linq;
7 using WixInternal.Core.TestPackage;
8 using WixInternal.TestSupport;
9 using WixToolset.Data;
10 using WixToolset.Data.Symbols;
11 using WixToolset.Data.WindowsInstaller;
12 using Xunit;
13
14 public class CommentsFixture
15 {
16 [Fact]
17 public void PackageNoSummaryInformation()
18 {
19 var propertyRows = BuildPackageAndQuerySummaryInformation("PackageNoSummaryInformation.wxs");
20
21 WixAssert.CompareLineByLine(new[]
22 {
23 "_SummaryInformation:Comments\tThis installer database contains the logic and data required to install MsiPackage."
24 }, propertyRows);
25 }
26
27 [Fact]
28 public void PackageDefaultComments()
29 {
30 var propertyRows = BuildPackageAndQuerySummaryInformation("PackageDefault.wxs");
31
32 WixAssert.CompareLineByLine(new[]
33 {
34 "_SummaryInformation:Comments\tThis installer database contains the logic and data required to install MsiPackage."
35 }, propertyRows);
36 }
37
38 [Fact]
39 public void PackageEmptyCommentsThrows()
40 {
41 var exception = Assert.Throws<WixException>(() => BuildPackageAndQuerySummaryInformation("PackageEmpty.wxs"));
42 WixAssert.StringEqual("The SummaryInformation/@Comments attribute's value cannot be an empty string. If a value is not required, simply remove the entire attribute.", exception.Message);
43 }
44
45 [Fact]
46 public void PackageCustomComments()
47 {
48 var propertyRows = BuildPackageAndQuerySummaryInformation("PackageCustom.wxs");
49
50 WixAssert.CompareLineByLine(new[]
51 {
52 "_SummaryInformation:Comments\tExample comments"
53 }, propertyRows);
54 }
55
56 [Fact]
57 public void ModuleNoSummaryInformation()
58 {
59 var propertyRows = BuildModuleAndQuerySummaryInformation("ModuleNoSummaryInformation.wxs");
60
61 WixAssert.CompareLineByLine(new[]
62 {
63 "_SummaryInformation:Comments\tThis merge module contains the logic and data required to install Module."
64 }, propertyRows);
65 }
66
67 [Fact]
68 public void ModuleDefaultComments()
69 {
70 var propertyRows = BuildModuleAndQuerySummaryInformation("ModuleDefault.wxs");
71
72 WixAssert.CompareLineByLine(new[]
73 {
74 "_SummaryInformation:Comments\tThis merge module contains the logic and data required to install Module."
75 }, propertyRows);
76 }
77
78 [Fact]
79 public void ModuleEmptyCommentsThrows()
80 {
81 var exception = Assert.Throws<WixException>(() => BuildModuleAndQuerySummaryInformation("ModuleEmpty.wxs"));
82 WixAssert.StringEqual("The SummaryInformation/@Comments attribute's value cannot be an empty string. If a value is not required, simply remove the entire attribute.", exception.Message);
83 }
84
85 [Fact]
86 public void ModuleCustomComments()
87 {
88 var propertyRows = BuildModuleAndQuerySummaryInformation("ModuleCustom.wxs");
89
90 WixAssert.CompareLineByLine(new[]
91 {
92 "_SummaryInformation:Comments\tExample comments"
93 }, propertyRows);
94 }
95
96 private static string[] BuildPackageAndQuerySummaryInformation(string file)
97 {
98 var folder = TestData.Get("TestData", "Comments");
99
100 using (var fs = new DisposableFileSystem())
101 {
102 var baseFolder = fs.GetFolder();
103 var intermediateFolder = Path.Combine(baseFolder, "obj");
104 var binFolder = Path.Combine(baseFolder, "bin");
105 var msiPath = Path.Combine(binFolder, "test.msi");
106
107 var result = WixRunner.Execute(new[]
108 {
109 "build",
110 Path.Combine(folder, file),
111 "-intermediateFolder", intermediateFolder,
112 "-bindpath", folder,
113 "-o", msiPath,
114 });
115
116 if(result.ExitCode != 0)
117 {
118 throw new WixException(result.Messages.First());
119 }
120
121 return Query.QueryDatabase(msiPath, new[] { "Property", "_SummaryInformation" })
122 .Where(s => s.StartsWith("_SummaryInformation:Comments"))
123 .OrderBy(s => s)
124 .ToArray();
125 }
126 }
127
128 private static string[] BuildModuleAndQuerySummaryInformation(string file)
129 {
130 var folder = TestData.Get("TestData", "Comments");
131
132 using (var fs = new DisposableFileSystem())
133 {
134 var baseFolder = fs.GetFolder();
135 var intermediateFolder = Path.Combine(baseFolder, "obj");
136 var binFolder = Path.Combine(baseFolder, "bin");
137 var msmPath = Path.Combine(binFolder, "test.msm");
138
139 var result = WixRunner.Execute(new[]
140 {
141 "build",
142 Path.Combine(folder, file),
143 "-intermediateFolder", intermediateFolder,
144 "-bindpath", Path.Combine(folder, "data"),
145 "-o", msmPath,
146 });
147
148 if (result.ExitCode != 0)
149 {
150 throw new WixException(result.Messages.First());
151 }
152
153 return Query.QueryDatabase(msmPath, new[] { "Property", "_SummaryInformation" })
154 .Where(s => s.StartsWith("_SummaryInformation:Comments"))
155 .OrderBy(s => s)
156 .ToArray();
157 }
158 }
159 }
160 }