コード例 #1
0
        private void SetupTestEnv(TestHostContext hc, string securityId)
        {
            _powerCfgCalledForACOption = _powerCfgCalledForDCOption = false;
            _autoLogonSettings         = null;

            _windowsServiceHelper = new Mock <INativeWindowsServiceHelper>();
            hc.SetSingleton <INativeWindowsServiceHelper>(_windowsServiceHelper.Object);

            _promptManager = new Mock <IPromptManager>();
            hc.SetSingleton <IPromptManager>(_promptManager.Object);

            _promptManager
            .Setup(x => x.ReadValue(
                       Constants.Agent.CommandLine.Args.WindowsLogonAccount, // argName
                       It.IsAny <string>(),                                  // description
                       It.IsAny <bool>(),                                    // secret
                       It.IsAny <string>(),                                  // defaultValue
                       Validators.NTAccountValidator,                        // validator
                       It.IsAny <bool>()))                                   // unattended
            .Returns(string.Format(@"{0}\{1}", _domainName, _userName));

            _windowsServiceHelper.Setup(x => x.IsValidAutoLogonCredential(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true);
            _windowsServiceHelper.Setup(x => x.SetAutoLogonPassword(It.IsAny <string>()));
            _windowsServiceHelper.Setup(x => x.GetSecurityId(It.IsAny <string>(), It.IsAny <string>())).Returns(() => securityId);
            _windowsServiceHelper.Setup(x => x.IsRunningInElevatedMode()).Returns(true);

            _processInvoker = new Mock <IProcessInvoker>();
            hc.EnqueueInstance <IProcessInvoker>(_processInvoker.Object);
            hc.EnqueueInstance <IProcessInvoker>(_processInvoker.Object);

            _processInvoker.Setup(x => x.ExecuteAsync(
                                      It.IsAny <String>(),
                                      "powercfg.exe",
                                      "/Change monitor-timeout-ac 0",
                                      null,
                                      It.IsAny <CancellationToken>())).Returns(Task.FromResult <int>(SetPowerCfgFlags(true)));

            _processInvoker.Setup(x => x.ExecuteAsync(
                                      It.IsAny <String>(),
                                      "powercfg.exe",
                                      "/Change monitor-timeout-dc 0",
                                      null,
                                      It.IsAny <CancellationToken>())).Returns(Task.FromResult <int>(SetPowerCfgFlags(false)));

            _mockRegManager = new MockRegistryManager();
            hc.SetSingleton <IWindowsRegistryManager>(_mockRegManager);

            _command = new CommandSettings(
                hc,
                new[]
            {
                "configure",
                "--windowslogonaccount", "wont be honored",
                "--windowslogonpassword", "sssh",
                "--norestart",
                _runOnce
            });

            _store = new Mock <IConfigurationStore>();
            _store.Setup(x => x.SaveAutoLogonSettings(It.IsAny <AutoLogonSettings>()))
            .Callback((AutoLogonSettings settings) =>
            {
                _autoLogonSettings = settings;
            });

            _store.Setup(x => x.IsAutoLogonConfigured()).Returns(() => _autoLogonSettings != null);
            _store.Setup(x => x.GetAutoLogonSettings()).Returns(() => _autoLogonSettings);



            hc.SetSingleton <IConfigurationStore>(_store.Object);

            hc.SetSingleton <IAutoLogonRegistryManager>(new AutoLogonRegistryManager());
        }