diff options
Diffstat (limited to '')
-rw-r--r-- | src/dtf/WixToolsetTests.Dtf.WindowsInstaller/WindowsInstallerTransactions.cs | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/src/dtf/WixToolsetTests.Dtf.WindowsInstaller/WindowsInstallerTransactions.cs b/src/dtf/WixToolsetTests.Dtf.WindowsInstaller/WindowsInstallerTransactions.cs new file mode 100644 index 00000000..3bdf5acd --- /dev/null +++ b/src/dtf/WixToolsetTests.Dtf.WindowsInstaller/WindowsInstallerTransactions.cs | |||
@@ -0,0 +1,161 @@ | |||
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 WixToolset.Dtf.Test | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using System.Windows.Forms; | ||
8 | using System.Globalization; | ||
9 | using System.Collections.Generic; | ||
10 | using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
11 | using WixToolset.Dtf.WindowsInstaller; | ||
12 | using View = WixToolset.Dtf.WindowsInstaller.View; | ||
13 | |||
14 | [TestClass] | ||
15 | public class WindowsInstallerTransactions | ||
16 | { | ||
17 | [TestInitialize()] | ||
18 | public void Initialize() | ||
19 | { | ||
20 | } | ||
21 | |||
22 | [TestCleanup()] | ||
23 | public void Cleanup() | ||
24 | { | ||
25 | } | ||
26 | |||
27 | [TestMethod] | ||
28 | [Ignore] // Requires elevation. | ||
29 | public void InstallerTransactTwoProducts() | ||
30 | { | ||
31 | string dbFile1 = "InstallerTransactProduct1.msi"; | ||
32 | string dbFile2 = "InstallerTransactProduct2.msi"; | ||
33 | string productCode1; | ||
34 | string productCode2; | ||
35 | |||
36 | using (Database db1 = new Database(dbFile1, DatabaseOpenMode.CreateDirect)) | ||
37 | { | ||
38 | WindowsInstallerUtils.InitializeProductDatabase(db1); | ||
39 | WindowsInstallerUtils.CreateTestProduct(db1); | ||
40 | |||
41 | productCode1 = db1.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0]; | ||
42 | |||
43 | db1.Commit(); | ||
44 | } | ||
45 | |||
46 | using (Database db2 = new Database(dbFile2, DatabaseOpenMode.CreateDirect)) | ||
47 | { | ||
48 | WindowsInstallerUtils.InitializeProductDatabase(db2); | ||
49 | WindowsInstallerUtils.CreateTestProduct(db2); | ||
50 | |||
51 | productCode2 = db2.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0]; | ||
52 | |||
53 | db2.Commit(); | ||
54 | } | ||
55 | |||
56 | ProductInstallation installation1 = new ProductInstallation(productCode1); | ||
57 | ProductInstallation installation2 = new ProductInstallation(productCode2); | ||
58 | Assert.IsFalse(installation1.IsInstalled, "Checking that product 1 is not installed before starting."); | ||
59 | Assert.IsFalse(installation2.IsInstalled, "Checking that product 2 is not installed before starting."); | ||
60 | |||
61 | Installer.SetInternalUI(InstallUIOptions.Silent); | ||
62 | ExternalUIHandler prevHandler = Installer.SetExternalUI(WindowsInstallerTest.ExternalUILogger, | ||
63 | InstallLogModes.FatalExit | | ||
64 | InstallLogModes.Error | | ||
65 | InstallLogModes.Warning | | ||
66 | InstallLogModes.User | | ||
67 | InstallLogModes.Info | | ||
68 | InstallLogModes.ResolveSource | | ||
69 | InstallLogModes.OutOfDiskSpace | | ||
70 | InstallLogModes.ActionStart | | ||
71 | InstallLogModes.ActionData | | ||
72 | InstallLogModes.CommonData | | ||
73 | InstallLogModes.Progress | | ||
74 | InstallLogModes.Initialize | | ||
75 | InstallLogModes.Terminate | | ||
76 | InstallLogModes.ShowDialog); | ||
77 | Assert.IsNull(prevHandler, "Checking that returned previous UI handler is null."); | ||
78 | |||
79 | Transaction transaction = new Transaction("TestInstallTransaction", TransactionAttributes.None); | ||
80 | |||
81 | Exception caughtEx = null; | ||
82 | try | ||
83 | { | ||
84 | Installer.InstallProduct(dbFile1, String.Empty); | ||
85 | } | ||
86 | catch (Exception ex) { caughtEx = ex; } | ||
87 | Assert.IsNull(caughtEx, "Exception thrown while installing product 1: " + caughtEx); | ||
88 | |||
89 | Console.WriteLine(); | ||
90 | Console.WriteLine("==================================================================="); | ||
91 | Console.WriteLine(); | ||
92 | |||
93 | try | ||
94 | { | ||
95 | Installer.InstallProduct(dbFile2, String.Empty); | ||
96 | } | ||
97 | catch (Exception ex) { caughtEx = ex; } | ||
98 | Assert.IsNull(caughtEx, "Exception thrown while installing product 2: " + caughtEx); | ||
99 | |||
100 | transaction.Commit(); | ||
101 | transaction.Close(); | ||
102 | |||
103 | prevHandler = Installer.SetExternalUI(prevHandler, InstallLogModes.None); | ||
104 | Assert.AreEqual<ExternalUIHandler>(WindowsInstallerTest.ExternalUILogger, prevHandler, "Checking that previously-set UI handler is returned."); | ||
105 | |||
106 | Assert.IsTrue(installation1.IsInstalled, "Checking that product 1 is installed."); | ||
107 | Assert.IsTrue(installation2.IsInstalled, "Checking that product 2 is installed."); | ||
108 | |||
109 | Console.WriteLine(); | ||
110 | Console.WriteLine(); | ||
111 | Console.WriteLine(); | ||
112 | Console.WriteLine("==================================================================="); | ||
113 | Console.WriteLine("==================================================================="); | ||
114 | Console.WriteLine(); | ||
115 | Console.WriteLine(); | ||
116 | Console.WriteLine(); | ||
117 | |||
118 | ExternalUIRecordHandler prevRecHandler = Installer.SetExternalUI(WindowsInstallerTest.ExternalUIRecordLogger, | ||
119 | InstallLogModes.FatalExit | | ||
120 | InstallLogModes.Error | | ||
121 | InstallLogModes.Warning | | ||
122 | InstallLogModes.User | | ||
123 | InstallLogModes.Info | | ||
124 | InstallLogModes.ResolveSource | | ||
125 | InstallLogModes.OutOfDiskSpace | | ||
126 | InstallLogModes.ActionStart | | ||
127 | InstallLogModes.ActionData | | ||
128 | InstallLogModes.CommonData | | ||
129 | InstallLogModes.Progress | | ||
130 | InstallLogModes.Initialize | | ||
131 | InstallLogModes.Terminate | | ||
132 | InstallLogModes.ShowDialog); | ||
133 | Assert.IsNull(prevRecHandler, "Checking that returned previous UI record handler is null."); | ||
134 | |||
135 | transaction = new Transaction("TestUninstallTransaction", TransactionAttributes.None); | ||
136 | |||
137 | try | ||
138 | { | ||
139 | Installer.InstallProduct(dbFile1, "REMOVE=All"); | ||
140 | } | ||
141 | catch (Exception ex) { caughtEx = ex; } | ||
142 | Assert.IsNull(caughtEx, "Exception thrown while removing product 1: " + caughtEx); | ||
143 | |||
144 | try | ||
145 | { | ||
146 | Installer.InstallProduct(dbFile2, "REMOVE=All"); | ||
147 | } | ||
148 | catch (Exception ex) { caughtEx = ex; } | ||
149 | Assert.IsNull(caughtEx, "Exception thrown while removing product 2: " + caughtEx); | ||
150 | |||
151 | transaction.Commit(); | ||
152 | transaction.Close(); | ||
153 | |||
154 | Assert.IsFalse(installation1.IsInstalled, "Checking that product 1 is not installed after removing."); | ||
155 | Assert.IsFalse(installation2.IsInstalled, "Checking that product 2 is not installed after removing."); | ||
156 | |||
157 | prevRecHandler = Installer.SetExternalUI(prevRecHandler, InstallLogModes.None); | ||
158 | Assert.AreEqual<ExternalUIRecordHandler>(WindowsInstallerTest.ExternalUIRecordLogger, prevRecHandler, "Checking that previously-set UI record handler is returned."); | ||
159 | } | ||
160 | } | ||
161 | } | ||