public void ConnectControlViewModel_TestConnectNullArgument() { //act var result = _target.TryConnectAsync(null); result.Wait(); //assert Assert.IsFalse(result.Result); }
public void ConnectControlViewModel_TestConnectSuccessful() { //arrange var mockServer = new Mock <IServer>(); var mockShellViewModel = new Mock <IShellViewModel>(); var mockEventAggregator = new Mock <IEventAggregator>(); var mockPopupController = new Mock <IPopupController>(); var mockEnvironmentConnection = new Mock <IEnvironmentConnection>(); var serverEnvironmentId = Guid.NewGuid(); var serverConnectedRaised = false; var rand = new Random(); mockEnvironmentConnection.Setup(o => o.IsConnected).Returns(true); mockEnvironmentConnection.Setup(o => o.AppServerUri).Returns((new Uri($"http://127.0.0.{rand.Next(1, 100)}:{rand.Next(1, 100)}/dsf"))); mockServer.Setup(it => it.ConnectAsync()).ReturnsAsync(true); mockServer.SetupGet(it => it.EnvironmentID).Returns(serverEnvironmentId); mockServer.SetupGet(it => it.DisplayName).Returns("display name"); mockServer.SetupGet(it => it.IsConnected).Returns(true); mockServer.SetupGet(it => it.Connection).Returns(mockEnvironmentConnection.Object); mockServer.SetupGet(o => o.Connection.AppServerUri).Returns((new Uri($"http://127.0.0.{rand.Next(1, 100)}:{rand.Next(1, 100)}/dsf"))); var connectControlViewModel = new ConnectControlViewModel(mockServer.Object, mockEventAggregator.Object) { ShouldUpdateActiveEnvironment = true }; connectControlViewModel.ServerConnected = (sender, e) => { serverConnectedRaised = sender == connectControlViewModel && Equals(e, mockServer.Object); }; CustomContainer.Register(mockShellViewModel.Object); mockPopupController.Setup(it => it.ShowConnectionTimeoutConfirmation("DisplayName")) .Returns <string>( dispName => { mockServer.Setup(it => it.ConnectAsync()).ReturnsAsync(true); return(MessageBoxResult.Yes); }); CustomContainer.Register(mockPopupController.Object); //act connectControlViewModel.SelectedConnection = new Server(serverEnvironmentId, mockEnvironmentConnection.Object); var result = connectControlViewModel.TryConnectAsync(mockServer.Object); //assert Assert.IsTrue(result.Result); Assert.IsTrue(serverConnectedRaised); mockServer.Verify(it => it.ConnectAsync()); mockShellViewModel.Verify(it => it.SetActiveServer(mockServer.Object.EnvironmentID)); }
public async Task Connect_GivenShowConnectionTimeoutConfirmation_MessageBox_Yes() { //------------Setup for test-------------------------- var popupController = new Mock <IPopupController>(); popupController.SetupSequence(controller => controller.ShowConnectionTimeoutConfirmation(_serverMock.Object.DisplayName)) .Returns(MessageBoxResult.Yes) .Returns(MessageBoxResult.None); var connectControlViewModel = new ConnectControlViewModel(_serverMock.Object, new EventAggregator(), popupController.Object); //------------Execute Test--------------------------- var connect = await connectControlViewModel.TryConnectAsync(_serverMock.Object); //------------Assert Results------------------------- Assert.IsNotNull(connect); }