public void Get_Should_GetService()
        {
            // arrange
            var serviceName = _nameGenerator.RandomName;

            _serviceInstaller.InstallService(serviceName);

            // act
            var service = new Model.WindowsServiceInfo(serviceName);

            // assert
            service.AccountDomain.Should().Be(null);
            service.AccountName.Should().Be("LocalSystem");
            service.Description.Should().Be(null);
            service.DisplayName.Should().Be(serviceName);
            service.ErrorControl.Should().Be(WindowsServiceErrorControl.Normal);
            service.InteractWithDesktop.Should().Be(false);
            service.Name.Should().Be(serviceName);
            service.Path.Should().Be(_serviceInstaller.ServicePath);
            service.ProcessId.Should().Be(0);
            service.StartMode.Should().Be(WindowsServiceStartMode.Automatic);
            service.State.Should().Be(WindowsServiceState.Stopped);
            service.Status.Should().Be(WindowsServiceStatus.Ok);
            service.CanPause.Should().BeFalse();
            service.CanStop.Should().BeFalse();
            service.ExitCode.Should().Be(1077u);
            service.ServiceDependencies.Should().BeEmpty();
        }
        public void Get_Should_Return_Proper_ServiceDependencies_When_Is_Collection()
        {
            // arrange
            var serviceName         = _nameGenerator.RandomName;
            var serviceDependencies = new List <string>
            {
                _nameGenerator.RandomName,
                _nameGenerator.RandomName
            };

            var config = new WindowsServiceConfiguration
            {
                Name = serviceName,
                Path = _serviceInstaller.ServicePath,
                ServiceDependencies = serviceDependencies
            };

            _serviceInstaller.InstallService(config);

            // act
            var service = new Model.WindowsServiceInfo(serviceName);

            // assert
            service.ServiceDependencies.Should().BeEquivalentTo(serviceDependencies);
        }
Exemplo n.º 3
0
        internal WindowsServiceInfoUpdate(Model.WindowsServiceInfo service, IWindowsServiceShell windowsShell, IWindowsServiceModelManager manager)
        {
            _shell   = windowsShell;
            _service = service;
            _manager = manager;

            _cache = new ConfigurationCache();
        }
        public void Get_Should_Throw_When_ServiceNotExisting()
        {
            // arrange
            var serviceName = "fakeService";

            // act
            Action act = () => { var _ = new Model.WindowsServiceInfo(serviceName); };

            // assert
            act.ShouldThrow <InvalidOperationException>();
        }
        protected void InitializeBase(Model.WindowsServiceInfo windowsServiceInfo)
        {
            _info    = windowsServiceInfo;
            _shell   = new Lazy <WindowsServiceShell>(() => new WindowsServiceShell());
            _mapper  = new Lazy <IWindowsServiceModelManager>(() => new WindowsServiceModelManager());
            _service = new Lazy <IWindowsServiceInfoUpdate>(
                () => new WindowsServiceInfoUpdate(windowsServiceInfo, _shell.Value, _mapper.Value));

            _exceptionFactory =
                new Lazy <IWindowsServiceExceptionFactory>(
                    () => new WindowsServiceExceptionFactory(new Win32ServiceMessages()));
        }
        public void Get_Should_Return_AcceptStopAndStart_True_WhenService_IsRunning()
        {
            // arrange
            var serviceName = _nameGenerator.RandomName;

            _serviceInstaller.InstallService(serviceName);
            ServiceHelper.StartService(serviceName);

            // act
            var service = new Model.WindowsServiceInfo(serviceName);

            // assert
            service.State.Should().Be(WindowsServiceState.Running);
            service.CanPause.Should().BeTrue();
            service.CanStop.Should().BeTrue();
        }
 public void CopyProperties(Model.WindowsServiceInfo target, Model.WindowsServiceInfo source)
 {
     target.AccountDomain       = source.AccountDomain;
     target.AccountName         = source.AccountName;
     target.CanPause            = source.CanPause;
     target.CanStop             = source.CanStop;
     target.Description         = source.Description;
     target.DisplayName         = source.DisplayName;
     target.ErrorControl        = source.ErrorControl;
     target.ExitCode            = source.ExitCode;
     target.InteractWithDesktop = source.InteractWithDesktop;
     target.Path                    = source.Path;
     target.ProcessId               = source.ProcessId;
     target.ServiceDependencies     = new List <string>(source.ServiceDependencies);
     target.ServiceSpecificExitCode = source.ServiceSpecificExitCode;
     target.State                   = source.State;
     target.Status                  = source.Status;
     target.StartMode               = source.StartMode;
 }
        public void Get_Should_Return_Proper_StartMode_When_Is_AutomaticWithDelayedStart()
        {
            // arrange
            var serviceName = _nameGenerator.RandomName;

            var config = new WindowsServiceConfiguration
            {
                Name      = serviceName,
                Path      = _serviceInstaller.ServicePath,
                StartMode = WindowsServiceStartMode.AutomaticDelayedStart
            };

            _serviceInstaller.InstallService(config);

            // act
            var service = new Model.WindowsServiceInfo(serviceName);

            // assert
            service.StartMode.Should().Be(WindowsServiceStartMode.AutomaticDelayedStart);
        }
        public void Get_Should_Return_Updated_Description()
        {
            // arrange
            var serviceName = _nameGenerator.RandomName;

            var config = new WindowsServiceConfiguration
            {
                Name        = serviceName,
                Path        = _serviceInstaller.ServicePath,
                Description = "test"
            };

            _serviceInstaller.InstallService(config);

            // act
            var service = new Model.WindowsServiceInfo(serviceName);

            // assert
            service.Description.Should().Be(config.Description);
        }
        public WindowsServiceConfigurationForUpdate CreateBackupConfig(Model.WindowsServiceInfo originalService, ConfigurationCache cachedChanges)
        {
            var config = new WindowsServiceConfigurationForUpdate();

            if (cachedChanges.Description != null)
            {
                config.Description = originalService.Description ?? String.Empty;
            }
            if (cachedChanges.DisplayName != null)
            {
                config.DisplayName = originalService.DisplayName;
            }
            if (cachedChanges.Path != null)
            {
                config.Path = originalService.Path;
            }
            if (cachedChanges.ServiceDependencies != null)
            {
                config.ServiceDependencies = originalService.ServiceDependencies;
            }
            if (cachedChanges.ErrorControl != null)
            {
                config.ErrorControl = originalService.ErrorControl;
            }
            if (cachedChanges.InteractWithDesktop != null)
            {
                config.InteractWithDesktop = originalService.InteractWithDesktop;
            }
            if (cachedChanges.StartMode != null)
            {
                config.StartMode = originalService.StartMode;
            }
            if (cachedChanges.Type != null)
            {
                config.Type = originalService.Type;
            }

            return(config);
        }