Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="settings"></param>
        public SystemSettingsSwitcher(CommandBase owner, SystemSettingsSwitcherSettings settings)
        {
            // argument checks
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            // settings can be null

            // initialize members
            this.Owner = owner;

            bool        enabled;
            string      configurationScript;
            DnsEndPoint actualProxyEndPoint;

            if (settings == null)
            {
                // simple initialization (ex. to restore only)
                enabled             = true;
                configurationScript = null;
                actualProxyEndPoint = null;
            }
            else
            {
                // usual initialization
                enabled = settings.EnableSystemSettingsSwitch;
                ActualProxySettings actualProxySettings = settings.ActualProxy;
                if (actualProxySettings != null)
                {
                    configurationScript = actualProxySettings.ConfigurationScript;
                    if (string.IsNullOrEmpty(configurationScript))
                    {
                        actualProxyEndPoint = new DnsEndPoint(actualProxySettings.Host, actualProxySettings.Port);
                    }
                    else
                    {
                        actualProxyEndPoint = null;
                    }
                }
                else
                {
                    configurationScript = null;
                    actualProxyEndPoint = null;
                }
            }

            this.Enabled = enabled;
            this.ActualProxyConfigurationScript = configurationScript;
            this.ActualProxyEndPoint            = actualProxyEndPoint;

            return;
        }
            public void Default()
            {
                // ARRANGE

                // ACT
                ActualProxySettings target = new ActualProxySettings();

                // ASSERT
                Assert.Equal(ActualProxySettings.Defaults.Host, target.Host);
                Assert.Equal(ActualProxySettings.Defaults.Port, target.Port);
                Assert.Equal(null, target.ConfigurationScript);
            }
            public void EmptyData()
            {
                // ARRANGE
                string      jsonText = $"{{}}";
                IObjectData data     = new JsonObjectData(jsonText);

                // ACT
                ActualProxySettings target = new ActualProxySettings(data);

                // ASSERT
                Assert.Equal(ActualProxySettings.Defaults.Host, target.Host);
                Assert.Equal(ActualProxySettings.Defaults.Port, target.Port);
                Assert.Equal(null, target.ConfigurationScript);
            }
            public void ConfigurationScriptData()
            {
                // ARRANGE
                string      configurationScript = "file:///c:/test.pac";
                string      jsonText            = $"{{\"ConfigurationScript\":\"{configurationScript}\"}}";
                IObjectData data = new JsonObjectData(jsonText);

                // ACT
                ActualProxySettings target = new ActualProxySettings(data);

                // ASSERT
                Assert.Equal(null, target.Host);
                Assert.Equal(ActualProxySettings.Defaults.Port, target.Port);
                Assert.Equal(configurationScript, target.ConfigurationScript);
            }
            public void AddressData()
            {
                // ARRANGE
                string      host     = "*****@*****.**";
                int         port     = 80;
                string      jsonText = $"{{\"Host\":\"{host}\", \"Port\": {port}}}";
                IObjectData data     = new JsonObjectData(jsonText);

                // ACT
                ActualProxySettings target = new ActualProxySettings(data);

                // ASSERT
                Assert.Equal(host, target.Host);
                Assert.Equal(port, target.Port);
                Assert.Equal(null, target.ConfigurationScript);
            }
Beispiel #6
0
        public virtual ActualProxySettings CreateActualProxySettings()
        {
            // create an ActualProxySettings instance
            ActualProxySettings actualProxySettings = new ActualProxySettings();

            // set up the instance
            if (string.IsNullOrEmpty(this.DefaultActualProxyHostName) == false)
            {
                actualProxySettings.Host = this.DefaultActualProxyHostName;
            }
            if (this.DefaultActualProxyPort != null)
            {
                actualProxySettings.Port = this.DefaultActualProxyPort.Value;
            }
            if (string.IsNullOrEmpty(this.DefaultActualProxyConfigurationScript) == false)
            {
                actualProxySettings.ConfigurationScript = this.DefaultActualProxyConfigurationScript;
            }

            return(actualProxySettings);
        }