public void EverythingSimulationTest()
        {
            Stream everythingConfigStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                "RemoteInstallUnitTests.TestConfigs.Everything.config");

            string configFileName = Path.GetTempFileName();

            using (StreamReader everythingConfigReader = new StreamReader(everythingConfigStream))
            {
                File.WriteAllText(configFileName, everythingConfigReader.ReadToEnd());
            }

            Stream everythingXmlStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                "RemoteInstallUnitTests.TestConfigs.EverythingTask.xml");

            using (StreamReader everythingXmlReader = new StreamReader(everythingXmlStream))
            {
                File.WriteAllText(Path.Combine(Path.GetDirectoryName(configFileName), "EverythingTask.xml"),
                    everythingXmlReader.ReadToEnd());
            }

            string outputDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            Directory.CreateDirectory(outputDir);

            NameValueCollection vars = new NameValueCollection();
            vars["root"] = @"..\..\..\..";

            Driver driver = new Driver(
                outputDir,
                true,
                configFileName,
                vars,
                1);

            // save results
            Results results = new Results();
            results.AddRange(driver.Run());
            string xmlFileName = Path.Combine(outputDir, "Results.xml");
            new ResultCollectionXmlWriter().Write(results, xmlFileName);
            // make sure results is a valid xml document with a number of results
            XmlDocument xmlResults = new XmlDocument();
            xmlResults.Load(xmlFileName);
            Assert.AreEqual(1, xmlResults.SelectNodes("/remoteinstallresultsgroups").Count);
            // reload the xml results
            Results resultsCopy = new Results();
            resultsCopy.Load(xmlResults);
            Assert.AreEqual(1, resultsCopy.GetXml().SelectNodes("/remoteinstallresultsgroups").Count);
            Directory.Delete(outputDir, true);
            File.Delete(configFileName);
        }
        public void SimulateAllMsiSequencesTest()
        {
            Stream sequencesConfigStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                "RemoteInstallUnitTests.TestConfigs.MsiSequences.config");

            string configFileName = Path.GetTempFileName();
            using (StreamReader sequencesConfigReader = new StreamReader(sequencesConfigStream))
            {
                File.WriteAllText(configFileName, sequencesConfigReader.ReadToEnd());
            }

            string outputDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            Directory.CreateDirectory(outputDir);

            foreach (InstallersSequence sequence in Enum.GetValues(typeof(InstallersSequence)))
            {
                Console.WriteLine("Sequence: {0}", sequence);
                NameValueCollection vars = new NameValueCollection();
                vars["root"] = @"..\..\..\..";
                vars["sequence"] = sequence.ToString();

                Driver driver = new Driver(
                    outputDir,
                    true,
                    configFileName,
                    vars,
                    1);

                Results results = new Results();
                results.AddRange(driver.Run());

                switch (sequence)
                {
                    case InstallersSequence.clean:
                        // a clean sequence is like 2 separate, clean installations
                        Assert.AreEqual(2, results.Count);
                        Assert.AreEqual(1, results[0].Count);
                        Assert.AreEqual(1, results[1].Count);
                        break;
                    case InstallersSequence.alternate:
                    case InstallersSequence.install:
                    case InstallersSequence.uninstall:
                        // two installers alternating with install+uninstall in the same run
                        // or just install or uninstall
                        Assert.AreEqual(1, results.Count);
                        Assert.AreEqual(2, results[0].Count);
                        break;
                    default:
                        // two installers split into install+uninstall in a sequence of 4
                        Assert.AreEqual(1, results.Count);
                        Assert.AreEqual(4, results[0].Count);
                        break;
                }
            }

            Directory.Delete(outputDir, true);
            File.Delete(configFileName);
        }
        public void SnapshotsWithParametersTest()
        {
            Stream configStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                "RemoteInstallUnitTests.TestConfigs.SnapshotWithParameters.config");
            string configFileName = Path.GetTempFileName();

            using (StreamReader sr = new StreamReader(configStream))
            {
                File.WriteAllText(configFileName, sr.ReadToEnd());
            }

            string outputDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            Directory.CreateDirectory(outputDir);

            try
            {
                Driver driver = new Driver(outputDir, true, configFileName, null, 0);
                Results results = new Results();
                results.AddRange(driver.Run());
                // four individual results
                Assert.AreEqual(4, results.Count);
                foreach (ResultsGroup group in results)
                {
                    Console.WriteLine("{0}: {1}", group.Vm, group.Snapshot);
                    foreach(Result result in group)
                    {
                        // installer name is defined as name="@{snapshot.installargs}"
                        // and each installargs is vm.snapshot
                        Assert.AreEqual(string.Format("{0}.{1}", group.Vm, group.Snapshot),
                            result.InstallerName);
                    }
                }
            }
            finally
            {
                Directory.Delete(outputDir, true);
                File.Delete(configFileName);
            }
        }
        public void NothingToDoTest()
        {
            Stream configStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                "RemoteInstallUnitTests.TestConfigs.NothingToDo.config");
            string configFileName = Path.GetTempFileName();

            using (StreamReader sr = new StreamReader(configStream))
            {
                File.WriteAllText(configFileName, sr.ReadToEnd());
            }

            string outputDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            Directory.CreateDirectory(outputDir);

            try
            {
                Driver driver = new Driver(outputDir, true, configFileName, null, 0);
                Results results = new Results();
                results.AddRange(driver.Run());
                Assert.Fail("Expected InvalidConfigurationException");
            }
            catch (InvalidConfigurationException ex)
            {
                Console.WriteLine("Expected exception: {0}", ex.Message);
            }
            finally
            {
                Directory.Delete(outputDir, true);
                File.Delete(configFileName);
            }
        }