public ViewModelLocator() { Navigation = new NavigationService(); MainViewModel = new MainViewModel(); DialogViewModel = new DialogViewModel(); LogScreenWindowViewModel = new LogScreenWindowViewModel(); FirstScreenViewModel = new FirstScreenViewModel(Navigation); AddHostViewModel = new AddHostViewModel(Navigation); AddCategoryViewModel = new AddCategoryViewModel(Navigation); EditCategoryViewModel = new EditCategoryViewModel(Navigation); SettingsViewModel = new SettingsViewModel(Navigation); LogScreenViewModel = new LogScreenViewModel(Navigation); Navigation.RegisterPage("FirstScreen", FirstScreenViewModel); Navigation.RegisterPage("AddHost", AddHostViewModel); Navigation.RegisterPage("AddCategory", AddCategoryViewModel); Navigation.RegisterPage("EditCategory", EditCategoryViewModel); Navigation.RegisterPage("Settings", SettingsViewModel); Navigation.RegisterPage("LogScreen", LogScreenViewModel); Navigation.GoTo("FirstScreen"); }
private async void ButtonAddEndpoints_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrWhiteSpace(TextBoxUrlInput.Text)) { return; } BeginLoadingIndication(); var result = await AddHostViewModel.ConnectToHosts(_wuEndpointFactory, _endpointCollection, TextBoxUrlInput.Text); StopLoadingIndication(); if (result.Any(a => a.Success && a.Exception is EndpointNeedsUpgradeException)) { string text = "The following hosts are outdated and should be upgraded:" + Environment.NewLine + String.Join(Environment.NewLine, result.Where(a => a.Success && a.Exception is EndpointNeedsUpgradeException).Select(a => a.Endpoint.FQDN)); _modalService.ShowMessageBox(text, "Outdated hosts.", MessageType.Info); } if (result.Any(a => !a.Success)) { TextBoxUrlInput.Text = String.Join(Environment.NewLine, result.Where(a => !a.Success).Select(a => a.Url)); _modalService.ShowMessageBox(String.Join(Environment.NewLine + Environment.NewLine, result.Where(a => !a.Success).Select(a => a.Url + ": " + a.Exception.Message)), "Connect to hosts", MessageType.Warning); } else { Close(); } }
public void Should_NotAllowOnlyWhiteSpaces_When_ConnectToHosts() { WaitForTaskAndThrow(AddHostViewModel.ConnectToHosts( new Mock <WuEndpointFactory>().Object, new WuEndpointCollection(), $" {Environment.NewLine} {Environment.NewLine}"), 2000); }
public void Should_ThrowException_When_InvalidUrlGiven() { var result = WaitForTaskAndThrow(AddHostViewModel.ConnectToHosts( new Mock <WuEndpointFactory>().Object, new WuEndpointCollection(), "//#?net.tcp://localhost:8523/WuRemoteService"), 2000); Assert.IsFalse(result.First().Success); Assert.IsTrue(result.First().Exception is ArgumentException); }
public void Should_ContainSpecifiedUrl_When_CreateAddHostViewModel() { var url = "//net.tcp://test"; var result = WaitForTaskAndThrow(AddHostViewModel.ConnectToHosts( new Mock <WuEndpointFactory>().Object, new WuEndpointCollection(), url), 2000); Assert.AreEqual(result.First().Url, url); }
public void Should_IndicateFailure_When_FailedToConnect() { var result = WaitForTaskAndThrow(AddHostViewModel.ConnectToHosts( new WuEndpointFactoryMock(null, new Exception("mock"), false), new WuEndpointCollection(), "test"), 5000); Assert.IsNotNull(result); Assert.IsTrue(result.Count() == 1); Assert.IsFalse(result.First().Success); Assert.IsNotNull(result.First().Exception); }
public void Should_ConnectToEndpointWithDefaultSettings_When_OnlyHostnameGiven() { var wuEndpoint = new Mock <IWuEndpoint>(); wuEndpoint.Setup(e => e.ConnectionState).Returns(CommunicationState.Created); var result = WaitForTaskAndThrow(AddHostViewModel.ConnectToHosts( new WuEndpointFactoryMock(wuEndpoint.Object, null, true), new WuEndpointCollection(), "localhost"), 5000); Assert.IsNotNull(result); Assert.IsTrue(result.Count() == 1); Assert.IsTrue(result.First().Success); }
public void Should_OnlyUseConnectedEndpoints_When_TestForAlreadyConntectedHost() { var endpointFactory = new Mock <WuEndpointFactory>(); var wuEndpoint1 = new Mock <IWuEndpoint>(); wuEndpoint1.Setup(e => e.ConnectionState).Returns(CommunicationState.Created); wuEndpoint1.Setup(e => e.FQDN).Returns("t1"); endpointFactory.Setup(m => m.TryCreateWuEndpoint( It.IsAny <Binding>(), It.Is <EndpointAddress>(e => e.Uri.Host.Equals($"t1")), out It.Ref <IWuEndpoint> .IsAny, out It.Ref <Exception> .IsAny )).Returns(new TryCreateWuEndpointCallback((Binding binding, EndpointAddress endpointAddress, out IWuEndpoint enpoint, out Exception ex) => { enpoint = wuEndpoint1.Object; ex = null; return(true); })); endpointFactory.Setup(m => m.TryCreateWuEndpoint( It.IsAny <Binding>(), It.Is <EndpointAddress>(e => e.Uri.Host.Equals($"t2")), out It.Ref <IWuEndpoint> .IsAny, out It.Ref <Exception> .IsAny )).Returns(new TryCreateWuEndpointCallback((Binding binding, EndpointAddress endpointAddress, out IWuEndpoint enpoint, out Exception ex) => { enpoint = null; ex = new Exception("mock"); return(false); })); var result1 = WaitForTaskAndThrow(AddHostViewModel.ConnectToHosts( endpointFactory.Object, new WuEndpointCollection(), $"t1{Environment.NewLine}t2"), 5000000); Assert.IsTrue(result1.Count(e => e.Success) == 1); }
public void Should_DismissConnection_When_ConnectToAlreadyConntectedHost() { var wuEndpoint = new Mock <IWuEndpoint>(); wuEndpoint.Setup(e => e.ConnectionState).Returns(CommunicationState.Created); wuEndpoint.Setup(e => e.FQDN).Returns("samename"); var endpointCol = new WuEndpointCollection(); var result1 = WaitForTaskAndThrow(AddHostViewModel.ConnectToHosts( new WuEndpointFactoryMock(null, true, wuEndpoint.Object, wuEndpoint.Object), endpointCol, $"samename{Environment.NewLine}samename"), 5000); var result2 = WaitForTaskAndThrow(AddHostViewModel.ConnectToHosts( new WuEndpointFactoryMock(null, true, wuEndpoint.Object), endpointCol, $"samename"), 5000); Assert.IsTrue(result1.Count() == 1); Assert.IsTrue(result2.Count() == 0); Assert.IsTrue(endpointCol.Count == 1); }
public void Should_IgnoreEmptyLines_When_ConnectToHosts() { var wuEndpoint1 = new Mock <IWuEndpoint>(); wuEndpoint1.Setup(e => e.ConnectionState).Returns(CommunicationState.Created); wuEndpoint1.Setup(e => e.FQDN).Returns("s1"); var wuEndpoint2 = new Mock <IWuEndpoint>(); wuEndpoint2.Setup(e => e.ConnectionState).Returns(CommunicationState.Created); wuEndpoint2.Setup(e => e.FQDN).Returns("s2"); var result = WaitForTaskAndThrow(AddHostViewModel.ConnectToHosts( new WuEndpointFactoryMock(null, true, wuEndpoint1.Object, wuEndpoint2.Object), new WuEndpointCollection(), $"test1{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}test2"), 5000); Trace.WriteLine(result.First().Url); Assert.IsNotNull(result); Assert.IsTrue(result.Count() == 2); Assert.IsTrue(result.All(r => r.Success)); }
public AddHostPage() { InitializeComponent(); BindingContext = _viewModel = new AddHostViewModel(Navigation); }
public void Should_NotAllowNullString_When_ConnectToHosts() { WaitForTaskAndThrow(AddHostViewModel.ConnectToHosts( new WuEndpointFactory(), new WuEndpointCollection(), null), 2000); }