Inheritance: INotifyPropertyChanged, IConnectControlViewModel
 public void ConnectControlViewModel_AddNewServer_ResourceRepositoryReturnExistingServers_False()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var env1 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid(), CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var env2 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid(), CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var connectControlEnvironments = new ObservableCollection<IConnectControlEnvironment>();
     var controEnv1 = new Mock<IConnectControlEnvironment>();
     var controEnv2 = new Mock<IConnectControlEnvironment>();
     controEnv1.Setup(c => c.EnvironmentModel).Returns(env1);
     controEnv2.Setup(c => c.EnvironmentModel).Returns(env2);
     controEnv1.Setup(c => c.IsConnected).Returns(true);
     connectControlEnvironments.Add(controEnv2.Object);
     connectControlEnvironments.Add(controEnv1.Object);
     connectControlSingleton.Setup(c => c.Servers).Returns(connectControlEnvironments);
     var environmentRepository = new Mock<IEnvironmentRepository>();
     ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>
         {
             env1
         };
     environmentRepository.Setup(e => e.All()).Returns(environments);
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", false);
     //------------Execution-------------------------------
     int serverIndex;
     var didAddNew = viewModel.AddNewServer(out serverIndex, i => { });
     //------------Assert----------------------------------
     Assert.IsNotNull(viewModel);
     Assert.IsFalse(didAddNew);
 }
 static void TestSelectedIndex(int selectedServerIndex, int expectedVal)
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var activeEnvironment = new Mock<IEnvironmentModel>();
     var env1Id = Guid.NewGuid();
     var env2Id = Guid.NewGuid();
     activeEnvironment.Setup(a => a.ID).Returns(env1Id);
     mainViewModel.Setup(m => m.ActiveEnvironment).Returns(activeEnvironment.Object);
     var env1 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env1Id, CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var env2 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env2Id, CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var connectControlEnvironments = new ObservableCollection<IConnectControlEnvironment>();
     var controEnv1 = new Mock<IConnectControlEnvironment>();
     var controEnv2 = new Mock<IConnectControlEnvironment>();
     controEnv1.Setup(c => c.EnvironmentModel).Returns(env1);
     controEnv2.Setup(c => c.EnvironmentModel).Returns(env2);
     controEnv1.Setup(c => c.IsConnected).Returns(false);
     connectControlEnvironments.Add(controEnv2.Object);
     connectControlEnvironments.Add(controEnv1.Object);
     connectControlSingleton.Setup(c => c.Servers).Returns(connectControlEnvironments);
     var environmentRepository = new Mock<IEnvironmentRepository>();
     ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>
         {
             env1
         };
     environmentRepository.Setup(e => e.All()).Returns(environments);
     //------------Execution-------------------------------
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", true)
         {
             SelectedServerIndex = selectedServerIndex
         };
     //------------Assert-------------------------------
     Assert.AreEqual(expectedVal, viewModel.SelectedServerIndex);
 }
 public void ConnectControlViewModel_AddNewServer_ResourceRepositoryReturnsAServer_True()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var environmentRepository = new Mock<IEnvironmentRepository>();
     connectControlSingleton.Setup(c => c.ToggleConnection(It.IsAny<int>()))
                            .Verifiable();
     ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>
         {
             new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid(), CreateConnection(false, false).Object, new Mock<IResourceRepository>().Object, false)
         };
     environmentRepository.Setup(e => e.All()).Returns(environments);
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", false);
     //------------Execution-------------------------------
     int serverIndex;
     var didAddNew = viewModel.AddNewServer(out serverIndex, i => { });
     //------------Assert----------------------------------
     Assert.IsNotNull(viewModel);
     Assert.IsTrue(didAddNew);
     Assert.AreEqual(0, serverIndex);
     Assert.AreEqual(1, viewModel.Servers.Count);
     connectControlSingleton.Verify(c => c.ToggleConnection(It.IsAny<int>()), Times.Once());
 }
 public void ConnectControlViewModel_UpdateActiveEnvironment_ActiveServerHasChangedToAServerOnTheList_SelectedIndexIsChanged()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     mainViewModel.Setup(m => m.SetActiveEnvironment(It.IsAny<IEnvironmentModel>())).Verifiable();
     var activeEnvironment = new Mock<IEnvironmentModel>();
     var env1Id = Guid.NewGuid();
     var env2Id = Guid.NewGuid();
     activeEnvironment.Setup(a => a.ID).Returns(env1Id);
     mainViewModel.Setup(m => m.ActiveEnvironment).Returns(activeEnvironment.Object);
     var env1 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env1Id, CreateConnection(true, true).Object, new Mock<IResourceRepository>().Object, false);
     var env2 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env2Id, CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var connectControlEnvironments = new ObservableCollection<IConnectControlEnvironment>();
     var controEnv1 = new Mock<IConnectControlEnvironment>();
     var controEnv2 = new Mock<IConnectControlEnvironment>();
     controEnv1.Setup(c => c.EnvironmentModel).Returns(env1);
     controEnv2.Setup(c => c.EnvironmentModel).Returns(env2);
     controEnv1.Setup(c => c.IsConnected).Returns(false);
     connectControlEnvironments.Add(controEnv2.Object);
     connectControlEnvironments.Add(controEnv1.Object);
     connectControlSingleton.Setup(c => c.Servers).Returns(connectControlEnvironments);
     var environmentRepository = new Mock<IEnvironmentRepository>();
     ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>
         {
             env1
         };
     environmentRepository.Setup(e => e.All()).Returns(environments);
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", true);
     Mock<IEnvironmentModel> selectedEnv = new Mock<IEnvironmentModel>();
     selectedEnv.Setup(e => e.ID).Returns(env2Id);
     var indexBefore = viewModel.SelectedServerIndex;
     //------------Execution-------------------------------
     viewModel.UpdateActiveEnvironment(selectedEnv.Object, false);
     //------------Assert----------------------------------
     Assert.AreEqual(1, indexBefore);
     Assert.AreEqual(0, viewModel.SelectedServerIndex);
     mainViewModel.Verify(m => m.SetActiveEnvironment(It.IsAny<IEnvironmentModel>()), Times.Exactly(1));
 }
 public void ConnectControlViewModel_SetTargetEnvironment_NoConnectedServerOtherThanLocalhost_SelectedIndexNotChanged()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var env1 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid(), CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var env2 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid(), CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var connectControlEnvironments = new ObservableCollection<IConnectControlEnvironment>();
     var controEnv1 = new Mock<IConnectControlEnvironment>();
     var controEnv2 = new Mock<IConnectControlEnvironment>();
     controEnv1.Setup(c => c.EnvironmentModel).Returns(env1);
     controEnv2.Setup(c => c.EnvironmentModel).Returns(env2);
     controEnv1.Setup(c => c.IsConnected).Returns(false);
     connectControlEnvironments.Add(controEnv2.Object);
     connectControlEnvironments.Add(controEnv1.Object);
     connectControlSingleton.Setup(c => c.Servers).Returns(connectControlEnvironments);
     var environmentRepository = new Mock<IEnvironmentRepository>();
     ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>
         {
             env1
         };
     environmentRepository.Setup(e => e.All()).Returns(environments);
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", false);
     var indexBefore = viewModel.SelectedServerIndex;
     //------------Execution-------------------------------
     viewModel.SetTargetEnvironment();
     //------------Assert----------------------------------
     Assert.AreEqual(indexBefore, viewModel.SelectedServerIndex);
 }
 public void ConnectControlViewModel_SelectedIndex_SetToNewServerAndNewServerWasAdded_SelectedIndexSetToNewServerIndex()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var activeEnvironment = new Mock<IEnvironmentModel>();
     var env1Id = Guid.NewGuid();
     var env2Id = Guid.NewGuid();
     activeEnvironment.Setup(a => a.ID).Returns(env1Id);
     mainViewModel.Setup(m => m.ActiveEnvironment).Returns(activeEnvironment.Object);
     var env1 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env1Id, CreateConnection(false, false, ConnectControlSingleton.NewServerText).Object, new Mock<IResourceRepository>().Object, false)
     {
         Name = ConnectControlSingleton.NewServerText
     };
     var env2 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env2Id, CreateConnection(true, true).Object, new Mock<IResourceRepository>().Object, false)
     {
         Name = "AzureOnFire"
     };
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var connectControlEnvironments = new ObservableCollection<IConnectControlEnvironment>();
     var controEnv1 = new Mock<IConnectControlEnvironment>();
     var controEnv2 = new Mock<IConnectControlEnvironment>();
     controEnv1.Setup(c => c.EnvironmentModel).Returns(env1);
     controEnv2.Setup(c => c.EnvironmentModel).Returns(env2);
     controEnv1.Setup(c => c.IsConnected).Returns(false);
     connectControlEnvironments.Add(controEnv1.Object);
     connectControlEnvironments.Add(controEnv2.Object);
     connectControlSingleton.Setup(c => c.Servers).Returns(connectControlEnvironments);
     var environmentRepository = new Mock<IEnvironmentRepository>();
     ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>
         {
              new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid() , CreateConnection(false, false).Object, new Mock<IResourceRepository>().Object, false)
                 {
                     Name = "New One"
                 }
         };
     environmentRepository.Setup(e => e.All()).Returns(environments);
     //------------Execution-------------------------------
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", true, (model, type, arg3, arg4, arg5, arg6, arg7) => { }) { SelectedServerIndex = 0 };
     //------------Assert------------------------------
     Assert.IsNotNull(viewModel);
     Assert.AreEqual(2, viewModel.SelectedServerIndex);
 }
 public void ConnectControlViewModel_OpenConnectionWizard_IndexPositive_OpensWizardForEditConnection()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var activeEnvironment = new Mock<IEnvironmentModel>();
     var env1Id = Guid.NewGuid();
     var env2Id = Guid.NewGuid();
     activeEnvironment.Setup(a => a.ID).Returns(env1Id);
     mainViewModel.Setup(m => m.ActiveEnvironment).Returns(activeEnvironment.Object);
     var env1 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env1Id, CreateConnection(false, false, ConnectControlSingleton.NewServerText).Object, new Mock<IResourceRepository>().Object, false)
     {
         Name = ConnectControlSingleton.NewServerText
     };
     var env2 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env2Id, CreateConnection(true, true).Object, new Mock<IResourceRepository>().Object, false)
     {
         Name = "AzureOnFire"
     };
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var connectControlEnvironments = new ObservableCollection<IConnectControlEnvironment>();
     var controEnv1 = new Mock<IConnectControlEnvironment>();
     var controEnv2 = new Mock<IConnectControlEnvironment>();
     controEnv1.Setup(c => c.EnvironmentModel).Returns(env1);
     controEnv2.Setup(c => c.EnvironmentModel).Returns(env2);
     controEnv1.Setup(c => c.IsConnected).Returns(false);
     connectControlEnvironments.Add(controEnv1.Object);
     connectControlEnvironments.Add(controEnv2.Object);
     connectControlSingleton.Setup(c => c.Servers).Returns(connectControlEnvironments);
     var environmentRepository = new Mock<IEnvironmentRepository>();
     ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>();
     environmentRepository.Setup(e => e.All()).Returns(environments);
     var actualEnvironmentId = Guid.Empty.ToString();
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", true, (model, type, arg3, arg4, environmentId, arg6, arg7) =>
     {
         actualEnvironmentId = environmentId;
     });
     //------------Execution-------------------------------
     viewModel.OpenConnectionWizard(1);
     //------------Assert------------------------------
     Assert.IsNotNull(viewModel);
     Assert.AreNotEqual(Guid.Empty.ToString(), actualEnvironmentId);
 }
 public void ConnectControlViewModel_EditCommand_Execute_CallsEditConnection()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var activeEnvironment = new Mock<IEnvironmentModel>();
     var env1Id = Guid.NewGuid();
     var env2Id = Guid.NewGuid();
     activeEnvironment.Setup(a => a.ID).Returns(env1Id);
     mainViewModel.Setup(m => m.ActiveEnvironment).Returns(activeEnvironment.Object);
     var env1 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env1Id, CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var env2 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env2Id, CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var connectControlEnvironments = new ObservableCollection<IConnectControlEnvironment>();
     var controEnv1 = new Mock<IConnectControlEnvironment>();
     var controEnv2 = new Mock<IConnectControlEnvironment>();
     controEnv1.Setup(c => c.EnvironmentModel).Returns(env1);
     controEnv2.Setup(c => c.EnvironmentModel).Returns(env2);
     controEnv1.Setup(c => c.IsConnected).Returns(false);
     connectControlEnvironments.Add(controEnv2.Object);
     connectControlEnvironments.Add(controEnv1.Object);
     connectControlSingleton.Setup(c => c.Servers).Returns(connectControlEnvironments);
     var environmentRepository = new Mock<IEnvironmentRepository>();
     ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>
         {
             env1
         };
     environmentRepository.Setup(e => e.All()).Returns(environments);
     connectControlSingleton.Setup(c => c.EditConnection(It.IsAny<int>(), It.IsAny<Action<int>>())).Verifiable();
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", true);
     //------------Execution-------------------------------
     viewModel.EditCommand.Execute(null);
     //------------Assert------------------------------
     Assert.IsNotNull(viewModel);
     connectControlSingleton.Verify(c => c.EditConnection(It.IsAny<int>(), It.IsAny<Action<int>>()), Times.Once());
 }
 public void ConnectControlViewModel_Constructor_WhenServersCollectionHasLocalHost_SelectedIndexDefaultsToLocalHost()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var env1 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid(), CreateConnection(true, true).Object, new Mock<IResourceRepository>().Object, false);
     var env2 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid(), CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var connectControlEnvironments = new ObservableCollection<IConnectControlEnvironment>();
     var controEnv1 = new Mock<IConnectControlEnvironment>();
     var controEnv2 = new Mock<IConnectControlEnvironment>();
     controEnv1.Setup(c => c.EnvironmentModel).Returns(env1);
     controEnv2.Setup(c => c.EnvironmentModel).Returns(env2);
     controEnv1.Setup(c => c.IsConnected).Returns(true);
     connectControlEnvironments.Add(controEnv2.Object);
     connectControlEnvironments.Add(controEnv1.Object);
     connectControlSingleton.Setup(c => c.Servers).Returns(connectControlEnvironments);
     var environmentRepository = new Mock<IEnvironmentRepository>();
     ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>
         {
             env1
         };
     environmentRepository.Setup(e => e.All()).Returns(environments);
     //------------Execution-------------------------------
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", false);
     //------------Assert----------------------------------
     Assert.AreEqual(1, viewModel.SelectedServerIndex);
 }
 public void ConnectControlViewModel_Constructor_VariablesAreInitialized()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var environmentRepository = new Mock<IEnvironmentRepository>();
     environmentRepository.Setup(e => e.All()).Returns((ICollection<IEnvironmentModel>)null);
     //------------Execution-------------------------------
     const string labelText = "TEST : ";
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, labelText, false);
     //------------Assert----------------------------------
     Assert.AreEqual(0, viewModel.SelectedServerIndex);
     Assert.AreEqual(null, viewModel.SelectedServer);
     Assert.AreEqual(false, viewModel.IsConnectButtonSpinnerVisible);
     Assert.AreEqual(true, viewModel.IsDropDownEnabled);
     Assert.AreEqual(true, viewModel.IsEnabled);
     Assert.AreEqual(0, viewModel.Servers.Count);
     Assert.AreEqual(labelText, viewModel.LabelText);
 }
 public void ConnectControlViewModel_ConnectedStatusChangedHandler_SetConnectedStateAndEnvironmentIdWasFound_ConnectButtonSpinnerIsNotVisible()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var activeEnvironment = new Mock<IEnvironmentModel>();
     var env1Id = Guid.NewGuid();
     var env2Id = Guid.NewGuid();
     activeEnvironment.Setup(a => a.ID).Returns(env1Id);
     mainViewModel.Setup(m => m.ActiveEnvironment).Returns(activeEnvironment.Object);
     var env1 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env1Id, CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var env2 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env2Id, CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var connectControlEnvironments = new ObservableCollection<IConnectControlEnvironment>();
     var controEnv1 = new Mock<IConnectControlEnvironment>();
     var controEnv2 = new Mock<IConnectControlEnvironment>();
     controEnv1.Setup(c => c.EnvironmentModel).Returns(env1);
     controEnv2.Setup(c => c.EnvironmentModel).Returns(env2);
     controEnv1.Setup(c => c.IsConnected).Returns(false);
     connectControlEnvironments.Add(controEnv2.Object);
     connectControlEnvironments.Add(controEnv1.Object);
     connectControlSingleton.Setup(c => c.Servers).Returns(connectControlEnvironments);
     var environmentRepository = new Mock<IEnvironmentRepository>();
     ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>
         {
             env1
         };
     environmentRepository.Setup(e => e.All()).Returns(environments);
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", true);
     //------------Execution-------------------------------
     viewModel.ConnectedStatusChanged(null, new ConnectionStatusChangedEventArg(ConnectionEnumerations.ConnectedState.Connected, env1Id, false));
     //------------Execution-------------------------------
     Assert.IsNotNull(viewModel);
     Assert.IsFalse(viewModel.IsConnectButtonSpinnerVisible);
     Assert.IsTrue(viewModel.IsDropDownEnabled);
 }
 public void ConnectControlViewModel_ConnectedServerChangedHandler_ServerIdFound_SelectedIndexChanged()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var activeEnvironment = new Mock<IEnvironmentModel>();
     var env1Id = Guid.NewGuid();
     var env2Id = Guid.NewGuid();
     activeEnvironment.Setup(a => a.ID).Returns(env1Id);
     mainViewModel.Setup(m => m.ActiveEnvironment).Returns(activeEnvironment.Object);
     var env1 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env1Id, CreateConnection(true, true).Object, new Mock<IResourceRepository>().Object, false);
     var env2 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, env2Id, CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var connectControlEnvironments = new ObservableCollection<IConnectControlEnvironment>();
     var controEnv1 = new Mock<IConnectControlEnvironment>();
     var controEnv2 = new Mock<IConnectControlEnvironment>();
     controEnv1.Setup(c => c.EnvironmentModel).Returns(env1);
     controEnv2.Setup(c => c.EnvironmentModel).Returns(env2);
     controEnv1.Setup(c => c.IsConnected).Returns(false);
     connectControlEnvironments.Add(controEnv2.Object);
     connectControlEnvironments.Add(controEnv1.Object);
     connectControlSingleton.Setup(c => c.Servers).Returns(connectControlEnvironments);
     var environmentRepository = new Mock<IEnvironmentRepository>();
     ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>
         {
             env1
         };
     environmentRepository.Setup(e => e.All()).Returns(environments);
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", true);
     var selectedIndexBefore = viewModel.SelectedServerIndex;
     //------------Execution-------------------------------
     viewModel.ConnectedServerChanged(null, new ConnectedServerChangedEvent(env2Id));
     //------------Execution-------------------------------
     Assert.IsNotNull(viewModel);
     Assert.AreEqual(1, selectedIndexBefore);
     Assert.AreEqual(0, viewModel.SelectedServerIndex);
 }
 public void ConnectControlViewModel_AddNewServer_ResourceRepositoryReturnsNull_False()
 {
     //------------Setup for test--------------------------
     var mainViewModel = new Mock<IMainViewModel>();
     var connectControlSingleton = new Mock<IConnectControlSingleton>();
     var environmentRepository = new Mock<IEnvironmentRepository>();
     connectControlSingleton.Setup(c => c.ToggleConnection(It.IsAny<int>()))
                          .Verifiable();
     environmentRepository.Setup(e => e.All()).Returns((ICollection<IEnvironmentModel>)null);
     var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", false);
     //------------Execution-------------------------------
     int serverIndex;
     var didAddNew = viewModel.AddNewServer(out serverIndex, i => { });
     //------------Assert----------------------------------
     Assert.IsNotNull(viewModel);
     Assert.IsFalse(didAddNew);
     Assert.AreEqual(-1, serverIndex);
     Assert.AreEqual(0, viewModel.Servers.Count);
     connectControlSingleton.Verify(c => c.ToggleConnection(It.IsAny<int>()), Times.Never());
 }