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(); } } }
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(); } } }
public void Dispose() { if (!_disposed) { _testService.DeleteTestServices(); _disposed = true; } }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); } } }
public void Dispose() { _testService.DeleteTestServices(); }