Ejemplo n.º 1
0
        public void WhenProxyAutoconfigUrlInvalid_ThenApplyChangesThrowsArgumentException()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            viewModel.IsProxyAutoConfigurationEnabled = true;
            viewModel.ProxyAutoconfigurationAddress   = "file:///proxy.pac";

            Assert.Throws <ArgumentException>(() => viewModel.ApplyChanges());
        }
        public void WhenProxyPortIsOutOfBounds_ThenApplyChangesThrowsArgumentException()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            viewModel.IsCustomProxyServerEnabled = true;
            viewModel.ProxyServer = "proxy";
            viewModel.ProxyPort   = "70000";

            Assert.Throws <ArgumentException>(() => viewModel.ApplyChanges());
        }
        public void WhenEnablingCustomProxy_ThenProxyAdapterIsUpdated()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            viewModel.IsCustomProxyServerEnabled = true;
            viewModel.ApplyChanges();

            this.proxyAdapterMock.Verify(m => m.ActivateSettings(
                                             It.IsAny <ApplicationSettings>()), Times.Once);
        }
        public void WhenNoProxyConfigured_ThenPropertiesAreInitializedCorrectly()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            Assert.IsTrue(viewModel.IsSystemProxyServerEnabled);
            Assert.IsFalse(viewModel.IsCustomProxyServerEnabled);
            Assert.IsNull(viewModel.ProxyServer);
            Assert.IsNull(viewModel.ProxyPort);
            Assert.IsFalse(viewModel.IsDirty);
        }
        public void WhenProxyServerInvalid_ThenApplyChangesThrowsArgumentException()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object)
            {
                IsCustomProxyServerEnabled = true,
                ProxyServer = " .",
                ProxyPort   = "442"
            };

            Assert.Throws <ArgumentException>(() => viewModel.ApplyChanges());
        }
        public void WhenEnablingProxyAuth_ThenProxyUsernameSetToDefault()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            viewModel.IsCustomProxyServerEnabled   = true;
            viewModel.IsProxyAuthenticationEnabled = true;

            Assert.AreEqual(Environment.UserName, viewModel.ProxyUsername);
            Assert.IsNull(viewModel.ProxyPassword);
            Assert.IsTrue(viewModel.IsDirty);
        }
        public void WhenProxyAuthIncomplete_ThenApplyChangesThrowsArgumentException()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object)
            {
                IsCustomProxyServerEnabled = true,
                ProxyServer   = "proxy",
                ProxyPort     = "1000",
                ProxyPassword = "******"
            };

            Assert.Throws <ArgumentException>(() => viewModel.ApplyChanges());
        }
        public void WhenChangesApplied_ThenDirtyFlagIsCleared()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            viewModel.IsCustomProxyServerEnabled = true;

            Assert.IsTrue(viewModel.IsDirty);

            viewModel.ApplyChanges();

            Assert.IsFalse(viewModel.IsDirty);
        }
        public void WhenEnablingCustomProxy_ThenProxyHostAndPortSetToDefaults()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            viewModel.IsCustomProxyServerEnabled = true;

            Assert.IsFalse(viewModel.IsSystemProxyServerEnabled);
            Assert.IsTrue(viewModel.IsCustomProxyServerEnabled);
            Assert.AreEqual("proxy", viewModel.ProxyServer);
            Assert.AreEqual("3128", viewModel.ProxyPort);
            Assert.IsTrue(viewModel.IsDirty);
        }
        public void WhenProxyConfiguredButInvalid_ThenDefaultsAreUsed()
        {
            // Store an invalid URL.
            this.settingsKey.SetValue("ProxyUrl", "123", RegistryValueKind.String);

            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            Assert.IsTrue(viewModel.IsSystemProxyServerEnabled);
            Assert.IsFalse(viewModel.IsCustomProxyServerEnabled);
            Assert.IsNull(viewModel.ProxyServer);
            Assert.IsNull(viewModel.ProxyPort);
            Assert.IsFalse(viewModel.IsDirty);
        }
        public void WhenDisablingProxyAuth_ThenProxyUsernameAndPasswordAreCleared()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            viewModel.IsCustomProxyServerEnabled   = true;
            viewModel.IsProxyAuthenticationEnabled = true;
            viewModel.ProxyUsername = "******";
            viewModel.ProxyPassword = "******";
            viewModel.IsProxyAuthenticationEnabled = false;

            Assert.IsNull(viewModel.ProxyUsername);
            Assert.IsNull(viewModel.ProxyPassword);
            Assert.IsTrue(viewModel.IsDirty);
        }
        public void WhenProxyConfigured_ThenPropertiesAreInitializedCorrectly()
        {
            var settings = this.settingsRepository.GetSettings();

            settings.ProxyUrl.StringValue = "http://proxy-server";
            this.settingsRepository.SetSettings(settings);

            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            Assert.IsFalse(viewModel.IsSystemProxyServerEnabled);
            Assert.IsTrue(viewModel.IsCustomProxyServerEnabled);
            Assert.AreEqual("proxy-server", viewModel.ProxyServer);
            Assert.AreEqual("80", viewModel.ProxyPort);
            Assert.IsFalse(viewModel.IsDirty);
        }
        public void WhenDisablingCustomProxy_ThenProxyHostAndPortAreCleared()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            viewModel.IsCustomProxyServerEnabled = true;
            viewModel.ProxyServer = "myserver";
            viewModel.ProxyPort   = "442";
            viewModel.IsSystemProxyServerEnabled = true;

            Assert.IsTrue(viewModel.IsSystemProxyServerEnabled);
            Assert.IsFalse(viewModel.IsCustomProxyServerEnabled);
            Assert.IsNull(viewModel.ProxyServer);
            Assert.IsNull(viewModel.ProxyPort);
            Assert.IsTrue(viewModel.IsDirty);
        }
