Пример #1
0
        public void Update_Should_Update_Path_Only()
        {
            // arrange
            var name = _nameGenerator.GetRandomName(Prefix);

            var configForCreate = new WindowsServiceConfiguration
            {
                Name = name,
                Path = _serviceInstaller.ServicePath
            };

            _serviceInstaller.InstallService(configForCreate);

            var configForUpdate = new WindowsServiceConfigurationForUpdate
            {
                Path = configForCreate.Path.Replace("BasicService", "BasicService2")
            };

            // act
            _shell.Update(name, configForUpdate);

            // assert
            var model = ServiceHelper.GetService(name);

            model.Path.Should().Be(configForUpdate.Path);

            model.DisplayName.Should().Be(name);
            model.StartMode.Should().Be(AutomaticStartMode);
            model.Type.Should().Be(configForCreate.Type);
            model.ErrorControl.Should().Be(configForCreate.ErrorControl);
            model.Account.Should().Be("LocalSystem");
            model.Description.Should().BeNullOrEmpty();
        }
Пример #2
0
        /// <inheritdoc />
        public void Update(string serviceName, WindowsServiceConfigurationForUpdate config)
        {
            ThrowIfCantFindService(serviceName);

            if (config.Path != null)
            {
                ThrowIfCantFindFile(config.Path);
            }

            var isDelayedStart = config.StartMode == WindowsServiceStartMode.AutomaticDelayedStart;
            var startMode      = isDelayedStart ? WindowsServiceStartMode.Automatic : config.StartMode;

            var parameters = new List <CommandParameter>
            {
                new CommandParameter("serviceName", serviceName),
                new CommandParameter("displayName", config.DisplayName),
                new CommandParameter("errorControl", (byte?)config.ErrorControl),
                new CommandParameter("startMode", startMode),
                new CommandParameter("serviceType", (byte?)config.Type),
                new CommandParameter("desktopInteract", config.InteractWithDesktop.GetValueOrDefault()),
                new CommandParameter("fullServicePath", config.Path),
                new CommandParameter("serviceDependencies", config.ServiceDependencies?.Count == 0 ? new [] { String.Empty } :  config.ServiceDependencies)
            };

            var result = _executor.Execute(_scripts.UpdateServiceWithParameters, parameters);

            if (config.Description != null)
            {
                UpdateDescription(serviceName, config.Description);
            }

            UpdateDelayedStart(serviceName, isDelayedStart);

            ThrowServiceExceptionIfNecessary(result);
        }
Пример #3
0
        public void Update_Should_Ignore_ServiceDependencies_When_Null()
        {
            // arrange
            var name = _nameGenerator.GetRandomName(Prefix);
            var serviceDependencies = new List <string>()
            {
                _nameGenerator.GetRandomName(Prefix),
                _nameGenerator.GetRandomName(Prefix)
            };

            var configForCreate = new WindowsServiceConfiguration
            {
                Name = name,
                Path = _serviceInstaller.ServicePath,
                ServiceDependencies = serviceDependencies
            };

            _serviceInstaller.InstallService(configForCreate);

            var configForUpdate = new WindowsServiceConfigurationForUpdate
            {
                ServiceDependencies = null
            };

            // act
            _shell.Update(name, configForUpdate);

            // assert
            var model = ServiceHelper.GetServiceDependencies(name);

            model.Should().BeEquivalentTo(serviceDependencies);
        }
Пример #4
0
        public void Update_Should_Update_DelayedAutostart_Only_ToFalse()
        {
            // arrange
            var name = _nameGenerator.GetRandomName(Prefix);

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

            _serviceInstaller.InstallService(configForCreate);

            var configForUpdate = new WindowsServiceConfigurationForUpdate
            {
                StartMode = WindowsServiceStartMode.Automatic
            };

            // act
            _shell.Update(name, configForUpdate);

            // assert
            var model = ServiceHelper.GetService(name);

            ServiceHelper.GetDelayedAutostart(name).Should().BeFalse();

            model.Description.Should().Be(configForCreate.Description);
            model.ErrorControl.Should().Be(configForCreate.ErrorControl);
            model.StartMode.Should().Be(AutomaticStartMode);
            model.Path.Should().Be(configForCreate.Path);
            model.DisplayName.Should().Be(name);
            model.Account.Should().Be("LocalSystem");
        }
Пример #5
0
        public void Update_Should_Update_InteractWithDekstop_Only()
        {
            // arrange
            var name = _nameGenerator.GetRandomName(Prefix);

            var configForCreate = new WindowsServiceConfiguration
            {
                Name = name,
                Path = _serviceInstaller.ServicePath
            };

            _serviceInstaller.InstallService(configForCreate);
            _userInstaller.Install(name, "test");

            var configForUpdate = new WindowsServiceConfigurationForUpdate
            {
                InteractWithDesktop = true
            };

            // act
            _shell.Update(name, configForUpdate);

            // assert
            var model = ServiceHelper.GetService(name);
            var interactiveWithDekstopFlag = 0x100;

            ((int)model.Type).Should().Be((int)configForCreate.Type.GetValueOrDefault() | interactiveWithDekstopFlag);

            model.ErrorControl.Should().Be(configForCreate.ErrorControl);
            model.StartMode.Should().Be(AutomaticStartMode);
            model.Path.Should().Be(configForCreate.Path);
            model.DisplayName.Should().Be(name);
            model.Account.Should().Be("LocalSystem");
            model.Description.Should().BeNullOrEmpty();
        }
Пример #6
0
        public IWindowsServiceInfoUpdate RollbackOnError()
        {
            _cache.RollbackOnError = true;

            if (_cache.RollbackOnError)
            {
                var service = _shell.Get(_service.Name);

                _backupConfig = _manager.CreateBackupConfig(service, _cache);
            }

            return(this);
        }
        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);
        }
Пример #8
0
        public void Update_Should_Update_ServiceDependencies_Only_FromEmpty_ToCollection()
        {
            // arrange
            var name = _nameGenerator.GetRandomName(Prefix);
            var serviceDependencies = new List <string>()
            {
                _nameGenerator.GetRandomName(Prefix),
                _nameGenerator.GetRandomName(Prefix)
            };

            var configForCreate = new WindowsServiceConfiguration
            {
                Name = name,
                Path = _serviceInstaller.ServicePath,
            };

            _serviceInstaller.InstallService(configForCreate);

            var configForUpdate = new WindowsServiceConfigurationForUpdate
            {
                ServiceDependencies = serviceDependencies
            };

            // act
            _shell.Update(name, configForUpdate);

            // assert
            var model = ServiceHelper.GetService(name);

            model.ServiceDependencies.Should().BeEquivalentTo(serviceDependencies);

            model.Description.Should().Be(configForCreate.Description);
            model.ErrorControl.Should().Be(configForCreate.ErrorControl);
            model.StartMode.Should().Be(AutomaticStartMode);
            model.Path.Should().Be(configForCreate.Path);
            model.DisplayName.Should().Be(name);
            model.Account.Should().Be("LocalSystem");
        }
Пример #9
0
        public void Update_Should_Throw_If_Path_IsInvalid()
        {
            // arrange
            var name = _nameGenerator.GetRandomName(Prefix);

            var configForCreate = new WindowsServiceConfiguration
            {
                Name = name,
                Path = _serviceInstaller.ServicePath
            };

            _serviceInstaller.InstallService(configForCreate);

            var configForUpdate = new WindowsServiceConfigurationForUpdate
            {
                Path = "FakePath"
            };

            // act
            Action act = () => _shell.Update(name, configForUpdate);

            // assert
            act.ShouldThrow <FileNotFoundException>();
        }