Esempio n. 1
0
        public void TestBasicRestartManager()
        {
            //Start up all the little dandies
            StartService(TestHelpers.TestService);
            RestartManagerSession manager = new RestartManagerSession();

            manager.StartSession();
            System.Threading.Thread.Sleep(1000);
            manager.RegisterResources(new List <string>()
            {
                ReplacementFileServicePath
            });

            //Look for the processes locking on our poor file
            RM_REBOOT_REASON rebootReason = default(RM_REBOOT_REASON);
            var processes = RestartManager.RmProcessToNetProcess(manager.GetList(ref rebootReason));

            //Make sure it's the service we expect.
            var serviceExecutable = GetServiceExecutablePath(TestHelpers.TestService);

            Assert.IsTrue(processes.Count > 0 && processes.Any(x => x.MainModule.FileName.ToLower() == serviceExecutable.ToLower()));

            manager.EndSession();
            StopService(TestHelpers.TestService);
        }
Esempio n. 2
0
        public void TestRestartManagerFakeFiles()
        {
            RestartManagerSession manager = new RestartManagerSession();

            manager.StartSession();
            manager.RegisterResources(new List <string>()
            {
                "REALLYNOTAFILE"
            });

            RM_REBOOT_REASON rebootReason = default(RM_REBOOT_REASON);
            var processes = RestartManager.RmProcessToNetProcess(manager.GetList(ref rebootReason));

            Assert.IsTrue(processes.Count == 0);

            manager.EndSession();
        }
Esempio n. 3
0
        public void TestRestartManagerManualShutdown()
        {
            var ReplacementProcessCopy = ReplacementProcess + "2";

            File.Copy(ReplacementProcess, ReplacementProcessCopy, true);

            //Start up the service and TRY to move the file. It should fail
            Process proc = Process.Start(ReplacementProcess);

            //We're hoping this will fail, as the process SHOULD be holding onto this guy
            MyAssert.ThrowsException(() => File.Copy(ReplacementProcessCopy, ReplacementProcess, true));

            //Now startup the restart manager and lets hope the process will be restarted.
            RestartManagerExtendedSession manager = new RestartManagerExtendedSession();

            manager.ManualRestartProcesses.Add(ReplacementProcess);
            manager.StartSession();
            manager.RegisterResources(new List <string>()
            {
                ReplacementProcess
            });

            RM_REBOOT_REASON rebootReason = default(RM_REBOOT_REASON);
            var processes = RestartManager.RmProcessToNetProcess(manager.GetList(ref rebootReason));

            Assert.IsTrue(rebootReason == RM_REBOOT_REASON.RmRebootReasonNone);
            Assert.IsTrue(processes.Count > 0);

            //After shutdown, the file should be copyable
            manager.Shutdown();
            ThreadingServices.WaitOnAction(() => File.Copy(ReplacementProcessCopy, ReplacementProcess, true), TimeSpan.FromSeconds(3));

            //Now try to restart everything
            manager.Restart();

            //We're hoping this will fail, as the service SHOULD be holding onto this guy again
            MyAssert.ThrowsException(() => ThreadingServices.WaitOnAction(() => File.Copy(ReplacementProcessCopy, ReplacementProcess, true), TimeSpan.FromSeconds(2)));

            manager.EndSession();

            System.Diagnostics.Process.GetProcessesByName(ReplacementProcess.Replace(".exe", "")).ToList().ForEach(x => x.Kill());
        }
Esempio n. 4
0
        public void TestRestartManagerServiceFileMove()
        {
            //Start up the service and TRY to move the file. It should fail
            StartService(TestHelpers.TestService);

            //We're hoping this will fail, as the service SHOULD be holding onto this guy
            MyAssert.ThrowsException(() => File.Copy(ReplacementFile, ReplacementFileServicePath, true));

            //Now startup the restart manager and lets hope the service will be restarted.
            RestartManagerSession manager = new RestartManagerSession();

            manager.StartSession();
            manager.RegisterResources(new List <string>()
            {
                ReplacementFileServicePath
            });

            RM_REBOOT_REASON rebootReason = default(RM_REBOOT_REASON);
            var processes = RestartManager.RmProcessToNetProcess(manager.GetList(ref rebootReason));

            Assert.IsTrue(rebootReason == RM_REBOOT_REASON.RmRebootReasonNone);
            Assert.IsTrue(processes.Count > 0);

            //After shutdown, the file should be copyable
            manager.Shutdown();
            ThreadingServices.WaitOnAction(() => File.Copy(ReplacementFile, ReplacementFileServicePath, true), TimeSpan.FromSeconds(3));

            //Now try to restart everything
            manager.Restart();

            //We're hoping this will fail, as the service SHOULD be holding onto this guy again
            MyAssert.ThrowsException(() => File.Copy(ReplacementFile, ReplacementFileServicePath, true));

            manager.EndSession();
            StopService(TestHelpers.TestService);
        }