public void TestStopOnlyGetsCalledOnce()
        {
            using (ShimsContext.Create())
            {
                int stopIterations = 0;

                var service = new System.ServiceProcess.Fakes.ShimServiceBase
                {
                    OnStop = () =>
                    {
                        stopIterations++;
                    }
                };

                var host = new ConsoleServiceHost(service);

                Assert.AreEqual(0, stopIterations);
                host.StartHostedService();
                Assert.AreEqual(0, stopIterations);

                host.StopHostedService();
                Assert.AreEqual(1, stopIterations);
                host.StopHostedService();
                Assert.AreEqual(1, stopIterations);
                host.StopHostedService();
                Assert.AreEqual(1, stopIterations);
                host.StopHostedService();
                Assert.AreEqual(1, stopIterations);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            if (args != null && args.Length == 1 && args[0].Length > 1 &&
                (args[0][0] == '-' || args[0][0] == '/'))
            {
                switch (args[0].Substring(1).ToLower())
                {
                default:
                    break;

                case "install":
                case "i":
                    SelfInstaller.InstallMe();
                    break;

                case "uninstall":
                case "u":
                    SelfInstaller.UninstallMe();
                    break;

                case "console":
                case "c":
                    ConsoleServiceHost.StartHost(args);
                    break;
                }
            }
            else
            {
                WindowsServiceHost.StartHost();
            }
        }
Example #3
0
 public static void Main(string[] args)
 {
     ConsoleServiceHost.Start <CustomerService>(baseAddress);
 }
        public void TestServiceStartsWhenExpected()
        {
            using (ShimsContext.Create())
            {
                bool startCodeRan = false;

                var service = new System.ServiceProcess.Fakes.ShimServiceBase
                {
                    OnStartStringArray = (args) =>
                    {
                        startCodeRan = true;
                    }
                };

                var host = new ConsoleServiceHost(service);

                Assert.IsFalse(startCodeRan);

                host.StopHostedService();
                Assert.IsFalse(startCodeRan);

                host.StartHostedService();
                Assert.IsTrue(startCodeRan);
            }
        }
        public void TestServiceIsServiceUpWorks()
        {
            using (ShimsContext.Create())
            {
                var service = new System.ServiceProcess.Fakes.ShimServiceBase
                {

                };

                var host = new ConsoleServiceHost(service);

                Assert.IsFalse(host.IsServiceUp);

                host.StopHostedService();
                Assert.IsFalse(host.IsServiceUp);
                host.StopHostedService();
                Assert.IsFalse(host.IsServiceUp);

                host.StartHostedService();
                Assert.IsTrue(host.IsServiceUp);

                host.StartHostedService();
                Assert.IsTrue(host.IsServiceUp);
                host.StartHostedService();
                Assert.IsTrue(host.IsServiceUp);
                host.StartHostedService();
                Assert.IsTrue(host.IsServiceUp);

                host.StopHostedService();
                Assert.IsFalse(host.IsServiceUp);
                host.StopHostedService();
                Assert.IsFalse(host.IsServiceUp);

                host.StartHostedService();
                Assert.IsTrue(host.IsServiceUp);
                host.StopHostedService();
                Assert.IsFalse(host.IsServiceUp);
            }
        }
        public void TestServiceStopsWhenExpected()
        {
            using (ShimsContext.Create())
            {
                bool stopCodeRan = false;

                var service = new System.ServiceProcess.Fakes.ShimServiceBase
                {
                    OnStop = () =>
                    {
                        stopCodeRan = true;
                    }
                };

                var host = new ConsoleServiceHost(service);

                Assert.IsFalse(stopCodeRan);

                // not running yet so shouldn't stop
                host.StopHostedService();
                Assert.IsFalse(stopCodeRan);

                host.StartHostedService();
                Assert.IsFalse(stopCodeRan);

                host.StopHostedService();
                Assert.IsTrue(stopCodeRan);
            }
        }