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 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 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 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); }
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 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 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 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); }