aboutsummaryrefslogtreecommitdiff
path: root/src/test/dtf/SampleCA
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-03-31 11:56:14 -0700
committerRob Mensching <rob@firegiant.com>2022-03-31 18:01:06 -0700
commit47582b162368e8edf7a3b11c13b8e9dabc5f0a26 (patch)
tree2c4063eff325684bed39de0edacd7866a257ae02 /src/test/dtf/SampleCA
parent167296c42497c4e95f0d5d71168542d747655981 (diff)
downloadwix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.tar.gz
wix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.tar.bz2
wix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.zip
Provide managed CA and Embedded UI DTF libraries via NuGet
Lots of refactoring to bring the SFX tooling back into the 'dtf' layer since they are (in the end) tightly coupled to some DTF assemblies. Also refactored the DTF tests into their own folder and added a couple integration tests to build using the new CA/UI NuGet package. Closes wixtoolset/issues#6080
Diffstat (limited to 'src/test/dtf/SampleCA')
-rw-r--r--src/test/dtf/SampleCA/SampleCA.cs125
-rw-r--r--src/test/dtf/SampleCA/SampleCA.csproj10
2 files changed, 135 insertions, 0 deletions
diff --git a/src/test/dtf/SampleCA/SampleCA.cs b/src/test/dtf/SampleCA/SampleCA.cs
new file mode 100644
index 00000000..fc9f30fe
--- /dev/null
+++ b/src/test/dtf/SampleCA/SampleCA.cs
@@ -0,0 +1,125 @@
1namespace WixToolset.Samples
2{
3 using System;
4 using System.Collections.Generic;
5 using System.IO;
6 using WixToolset.Dtf.WindowsInstaller;
7
8 public class SampleCA
9 {
10 [CustomAction]
11 public static ActionResult SampleCA1(Session session)
12 {
13 using (Record msgRec = new Record(0))
14 {
15 msgRec[0] = "Hello from SampleCA1!" +
16 "\r\nCLR version is v" + Environment.Version;
17 session.Message(InstallMessage.Info, msgRec);
18 session.Message(InstallMessage.User, msgRec);
19 }
20
21 session.Log("Testing summary info...");
22 SummaryInfo summInfo = session.Database.SummaryInfo;
23 session.Log("MSI PackageCode = {0}", summInfo.RevisionNumber);
24 session.Log("MSI ModifyDate = {0}", summInfo.LastSaveTime);
25
26 string testProp = session["SampleCATest"];
27 session.Log("Simple property test: [SampleCATest]={0}.", testProp);
28
29 session.Log("Testing subdirectory extraction...");
30 string testFilePath = "testsub\\SampleCAs.cs";
31 if (!File.Exists(testFilePath))
32 {
33 session.Log("Subdirectory extraction failed. File not found: " + testFilePath);
34 return ActionResult.Failure;
35 }
36 else
37 {
38 session.Log("Found file extracted in subdirectory.");
39 }
40
41 session.Log("Testing record stream extraction...");
42 string tempFile = null;
43 try
44 {
45 tempFile = Path.GetTempFileName();
46 using (View binView = session.Database.OpenView(
47 "SELECT `Binary`.`Data` FROM `Binary`, `CustomAction` " +
48 "WHERE `CustomAction`.`Target` = 'SampleCA1' AND " +
49 "`CustomAction`.`Source` = `Binary`.`Name`"))
50 {
51 binView.Execute();
52 using (Record binRec = binView.Fetch())
53 {
54 binRec.GetStream(1, tempFile);
55 }
56 }
57
58 session.Log("CA binary file size: {0}", new FileInfo(tempFile).Length);
59 string binFileVersion = Installer.GetFileVersion(tempFile);
60 session.Log("CA binary file version: {0}", binFileVersion);
61 }
62 finally
63 {
64 if (tempFile != null && File.Exists(tempFile))
65 {
66 File.Delete(tempFile);
67 }
68 }
69
70 session.Log("Testing record stream reading...");
71 using (View binView2 = session.Database.OpenView("SELECT `Data` FROM `Binary` WHERE `Name` = 'TestData'"))
72 {
73 binView2.Execute();
74 using (Record binRec2 = binView2.Fetch())
75 {
76 Stream stream = binRec2.GetStream("Data");
77 string testData = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd();
78 session.Log("Test data: " + testData);
79 }
80 }
81
82 session.Log("Listing components");
83 using (View compView = session.Database.OpenView(
84 "SELECT `Component` FROM `Component`"))
85 {
86 compView.Execute();
87 foreach (Record compRec in compView)
88 {
89 using (compRec)
90 {
91 session.Log("\t{0}", compRec["Component"]);
92 }
93 }
94 }
95
96 session.Log("Testing the ability to access an external MSI database...");
97 string tempDbFile = Path.GetTempFileName();
98 using (Database tempDb = new Database(tempDbFile, DatabaseOpenMode.CreateDirect))
99 {
100 // Just create an empty database.
101 }
102 using (Database tempDb2 = new Database(tempDbFile))
103 {
104 // See if we can open and query the database.
105 IList<string> tables = tempDb2.ExecuteStringQuery("SELECT `Name` FROM `_Tables`");
106 session.Log("Found " + tables.Count + " tables in the newly created database.");
107 }
108 File.Delete(tempDbFile);
109
110 return ActionResult.Success;
111 }
112
113 [CustomAction("SampleCA2")]
114 public static ActionResult SampleCustomAction2(Session session)
115 {
116 using (Record msgRec = new Record(0))
117 {
118 msgRec[0] = "Hello from SampleCA2!";
119 session.Message(InstallMessage.Info, msgRec);
120 session.Message(InstallMessage.User, msgRec);
121 }
122 return ActionResult.UserExit;
123 }
124 }
125}
diff --git a/src/test/dtf/SampleCA/SampleCA.csproj b/src/test/dtf/SampleCA/SampleCA.csproj
new file mode 100644
index 00000000..fb6d8dca
--- /dev/null
+++ b/src/test/dtf/SampleCA/SampleCA.csproj
@@ -0,0 +1,10 @@
1<Project Sdk="Microsoft.NET.Sdk">
2 <PropertyGroup>
3 <TargetFramework>net472</TargetFramework>
4 <Description>Sample managed custom actions</Description>
5 </PropertyGroup>
6
7 <ItemGroup>
8 <PackageReference Include="WixToolset.Dtf.CustomAction" />
9 </ItemGroup>
10</Project>