private void AddEnvironment(IEnvironmentModel environmentModel)
 {
     if (environmentModel != null)
     {
         NavigationViewModel.AddEnvironment(environmentModel);
         SaveEnvironment(environmentModel);
     }
 }
        public void NavigationViewModel_RemoveEnvironment_InvokesSelectLocalhost()
        {
            //------------Setup for test--------------------------
            var publisher = new Mock<IEventAggregator>();
            publisher.Setup(p => p.Publish(It.IsAny<SetActiveEnvironmentMessage>())).Verifiable();

            var localhost = new Mock<IEnvironmentModel>();
            localhost.Setup(e => e.ID).Returns(Guid.Empty);
            localhost.Setup(e => e.Name).Returns("localhost");
            localhost.Setup(e => e.IsLocalHost).Returns(true);
            localhost.Setup(e => e.IsConnected).Returns(true);
            localhost.Setup(e => e.CanStudioExecute).Returns(true);
            localhost.SetupGet(x => x.Connection.AppServerUri).Returns(new Uri("http://127.0.0.1/"));

            localhost.Setup(e => e.CanStudioExecute).Returns(true);

            var toBeRemoved = new Mock<IEnvironmentModel>();
            toBeRemoved.Setup(e => e.ID).Returns(Guid.NewGuid());
            toBeRemoved.Setup(e => e.Name).Returns("Other Server");
            toBeRemoved.Setup(e => e.CanStudioExecute).Returns(true);
            toBeRemoved.SetupGet(x => x.Connection.AppServerUri).Returns(new Uri("http://127.0.0.2/"));

            var envList = new List<IEnvironmentModel> { localhost.Object, toBeRemoved.Object };
            var envRepo = new Mock<IEnvironmentRepository>();
            envRepo.Setup(e => e.All()).Returns(envList);
            envRepo.Setup(e => e.Source).Returns(localhost.Object);

            var localhostExplorerItemModel = new ExplorerItemModel { EnvironmentId = Guid.Empty, DisplayName = "localhost" };

            ExplorerItemModel anotherEnvironment = new ExplorerItemModel { DisplayName = "Other Server", EnvironmentId = toBeRemoved.Object.ID };
            var studioResourceRepository = new StudioResourceRepository(localhostExplorerItemModel, _Invoke);
            studioResourceRepository.ExplorerItemModels.Add(anotherEnvironment);
            studioResourceRepository.GetExplorerProxy = guid => new Mock<IClientExplorerResourceRepository>().Object;
            var viewModel = new NavigationViewModel(publisher.Object, new TestAsyncWorker(), null, envRepo.Object, studioResourceRepository, new Mock<IConnectControlSingleton>().Object, () => { });


            foreach(var env in envList)
            {
                viewModel.AddEnvironment(env);
            }

            //------------Execute Test---------------------------
            viewModel.RemoveEnvironment(toBeRemoved.Object);

            //------------Assert Results-------------------------
            publisher.Verify(p => p.Publish(It.IsAny<SetActiveEnvironmentMessage>()));
            Assert.IsTrue(viewModel.ExplorerItemModels[0].IsExplorerSelected);
        }