Наследование: Dev2.Studio.Core.Models.EnvironmentModel
 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);
 }
Пример #2
0
        public void EnvironmentModel_AuthorizationService_PermissionsChanged_IsAuthorizedDeployToAndIsAuthorizedDeployFromChanged()
        {
            //------------Setup for test--------------------------
            var connection = CreateConnection();

            var envModel = new TestEnvironmentModel(new Mock <IEventAggregator>().Object, Guid.NewGuid(), connection.Object, new Mock <IResourceRepository>().Object, false);

            connection.Raise(environmentConnection => environmentConnection.NetworkStateChanged += null, new NetworkStateEventArgs(NetworkState.Offline, NetworkState.Online));
            envModel.AuthorizationServiceMock.Setup(a => a.IsAuthorized(AuthorizationContext.DeployFrom, null)).Returns(false).Verifiable();
            envModel.AuthorizationServiceMock.Setup(a => a.IsAuthorized(AuthorizationContext.DeployTo, null)).Returns(false).Verifiable();

            Assert.IsFalse(envModel.IsAuthorizedDeployFrom);
            Assert.IsFalse(envModel.IsAuthorizedDeployTo);

            //------------Execute Test---------------------------
            envModel.AuthorizationServiceMock.Setup(a => a.IsAuthorized(AuthorizationContext.DeployFrom, null)).Returns(true).Verifiable();
            envModel.AuthorizationServiceMock.Setup(a => a.IsAuthorized(AuthorizationContext.DeployTo, null)).Returns(true).Verifiable();
            envModel.AuthorizationServiceMock.Raise(a => a.PermissionsChanged += null, EventArgs.Empty);

            //------------Assert Results-------------------------
            envModel.AuthorizationServiceMock.Verify(a => a.IsAuthorized(AuthorizationContext.DeployFrom, null));
            envModel.AuthorizationServiceMock.Verify(a => a.IsAuthorized(AuthorizationContext.DeployTo, null));
            Assert.IsTrue(envModel.IsAuthorizedDeployFrom);
            Assert.IsTrue(envModel.IsAuthorizedDeployTo);
        }
Пример #3
0
        public void EnvironmentModel_Connection_PermissionsChanged_IsAuthorizedChanged()
        {
            //------------Setup for test--------------------------
            var connection = CreateConnection();

            connection.Setup(c => c.IsAuthorized).Returns(false);

            var envModel = new TestEnvironmentModel(new Mock <IEventAggregator>().Object, Guid.NewGuid(), connection.Object, new Mock <IResourceRepository>().Object, false);

            Assert.IsFalse(envModel.IsAuthorized);

            //------------Execute Test---------------------------
            connection.Setup(c => c.IsAuthorized).Returns(true);
            connection.Raise(c => c.PermissionsChanged += null, EventArgs.Empty);

            //------------Assert Results-------------------------
            Assert.IsTrue(envModel.IsAuthorized);
        }
Пример #4
0
        public void EnvironmentModel_AuthorizationService_PermissionsChanged_IsAuthorizedDeployToAndIsAuthorizedDeployFromChanged()
        {
            //------------Setup for test--------------------------
            var connection = CreateConnection();

            var envModel = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid(), connection.Object, new Mock<IResourceRepository>().Object, false);
            connection.Raise(environmentConnection => environmentConnection.NetworkStateChanged += null, new NetworkStateEventArgs(NetworkState.Offline, NetworkState.Online));
            envModel.AuthorizationServiceMock.Setup(a => a.IsAuthorized(AuthorizationContext.DeployFrom, null)).Returns(false).Verifiable();
            envModel.AuthorizationServiceMock.Setup(a => a.IsAuthorized(AuthorizationContext.DeployTo, null)).Returns(false).Verifiable();

            Assert.IsFalse(envModel.IsAuthorizedDeployFrom);
            Assert.IsFalse(envModel.IsAuthorizedDeployTo);

            //------------Execute Test---------------------------
            envModel.AuthorizationServiceMock.Setup(a => a.IsAuthorized(AuthorizationContext.DeployFrom, null)).Returns(true).Verifiable();
            envModel.AuthorizationServiceMock.Setup(a => a.IsAuthorized(AuthorizationContext.DeployTo, null)).Returns(true).Verifiable();
            envModel.AuthorizationServiceMock.Raise(a => a.PermissionsChanged += null, EventArgs.Empty);

            //------------Assert Results-------------------------
            envModel.AuthorizationServiceMock.Verify(a => a.IsAuthorized(AuthorizationContext.DeployFrom, null));
            envModel.AuthorizationServiceMock.Verify(a => a.IsAuthorized(AuthorizationContext.DeployTo, null));
            Assert.IsTrue(envModel.IsAuthorizedDeployFrom);
            Assert.IsTrue(envModel.IsAuthorizedDeployTo);
        }
 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_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_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 EnvironmentModel_Connection_PermissionsChanged_IsAuthorizedChanged()
        {
            //------------Setup for test--------------------------
            var connection = CreateConnection();
            connection.Setup(c => c.IsAuthorized).Returns(false);

            var envModel = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid(), connection.Object, new Mock<IResourceRepository>().Object, false);
            Assert.IsFalse(envModel.IsAuthorized);

            //------------Execute Test---------------------------
            connection.Setup(c => c.IsAuthorized).Returns(true);
            connection.Raise(c => c.PermissionsChanged += null, EventArgs.Empty);

            //------------Assert Results-------------------------
            Assert.IsTrue(envModel.IsAuthorized);
        }