Ejemplo n.º 14
0
        public void WhenEnablingProxyAutoconfig_ThenProxyHostAndPortSetToDefaults()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            viewModel.IsProxyAutoConfigurationEnabled = true;

            Assert.IsFalse(viewModel.IsSystemProxyServerEnabled);
            Assert.IsFalse(viewModel.IsCustomProxyServerEnabled);
            Assert.IsTrue(viewModel.IsProxyAutoConfigurationEnabled);
            Assert.IsNull(viewModel.ProxyServer);
            Assert.IsNull(viewModel.ProxyPort);
            Assert.AreEqual("http://proxy/proxy.pac", viewModel.ProxyAutoconfigurationAddress);
            Assert.IsFalse(viewModel.IsProxyAuthenticationEnabled);
            Assert.IsNull(viewModel.ProxyUsername);
            Assert.IsNull(viewModel.ProxyPassword);
            Assert.IsTrue(viewModel.IsDirty);
        }
        public void WhenEnablingOrDisablingCustomProxy_ThenSettingsAreSaved()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object)
            {
                // Enable proxy with authentication.
                IsCustomProxyServerEnabled = true,
                ProxyServer   = "prx",
                ProxyPort     = "123",
                ProxyUsername = "******",
                ProxyPassword = "******"
            };

            viewModel.ApplyChanges();

            var settings = this.settingsRepository.GetSettings();

            Assert.AreEqual("http://prx:123", settings.ProxyUrl.StringValue);
            Assert.AreEqual("user", settings.ProxyUsername.StringValue);
            Assert.AreEqual("pass", settings.ProxyPassword.ClearTextValue);

            // Disable authentication.
            viewModel.IsProxyAuthenticationEnabled = false;
            viewModel.ApplyChanges();

            settings = this.settingsRepository.GetSettings();
            Assert.AreEqual("http://prx:123", settings.ProxyUrl.StringValue);
            Assert.IsNull(settings.ProxyUsername.StringValue);
            Assert.IsNull(settings.ProxyPassword.ClearTextValue);

            // Revert to system proxy.
            viewModel.IsSystemProxyServerEnabled = true;
            viewModel.ApplyChanges();

            settings = this.settingsRepository.GetSettings();
            Assert.IsNull(settings.ProxyUrl.StringValue);
            Assert.IsNull(settings.ProxyUsername.StringValue);
            Assert.IsNull(settings.ProxyPassword.ClearTextValue);
        }
