private void InitLinqTestDatabase(QDatabase db) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); db.Execute( "INSERT INTO `Feature` (`Feature`, `Title`, `Description`, `Level`, `Attributes`) VALUES ('{0}', '{1}', '{2}', {3}, {4})", "TestFeature2", "Test Feature 2", "Test Feature 2 Description", 1, (int)FeatureAttributes.None); WindowsInstallerUtils.AddRegistryComponent( db, "TestFeature2", "MyTestRegComp", Guid.NewGuid().ToString("B"), "SOFTWARE\\Microsoft\\DTF\\Test", "MyTestRegComp", "test"); WindowsInstallerUtils.AddRegistryComponent( db, "TestFeature2", "MyTestRegComp2", Guid.NewGuid().ToString("B"), "SOFTWARE\\Microsoft\\DTF\\Test", "MyTestRegComp2", "test2"); WindowsInstallerUtils.AddRegistryComponent( db, "TestFeature2", "excludeComp", Guid.NewGuid().ToString("B"), "SOFTWARE\\Microsoft\\DTF\\Test", "MyTestRegComp3", "test3"); db.Commit(); db.Log = Console.Out; }
public void InstallerDatabaseSchema() { string dbFile = "InstallerDatabaseSchema.msi"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); db.Commit(); } Assert.IsTrue(File.Exists(dbFile), "Checking whether created database file " + dbFile + " exists."); using (Database db = new Database(dbFile, DatabaseOpenMode.ReadOnly)) { TableCollection tables = db.Tables; Assert.AreEqual <int>(Schema.Tables.Count, tables.Count, "Counting tables."); Assert.AreEqual <int>(Schema.Property.Columns.Count, tables["Property"].Columns.Count, "Counting columns in Property table."); foreach (TableInfo tableInfo in tables) { Console.WriteLine(tableInfo.Name); foreach (ColumnInfo columnInfo in tableInfo.Columns) { Console.WriteLine("\t{0} {1}", columnInfo.Name, columnInfo.ColumnDefinitionString); } } } }
public void SeekRecordThenTryFormatString() { string dbFile = "SeekRecordThenTryFormatString.msi"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); string parameterFormatString = "[1]"; string[] properties = new string[] { "SonGoku", "Over 9000", }; string query = "SELECT `Property`, `Value` FROM `Property`"; using (View view = db.OpenView(query)) { using (Record rec = new Record(2)) { rec[1] = properties[0]; rec[2] = properties[1]; rec.FormatString = parameterFormatString; Console.WriteLine("Record fields before seeking: " + rec[0] + " " + rec[1] + " " + rec[2]); view.Seek(rec); //TODO: Why does view.Seek remove the record fields? Console.WriteLine("Record fields after seeking: " + rec[0] + " " + rec[1] + " " + rec[2]); // After inserting, the format string is invalid. Assert.AreEqual(String.Empty, rec.ToString()); } } } }
public void DeleteRecord() { string dbFile = "DeleteRecord.msi"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); string query = "SELECT `Property`, `Value` FROM `Property` WHERE `Property` = 'UpgradeCode'"; using (View view = db.OpenView(query)) { view.Execute(); Record rec = view.Fetch(); Console.WriteLine("Calling ToString() : " + rec); view.Delete(rec); } Assert.AreEqual(0, db.ExecuteStringQuery(query).Count); } }
private void CreateCustomActionProduct( string msiFile, string customActionFile, IList <string> customActions, bool sixtyFourBit) { using (Database db = new Database(msiFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db, sixtyFourBit); WindowsInstallerUtils.CreateTestProduct(db); if (!File.Exists(customActionFile)) { throw new FileNotFoundException(customActionFile); } using (Record binRec = new Record(2)) { binRec[1] = Path.GetFileName(customActionFile); binRec.SetStream(2, customActionFile); db.Execute("INSERT INTO `Binary` (`Name`, `Data`) VALUES (?, ?)", binRec); } using (Record binRec2 = new Record(2)) { binRec2[1] = "TestData"; binRec2.SetStream(2, new MemoryStream(Encoding.UTF8.GetBytes("This is a test data stream."))); db.Execute("INSERT INTO `Binary` (`Name`, `Data`) VALUES (?, ?)", binRec2); } for (int i = 0; i < customActions.Count; i++) { db.Execute( "INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) VALUES ('{0}', 1, '{1}', '{2}')", customActions[i], Path.GetFileName(customActionFile), customActions[i]); db.Execute( "INSERT INTO `InstallExecuteSequence` (`Action`, `Condition`, `Sequence`) VALUES ('{0}', '', {1})", customActions[i], 101 + i); } db.Execute("INSERT INTO `Property` (`Property`, `Value`) VALUES ('SampleCATest', 'TestValue')"); db.Commit(); } }
public void InstallerViewTables() { string dbFile = "InstallerViewTables.msi"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); db.Commit(); using (View view1 = db.OpenView("SELECT `Property`, `Value` FROM `Property` WHERE `Value` IS NOT NULL")) { IList <TableInfo> viewTables = view1.Tables; Assert.IsNotNull(viewTables); Assert.AreEqual <int>(1, viewTables.Count); Assert.AreEqual <String>("Property", viewTables[0].Name); } using (View view2 = db.OpenView("INSERT INTO `Property` (`Property`, `Value`) VALUES ('TestViewTables', 1)")) { IList <TableInfo> viewTables = view2.Tables; Assert.IsNotNull(viewTables); Assert.AreEqual <int>(1, viewTables.Count); Assert.AreEqual <String>("Property", viewTables[0].Name); } using (View view3 = db.OpenView("UPDATE `Property` SET `Value` = 2 WHERE `Property` = 'TestViewTables'")) { IList <TableInfo> viewTables = view3.Tables; Assert.IsNotNull(viewTables); Assert.AreEqual <int>(1, viewTables.Count); Assert.AreEqual <String>("Property", viewTables[0].Name); } using (View view4 = db.OpenView("alter table Property hold")) { IList <TableInfo> viewTables = view4.Tables; Assert.IsNotNull(viewTables); Assert.AreEqual <int>(1, viewTables.Count); Assert.AreEqual <String>("Property", viewTables[0].Name); } } }
public void DatabaseAsQueryable() { using (Database db = new Database("testlinq.msi", DatabaseOpenMode.Create)) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); var comps = from c in db.AsQueryable().Components select c; int count = 0; foreach (var c in comps) { Console.WriteLine(c); count++; } Assert.AreEqual <int>(1, count); } }
public void InsertRecordThenTryFormatString() { string dbFile = "InsertRecordThenTryFormatString.msi"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); string parameterFormatString = "[1]"; string[] properties = new string[] { "SonGoku", "Over 9000", }; string query = "SELECT `Property`, `Value` FROM `Property`"; using (View view = db.OpenView(query)) { using (Record rec = new Record(2)) { rec[1] = properties[0]; rec[2] = properties[1]; rec.FormatString = parameterFormatString; Console.WriteLine("Format String before inserting: " + rec.FormatString); view.Insert(rec); Console.WriteLine("Format String after inserting: " + rec.FormatString); // After inserting, the format string is invalid. Assert.AreEqual(String.Empty, rec.ToString()); // Setting the format string manually makes it valid again. rec.FormatString = parameterFormatString; Assert.AreEqual(properties[0], rec.ToString()); } } } }
public void EmbeddedUISingleInstall() { string dbFile = "EmbeddedUISingleInstall.msi"; string productCode; string uiDir = Path.GetFullPath(EmbeddedExternalUI.EmbeddedUISampleBinDir); string uiFile = "Microsoft.Deployment.Samples.EmbeddedUI.dll"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); productCode = db.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0]; using (Record uiRec = new Record(5)) { uiRec[1] = "TestEmbeddedUI"; uiRec[2] = Path.GetFileNameWithoutExtension(uiFile) + ".Wrapper.dll"; uiRec[3] = 1; uiRec[4] = (int)( EmbeddedExternalUI.TestLogModes | InstallLogModes.Progress | InstallLogModes.Initialize | InstallLogModes.Terminate | InstallLogModes.ShowDialog); uiRec.SetStream(5, Path.Combine(uiDir, uiFile)); db.Execute(db.Tables["MsiEmbeddedUI"].SqlInsertString, uiRec); } db.Commit(); } Installer.SetInternalUI(InstallUIOptions.Full); ProductInstallation installation = new ProductInstallation(productCode); Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed before starting."); Exception caughtEx = null; try { Installer.EnableLog(EmbeddedExternalUI.TestLogModes, "install.log"); Installer.InstallProduct(dbFile, String.Empty); } catch (Exception ex) { caughtEx = ex; } Assert.IsNull(caughtEx, "Exception thrown while installing product: " + caughtEx); Assert.IsTrue(installation.IsInstalled, "Checking that product is installed."); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("==================================================================="); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); try { Installer.EnableLog(EmbeddedExternalUI.TestLogModes, "uninstall.log"); Installer.InstallProduct(dbFile, "REMOVE=All"); } catch (Exception ex) { caughtEx = ex; } Assert.IsNull(caughtEx, "Exception thrown while uninstalling product: " + caughtEx); }
// This test does not pass if run normally. // It only passes when a failure is injected into the EmbeddedUI launcher. ////[TestMethod] public void EmbeddedUIInitializeFails() { string dbFile = "EmbeddedUIInitializeFails.msi"; string productCode; string uiDir = Path.GetFullPath(EmbeddedExternalUI.EmbeddedUISampleBinDir); string uiFile = "Microsoft.Deployment.Samples.EmbeddedUI.dll"; // A number that will be used to check whether a type 19 CA runs. const string magicNumber = "3.14159265358979323846264338327950"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); const string failureActionName = "EmbeddedUIInitializeFails"; db.Execute("INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) " + "VALUES ('{0}', 19, '', 'Logging magic number: {1}')", failureActionName, magicNumber); // This type 19 CA (launch condition) is given a condition of 'UILevel = 3' so that it only runs if the // installation is running in BASIC UI mode, which is what we expect if the EmbeddedUI fails to initialize. db.Execute("INSERT INTO `InstallExecuteSequence` (`Action`, `Condition`, `Sequence`) " + "VALUES ('{0}', 'UILevel = 3', 1)", failureActionName); productCode = db.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0]; using (Record uiRec = new Record(5)) { uiRec[1] = "TestEmbeddedUI"; uiRec[2] = Path.GetFileNameWithoutExtension(uiFile) + ".Wrapper.dll"; uiRec[3] = 1; uiRec[4] = (int)( EmbeddedExternalUI.TestLogModes | InstallLogModes.Progress | InstallLogModes.Initialize | InstallLogModes.Terminate | InstallLogModes.ShowDialog); uiRec.SetStream(5, Path.Combine(uiDir, uiFile)); db.Execute(db.Tables["MsiEmbeddedUI"].SqlInsertString, uiRec); } db.Commit(); } Installer.SetInternalUI(InstallUIOptions.Full); ProductInstallation installation = new ProductInstallation(productCode); Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed before starting."); string logFile = "install.log"; Exception caughtEx = null; try { Installer.EnableLog(EmbeddedExternalUI.TestLogModes, logFile); Installer.InstallProduct(dbFile, String.Empty); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(InstallerException), "Excpected InstallerException installing product; caught: " + caughtEx); Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed."); string logText = File.ReadAllText(logFile); Assert.IsTrue(logText.Contains(magicNumber), "Checking that the type 19 custom action ran."); }
public void InstallerInstallProduct() { string dbFile = "InstallerInstallProduct.msi"; string productCode; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); productCode = db.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0]; db.Commit(); } ProductInstallation installation = new ProductInstallation(productCode); Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed before starting."); Installer.SetInternalUI(InstallUIOptions.Silent); ExternalUIHandler prevHandler = Installer.SetExternalUI(WindowsInstallerTest.ExternalUILogger, InstallLogModes.FatalExit | InstallLogModes.Error | InstallLogModes.Warning | InstallLogModes.User | InstallLogModes.Info | InstallLogModes.ResolveSource | InstallLogModes.OutOfDiskSpace | InstallLogModes.ActionStart | InstallLogModes.ActionData | InstallLogModes.CommonData | InstallLogModes.Progress | InstallLogModes.Initialize | InstallLogModes.Terminate | InstallLogModes.ShowDialog); Assert.IsNull(prevHandler, "Checking that returned previous UI handler is null."); Exception caughtEx = null; try { Installer.InstallProduct(dbFile, String.Empty); } catch (Exception ex) { caughtEx = ex; } Assert.IsNull(caughtEx, "Exception thrown while installing product: " + caughtEx); prevHandler = Installer.SetExternalUI(prevHandler, InstallLogModes.None); Assert.AreEqual <ExternalUIHandler>(WindowsInstallerTest.ExternalUILogger, prevHandler, "Checking that previously-set UI handler is returned."); Assert.IsTrue(installation.IsInstalled, "Checking that product is installed."); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("==================================================================="); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); ExternalUIRecordHandler prevRecHandler = Installer.SetExternalUI(WindowsInstallerTest.ExternalUIRecordLogger, InstallLogModes.FatalExit | InstallLogModes.Error | InstallLogModes.Warning | InstallLogModes.User | InstallLogModes.Info | InstallLogModes.ResolveSource | InstallLogModes.OutOfDiskSpace | InstallLogModes.ActionStart | InstallLogModes.ActionData | InstallLogModes.CommonData | InstallLogModes.Progress | InstallLogModes.Initialize | InstallLogModes.Terminate | InstallLogModes.ShowDialog); Assert.IsNull(prevRecHandler, "Checking that returned previous UI record handler is null."); try { Installer.InstallProduct(dbFile, "REMOVE=All"); } catch (Exception ex) { caughtEx = ex; } Assert.IsNull(caughtEx, "Exception thrown while installing product: " + caughtEx); Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed after removing."); prevRecHandler = Installer.SetExternalUI(prevRecHandler, InstallLogModes.None); Assert.AreEqual <ExternalUIRecordHandler>(WindowsInstallerTest.ExternalUIRecordLogger, prevRecHandler, "Checking that previously-set UI record handler is returned."); }