protected static void SetupResources(DeployStatsCalculator deployStatsCalculator, bool isChecked) { IEnvironmentModel environmentModel; IExplorerItemModel resourceVm; var studioResourceRepository = CreateModels(isChecked, out environmentModel, out resourceVm); var navVm = new DeployNavigationViewModel(new Mock<IEventAggregator>().Object, AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, new Mock<IEnvironmentRepository>().Object, studioResourceRepository, true, new Mock<IConnectControlSingleton>().Object) { Environment = environmentModel }; resourceVm.IsChecked = isChecked; deployStatsCalculator.DeploySummaryPredicateExisting(resourceVm, navVm); }
static DeployNavigationViewModel CreateDeployNavigationViewModel(IEnvironmentModel environmentModel, IEventAggregator eventAggregator, IAsyncWorker asyncWorker, IEnvironmentRepository environmentRepository, StudioResourceRepository studioResourceRepository) { DeployNavigationViewModel navigationViewModel = new DeployNavigationViewModel(eventAggregator, asyncWorker, environmentRepository, studioResourceRepository, true, new Mock<IConnectControlSingleton>().Object) { Environment = environmentModel }; return navigationViewModel; }
void Init(bool addWizardChildToResource, bool shouldLoadResources) { SetupMockEnvironment(shouldLoadResources); Mock<IResourceRepository> mockResourceRepository; SetUpResources(addWizardChildToResource, out mockResourceRepository); _vm = CreateViewModel(mockResourceRepository); _mockEnvironmentModel.Setup(model => model.IsLocalHost).Returns(true); _vm.Environment = _mockEnvironmentModel.Object; }
DeployNavigationViewModel CreateViewModel(IEnvironmentRepository environmentRepository, Mock<IResourceRepository> mockResourceRepository) { StudioResourceRepository studioResourceRepository = BuildExplorerItems(mockResourceRepository.Object); var navigationViewModel = new DeployNavigationViewModel(new Mock<IEventAggregator>().Object, AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, environmentRepository, studioResourceRepository, _target, new Mock<IConnectControlSingleton>().Object); return navigationViewModel; }
public void DeployViewModel_SelectItemInDeploy_TwoServers_ItemAndServerSelected_ExpectChecked() { //New Mocks var mockedServerRepo = new Mock<IEnvironmentRepository>(); var server = new Mock<IEnvironmentModel>(); var secondServer = new Mock<IEnvironmentModel>(); var provider = new Mock<IEnvironmentModelProvider>(); var resourceNode = new Mock<IContextualResourceModel>(); //Setup Servers server.Setup(svr => svr.IsConnected).Returns(true); server.Setup(svr => svr.Connection).Returns(DebugOutputViewModelTest.CreateMockConnection(new Random()).Object); server.Setup(a => a.AuthorizationService).Returns(_authService.Object); secondServer.Setup(svr => svr.IsConnected).Returns(true); secondServer.Setup(a => a.AuthorizationService).Returns(_authService.Object); secondServer.Setup(svr => svr.Connection).Returns(DebugOutputViewModelTest.CreateMockConnection(new Random()).Object); mockedServerRepo.Setup(svr => svr.Fetch(It.IsAny<IEnvironmentModel>())).Returns(server.Object); mockedServerRepo.Setup(r => r.FindSingle(It.IsAny<Expression<Func<IEnvironmentModel, bool>>>())).Returns(server.Object); provider.Setup(prov => prov.Load()).Returns(new List<IEnvironmentModel> { server.Object, secondServer.Object }); //Setup Navigation Tree var eventAggregator = new Mock<IEventAggregator>().Object; var treeParent = new ExplorerItemModel { DisplayName = "Test Category", ResourceType = ResourceType.Folder, IsDeploySourceExpanded = false }; const string expectedResourceName = "Test Resource"; var resourceID = Guid.NewGuid(); resourceNode.Setup(res => res.ResourceName).Returns(expectedResourceName); resourceNode.Setup(model => model.ID).Returns(resourceID); resourceNode.Setup(res => res.Environment.Connection.ServerEvents).Returns(new Mock<IEventPublisher>().Object); var resourceTreeNode = new ExplorerItemModel { Parent = treeParent, DisplayName = resourceNode.Object.ResourceName, ResourceId = resourceID, EnvironmentId = server.Object.ID, IsChecked = false }; //Setup Server Resources var mockStudioResourceRepository = new Mock<IStudioResourceRepository>(); mockStudioResourceRepository.Setup(repository => repository.FindItem(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(resourceTreeNode); mockStudioResourceRepository.Setup(repository => repository.Filter(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(new ObservableCollection<IExplorerItemModel>()); var sourceDeployNavigationViewModel = new DeployNavigationViewModel(eventAggregator, new TestAsyncWorker(), mockedServerRepo.Object, mockStudioResourceRepository.Object, true, new Mock<IConnectControlSingleton>().Object) { ExplorerItemModels = new ObservableCollection<IExplorerItemModel>() }; server.Setup(svr => svr.LoadResources()).Callback(() => sourceDeployNavigationViewModel.ExplorerItemModels.Add(treeParent)); sourceDeployNavigationViewModel.Environment = server.Object; var deployViewModel = new DeployViewModel(new TestAsyncWorker(), provider.Object, mockedServerRepo.Object, new Mock<IEventAggregator>().Object, mockStudioResourceRepository.Object, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object) { Source = sourceDeployNavigationViewModel }; var initialResource = new Mock<IContextualResourceModel>(); initialResource.Setup(res => res.Environment).Returns(server.Object); initialResource.Setup(res => res.ID).Returns(resourceID); //------------Execute Test--------------------------- deployViewModel.Handle(new SelectItemInDeployMessage(initialResource.Object.ID, initialResource.Object.Environment.ID)); // Assert item visible and selected Assert.IsTrue(resourceTreeNode.IsChecked.GetValueOrDefault(false), "Deployed item not selected in deploy"); Assert.IsTrue(treeParent.IsDeploySourceExpanded, "Item not visible in deploy view"); mockStudioResourceRepository.Verify(r => r.FindItem(It.IsAny<Func<IExplorerItemModel, bool>>())); }
public void DeployViewModel_Deploy_AssertSelectedEnvIsDestination() { //New Mocks var mockedServerRepo = new Mock<IEnvironmentRepository>(); var server = new Mock<IEnvironmentModel>(); server.Setup(x => x.AuthorizationService).Returns(_authService.Object); _authService.Setup(a => a.IsAuthorized(AuthorizationContext.DeployFrom, It.IsAny<string>())).Returns(true); _authService.Setup(a => a.IsAuthorized(AuthorizationContext.DeployTo, It.IsAny<string>())).Returns(true); var secondServer = new Mock<IEnvironmentModel>(); secondServer.Setup(x => x.AuthorizationService).Returns(_authService.Object); var provider = new Mock<IEnvironmentModelProvider>(); var resourceNode = new Mock<IContextualResourceModel>(); var resRepo = new Mock<IResourceRepository>(); var resRepo2 = new Mock<IResourceRepository>(); var id = Guid.NewGuid(); const string expectedResourceName = "Test Resource"; resourceNode.Setup(res => res.ResourceName).Returns(expectedResourceName); resourceNode.Setup(res => res.Environment.Connection.ServerEvents).Returns(new Mock<IEventPublisher>().Object); resourceNode.Setup(res => res.ID).Returns(id); //Setup Servers resRepo.Setup(c => c.FindSingle(It.IsAny<Expression<Func<IResourceModel, bool>>>(), false, false)).Verifiable(); resRepo.Setup(c => c.FindSingle(It.IsAny<Expression<Func<IResourceModel, bool>>>(), false, false)).Returns(resourceNode.Object); resRepo.Setup(c => c.DeployResources(It.IsAny<IEnvironmentModel>(), It.IsAny<IEnvironmentModel>(), It.IsAny<IDeployDto>(), It.IsAny<IEventAggregator>())).Verifiable(); resRepo.Setup(c => c.All()).Returns(new List<IResourceModel>()); resRepo2.Setup(c => c.All()).Returns(new List<IResourceModel>()); server.Setup(svr => svr.IsConnected).Returns(true); server.Setup(svr => svr.Connection).Returns(DebugOutputViewModelTest.CreateMockConnection(new Random()).Object); server.Setup(svr => svr.ResourceRepository).Returns(resRepo.Object); secondServer.Setup(svr => svr.IsConnected).Returns(true); secondServer.Setup(svr => svr.Connection).Returns(DebugOutputViewModelTest.CreateMockConnection(new Random()).Object); secondServer.Setup(svr => svr.ResourceRepository).Returns(resRepo2.Object); mockedServerRepo.Setup(svr => svr.Fetch(It.IsAny<IEnvironmentModel>())).Returns(server.Object); provider.Setup(prov => prov.Load()).Returns(new List<IEnvironmentModel> { server.Object, secondServer.Object }); var initialResource = new Mock<IContextualResourceModel>(); initialResource.Setup(res => res.Environment).Returns(server.Object); initialResource.Setup(res => res.ResourceName).Returns(expectedResourceName); //Setup Navigation Tree //Setup Server Resources var mockStudioResourceRepository = GetMockStudioResourceRepository(); var resourceTreeNode = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, mockStudioResourceRepository.Object); mockStudioResourceRepository.Setup(repository => repository.FindItem(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(resourceTreeNode); var sourceDeployNavigationViewModel = new DeployNavigationViewModel(new Mock<IEventAggregator>().Object, new TestAsyncWorker(), mockedServerRepo.Object, mockStudioResourceRepository.Object, true, new Mock<IConnectControlSingleton>().Object) { Environment = server.Object, ExplorerItemModels = new ObservableCollection<IExplorerItemModel>() }; var deployViewModel = new DeployViewModel(new TestAsyncWorker(), provider.Object, mockedServerRepo.Object, new Mock<IEventAggregator>().Object, mockStudioResourceRepository.Object, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object, null, null, null, new Mock<IConnectControlSingleton>().Object) { Source = sourceDeployNavigationViewModel, Target = sourceDeployNavigationViewModel, SelectedSourceServer = server.Object }; int active = 0; int getActive = 0; resourceTreeNode.IsChecked = true; PrivateObject pvt = new PrivateObject(deployViewModel); pvt.SetField("_setActive", new Action<IEnvironmentModel>(a => active++)); pvt.SetField("_getActive", new Func<IEnvironmentModel>(() => { getActive++; return new Mock<IEnvironmentModel>().Object; })); //------------Execute Test--------------------------- deployViewModel.DeployCommand.Execute(null); Assert.AreEqual(active, 2); Assert.AreEqual(getActive, 1); }
public PartialNaviationViewModel(DeployNavigationViewModel model) : base(model.EventAggregator, model.AsyncWorker, model.EnvironmentRepository, model.StudioResourceRepository, true, new Mock<IConnectControlSingleton>().Object) { }
/// <summary> /// The predicate used to detemine which resources are going to be overridden /// </summary> public bool DeploySummaryPredicateExisting(IExplorerItemModel node, DeployNavigationViewModel targetNavViewModel) { var vm = node; if(vm == null || !vm.IsChecked.GetValueOrDefault(false)) return false; if(targetNavViewModel != null && targetNavViewModel.Environment != null) { IEnvironmentModel targetEnvironment = targetNavViewModel.Environment; if(targetEnvironment == null || targetEnvironment.ResourceRepository == null) return false; var conflictingItems = targetEnvironment.ResourceRepository.All() .Where(r => r.ID == vm.ResourceId) .Select(r => new Tuple<IResourceModel, IContextualResourceModel, IExplorerItemModel, DeployNavigationViewModel>(r, r as IContextualResourceModel, node, targetNavViewModel)) .ToList(); conflictingItems.ForEach(AddConflictingResources); return targetEnvironment.ResourceRepository.All() .Any(r => r.ID == vm.ResourceId); } return false; }
public IEnumerable<IExplorerItemModel> CheckForNamingConflicts(List<IExplorerItemModel> items, DeployNavigationViewModel targetNavViewModel) { var vm = items; if (vm == null || !vm.All(a => a.IsChecked.GetValueOrDefault(false))) return new List<IExplorerItemModel>(); if (targetNavViewModel != null && targetNavViewModel.Environment != null) { IEnvironmentModel targetEnvironment = targetNavViewModel.Environment; if (targetEnvironment == null || targetEnvironment.ResourceRepository == null) return new List<IExplorerItemModel>(); var all = targetEnvironment.ResourceRepository.All(); if(all != null) { var conflictingItems = all.Join(vm, a => a.Category, explorerItemModel => explorerItemModel.ResourcePath, (a, explorerItemModel) => new { a, explorerItemModel }).Where(@t => @t.explorerItemModel.ResourceId != @t.a.ID).Select(@t => @t.explorerItemModel); return conflictingItems; } } return new List<IExplorerItemModel>(); }