예제 #1
0
        public void DeleteTestServices()
        {
            try
            {
                TestServiceInstaller testServiceInstaller = new TestServiceInstaller();
                testServiceInstaller.ServiceName = TestServiceName;
                testServiceInstaller.RemoveService();

                if (File.Exists(LogPath))
                {
                    try
                    {
                        File.Delete(LogPath);
                    }
                    catch (IOException)
                    {
                        // Don't fail simply because the service was not fully cleaned up
                        // and is still holding a handle to the log file
                    }
                }
            }
            finally
            {
                // Lets be sure to try and clean up dependenct services even if something goes
                // wrong with the full removal of the other service.
                if (_dependentServices != null)
                {
                    _dependentServices.DeleteTestServices();
                }
            }
        }
예제 #2
0
        public void DeleteTestServices()
        {
            try
            {
                if (_client != null)
                {
                    DebugTrace("TestServiceProvider: Disposing client stream in Dispose()");
                    _client.Dispose();
                    _client = null;
                }

                TestServiceInstaller testServiceInstaller = new TestServiceInstaller();
                testServiceInstaller.ServiceName = TestServiceName;
                testServiceInstaller.RemoveService();
            }
            finally
            {
                // Lets be sure to try and clean up dependenct services even if something goes
                // wrong with the full removal of the other service.
                if (_dependentServices != null)
                {
                    _dependentServices.DeleteTestServices();
                }
            }
        }
예제 #3
0
 public void Dispose()
 {
     if (!_disposed)
     {
         _testService.DeleteTestServices();
         _disposed = true;
     }
 }
예제 #4
0
        public void LogWritten_AutoLog_False()
        {
            string serviceName = nameof(LogWritten_AutoLog_False) + Guid.NewGuid().ToString();
            var    testService = new TestServiceProvider(serviceName);

            Assert.False(EventLog.SourceExists(serviceName));
            testService.DeleteTestServices();
        }
예제 #5
0
        public void LogWritten()
        {
            string serviceName = Guid.NewGuid().ToString();
            // If the username is null, then the service is created under LocalSystem Account which have access to EventLog.
            var testService = new TestServiceProvider(serviceName);

            Assert.True(EventLog.SourceExists(serviceName));
            testService.DeleteTestServices();
        }
예제 #6
0
        public void PropagateExceptionFromOnStart()
        {
            string serviceName = nameof(PropagateExceptionFromOnStart) + Guid.NewGuid().ToString();
            TestServiceProvider _testService = new TestServiceProvider(serviceName);

            _testService.Client.Connect(connectionTimeout);
            Assert.Equal((int)PipeMessageByteCode.ExceptionThrown, _testService.GetByte());
            _testService.DeleteTestServices();
        }
예제 #7
0
        public void LogWritten()
        {
            string serviceName = Guid.NewGuid().ToString();
            // The default username for installing the service is NT AUTHORITY\\LocalService which does not have access to EventLog.
            // If the username is null, then the service is created under LocalSystem Account which have access to EventLog.
            var testService = new TestServiceProvider(serviceName, userName: null);

            Assert.True(EventLog.SourceExists(serviceName));
            testService.DeleteTestServices();
        }
예제 #8
0
        public void NoServiceNameOnServiceBase()
        {
            // When installing a service, you must supply a non empty name.
            // When a service starts itself (using StartServiceCtrlDispatcher) it's legal to pass an empty string for the name.
            string serviceName = "NoServiceNameOnServiceBase";
            var    testService = new TestServiceProvider(serviceName);

            // Ensure it has successfully written to the event log,
            // indicating it figured out its own name.
            Assert.True(EventLog.SourceExists(serviceName));

            testService.DeleteTestServices();
        }
예제 #9
0
        public void DeleteTestServices()
        {
            try
            {
                TestServiceInstaller testServiceInstaller = new TestServiceInstaller();
                testServiceInstaller.ServiceName = TestServiceName;
                testServiceInstaller.RemoveService();

                if (File.Exists(LogPath))
                {
                    File.Delete(LogPath);
                }
            }
            finally
            {
                // Lets be sure to try and clean up dependenct services even if something goes
                // wrong with the full removal of the other service.
                if (_dependentServices != null)
                {
                    _dependentServices.DeleteTestServices();
                }
            }
        }
예제 #10
0
 public void Dispose()
 {
     _testService.DeleteTestServices();
 }