EmbeddedExternalUI.cs :  » Installers-Generators » WiX » Microsoft » Deployment » Test » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Installers Generators » WiX 
WiX » Microsoft » Deployment » Test » EmbeddedExternalUI.cs
//---------------------------------------------------------------------
// <copyright file="EmbeddedExternalUI.cs" company="Microsoft">
//    Copyright (c) Microsoft Corporation.  All rights reserved.
//    
//    The use and distribution terms for this software are covered by the
//    Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
//    which can be found in the file CPL.TXT at the root of this distribution.
//    By using this software in any fashion, you are agreeing to be bound by
//    the terms of this license.
//    
//    You must not remove this notice, or any other, from this software.
// </copyright>
// <summary>
// Part of the Deployment Tools Foundation tests.
// </summary>
//---------------------------------------------------------------------

namespace Microsoft.Deployment.Test{
    using System;
    using System.IO;
    using System.Reflection;
    using System.Windows.Forms;
    using System.Globalization;
    using System.Collections.Generic;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Microsoft.Deployment.WindowsInstaller;
    using View = Microsoft.Deployment.WindowsInstaller.View;

    [TestClass]
    public class EmbeddedExternalUI
    {
        const InstallLogModes TestLogModes =
                InstallLogModes.FatalExit |
                InstallLogModes.Error |
                InstallLogModes.Warning |
                InstallLogModes.User |
                InstallLogModes.Info |
                InstallLogModes.ResolveSource |
                InstallLogModes.OutOfDiskSpace |
                InstallLogModes.ActionStart |
                InstallLogModes.ActionData |
                InstallLogModes.CommonData;

#if DEBUG
        const string EmbeddedUISampleBinDir = @"..\..\..\..\..\build\debug\x86\";
#else
        const string EmbeddedUISampleBinDir = @"..\..\..\..\..\build\ship\x86\";
#endif

        [TestMethod]
        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.");
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.