Ejemplo n.º 16
0
        public void WhenProxyAutoconfigConfigured_ThenPropertiesAreInitializedCorrectly()
        {
            var settings = this.settingsRepository.GetSettings();

            settings.ProxyPacUrl.StringValue = "http://proxy-server/proxy.pac";
            this.settingsRepository.SetSettings(settings);

            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            Assert.IsFalse(viewModel.IsSystemProxyServerEnabled);
            Assert.IsTrue(viewModel.IsProxyAutoConfigurationEnabled);
            Assert.IsFalse(viewModel.IsCustomProxyServerEnabled);
            Assert.IsNull(viewModel.ProxyServer);
            Assert.IsNull(viewModel.ProxyPort);
            Assert.AreEqual("http://proxy-server/proxy.pac", viewModel.ProxyAutoconfigurationAddress);
            Assert.IsFalse(viewModel.IsProxyAuthenticationEnabled);
            Assert.IsNull(viewModel.ProxyUsername);
            Assert.IsNull(viewModel.ProxyPassword);
            Assert.IsFalse(viewModel.IsDirty);
        }
        public void WhenDisablingProxyAutoconfig_ThenProxyHostAndPortAreCleared()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object)
            {
                IsProxyAutoConfigurationEnabled = true,
                ProxyAutoconfigurationAddress   = "http://proxy-server/proxy.pac",
                IsSystemProxyServerEnabled      = true
            };

            Assert.IsTrue(viewModel.IsSystemProxyServerEnabled);
            Assert.IsFalse(viewModel.IsCustomProxyServerEnabled);
            Assert.IsFalse(viewModel.IsProxyAutoConfigurationEnabled);
            Assert.IsNull(viewModel.ProxyServer);
            Assert.IsNull(viewModel.ProxyPort);
            Assert.IsNull(viewModel.ProxyAutoconfigurationAddress);
            Assert.IsFalse(viewModel.IsProxyAuthenticationEnabled);
            Assert.IsNull(viewModel.ProxyUsername);
            Assert.IsNull(viewModel.ProxyPassword);
            Assert.IsTrue(viewModel.IsDirty);
        }
Ejemplo n.º 18
0
        public void WhenEnablingOrDisablingProxyAutoconfig_ThenSettingsAreSaved()
        {
            var viewModel = new NetworkOptionsViewModel(
                this.settingsRepository,
                this.proxyAdapterMock.Object);

            // Enable proxy with authentication.
            viewModel.IsProxyAutoConfigurationEnabled = true;
            viewModel.ProxyAutoconfigurationAddress   = "https://www/proxy.pac";
            viewModel.ProxyUsername = "******";
            viewModel.ProxyPassword = "******";
            viewModel.ApplyChanges();

            var settings = this.settingsRepository.GetSettings();

            Assert.AreEqual("https://www/proxy.pac", settings.ProxyPacUrl.StringValue);
            Assert.AreEqual("user", settings.ProxyUsername.StringValue);
            Assert.AreEqual("pass", settings.ProxyPassword.ClearTextValue);

            // Disable authentication.
            viewModel.IsProxyAuthenticationEnabled = false;
            viewModel.ApplyChanges();

            settings = this.settingsRepository.GetSettings();
            Assert.AreEqual("https://www/proxy.pac", settings.ProxyPacUrl.StringValue);
            Assert.IsNull(settings.ProxyUsername.StringValue);
            Assert.IsNull(settings.ProxyPassword.ClearTextValue);

            // Revert to system proxy.
            viewModel.IsSystemProxyServerEnabled = true;
            viewModel.ApplyChanges();

            settings = this.settingsRepository.GetSettings();
            Assert.IsNull(settings.ProxyUrl.StringValue);
            Assert.IsNull(settings.ProxyUsername.StringValue);
            Assert.IsNull(settings.ProxyPassword.ClearTextValue);
        }