/// <summary>
        /// Performs test cleanup.
        /// </summary>
        private static void Cleanup()
        {
            if (File.Exists(ServiceTransaction.FilePathName))
            {
                File.Delete(ServiceTransaction.FilePathName);
            }

            var sourceCodes = new Dictionary <string, string>
            {
                { "WindowsService1", Resources.WindowsService1 },
                { "WindowsService2a", Resources.WindowsService2 },
                { "WindowsService2b", Resources.WindowsService2 }
            };

            var services =
                ServiceHelper_Accessor.GetInstalledServices()
                .Where(p => sourceCodes.Keys.Contains(p.ServiceName));

            foreach (var service in services)
            {
                service.TargetFramework =
                    TargetFramework.Net40;
                service.BinaryPathName =
                    ServiceHelper_Accessor.GetInstalledServiceBinaryPathName(service.ServiceName);

                CleanupServiceInstallation(
                    service,
                    sourceCodes[service.ServiceName]);
            }
        }
        public void Installing_And_Uninstalling_Multiple_Service_NET_2()
        {
            const TargetFramework targetFramework = TargetFramework.Net20;

            string binaryPathName = Path.Combine(
                s_basePath,
                "TestWindowsService.exe");

            bool ok = CompileDynamic(
                Resources.WindowsService2,
                binaryPathName,
                "v2.0.50727");

            Assert.IsTrue(ok);

            var services1 = ServiceHelper_Accessor.GetInstalledServices();

            ServiceHelper_Accessor.InstallService(
                targetFramework,
                binaryPathName);

            var services2 = ServiceHelper_Accessor.GetInstalledServices();

            services2.ExceptWith(services1);

            Assert.AreEqual(2, services2.Count);

            ServiceItem serviceItemA = services2.First();

            Assert.AreEqual("WindowsService2a", serviceItemA.ServiceName);
            Assert.AreEqual("[Test] Windows Service #2-A", serviceItemA.DisplayName);

            string actualBinaryPathNameA = ServiceHelper_Accessor.GetInstalledServiceBinaryPathName("WindowsService2a");

            Assert.AreEqual(binaryPathName, actualBinaryPathNameA);

            ServiceItem serviceItemB = services2.Last();

            Assert.AreEqual("WindowsService2b", serviceItemB.ServiceName);
            Assert.AreEqual("[Test] Windows Service #2-B", serviceItemB.DisplayName);

            string actualBinaryPathNameB = ServiceHelper_Accessor.GetInstalledServiceBinaryPathName("WindowsService2a");

            Assert.AreEqual(binaryPathName, actualBinaryPathNameB);

            ServiceHelper_Accessor.UninstallService(
                targetFramework,
                binaryPathName);

            File.Delete(binaryPathName);
        }
        public void Installing_And_Uninstalling_Single_Service_NET_4()
        {
            const TargetFramework targetFramework = TargetFramework.Net40;

            string binaryPathName = Path.Combine(
                s_basePath,
                "TestWindowsService.exe");

            bool ok = CompileDynamic(
                Resources.WindowsService1,
                binaryPathName,
                "v4.0.30319");

            Assert.IsTrue(ok);

            var services1 = ServiceHelper_Accessor.GetInstalledServices();

            ServiceHelper_Accessor.InstallService(
                targetFramework,
                binaryPathName);

            var services2 = ServiceHelper_Accessor.GetInstalledServices();

            services2.ExceptWith(services1);

            Assert.AreEqual(
                1,
                services2.Count);

            ServiceItem serviceItem = services2.First();

            Assert.AreEqual(
                "WindowsService1",
                serviceItem.ServiceName);
            Assert.AreEqual(
                "[Test] Windows Service #1",
                serviceItem.DisplayName);

            string actualBinaryPathName =
                ServiceHelper_Accessor.GetInstalledServiceBinaryPathName("WindowsService1");

            Assert.AreEqual(binaryPathName, actualBinaryPathName);

            ServiceHelper_Accessor.UninstallService(
                targetFramework,
                binaryPathName);

            File.Delete(binaryPathName);
        }
        public void Deleting_Service_Using_Uncommited_Transaction_Info()
        {
            string binaryPathName = Path.Combine(
                s_basePath,
                "TestWindowsService.exe");

            // create log file
            string log = ServiceTransaction.FilePathName;

            File.WriteAllText(
                log,
                string.Format(
                    Resources.UncommitedInstalledServicesXmlFile,
                    binaryPathName));

            // install service
            const TargetFramework targetFramework = TargetFramework.Net20;

            bool ok = CompileDynamic(
                Resources.WindowsService1,
                binaryPathName,
                "v2.0.50727");

            Assert.IsTrue(ok);

            ServiceHelper_Accessor.InstallService(
                targetFramework,
                binaryPathName);

            // ensure in successfully installation
            string actualBinaryPath =
                ServiceHelper_Accessor.GetInstalledServiceBinaryPathName("WindowsService1");

            Assert.AreEqual(
                binaryPathName,
                actualBinaryPath);

            // call test method
            ServiceHelper.DeletePreviouslyInstalledServices();

            // ensure in successfully uninstallation
            actualBinaryPath =
                ServiceHelper_Accessor.GetInstalledServiceBinaryPathName("WindowsService1");

            Assert.IsNull(actualBinaryPath);
        }
        public void Getting_Binary_File_Name_Of_Installed_Service()
        {
            string systemRoot = Environment.GetEnvironmentVariable("SystemRoot");

            Assert.IsNotNull(systemRoot);

            string expected = Path.Combine(
                Path.Combine(
                    systemRoot,
                    "system32"),
                "svchost.exe");

            string actual =
                ServiceHelper_Accessor.GetInstalledServiceBinaryPathName(
                    "LanmanServer");

            Assert.AreEqual(
                expected,
                actual);
        }