public void GetItems_GivenEmptyNodes_ShouldZeroExploreNodes() { //---------------Set up test pack------------------- var aggreMock = new Mock <IEventAggregator>(); var resourceModel = new Mock <IContextualResourceModel>(); var depGrap = new Mock <IDependencyGraphGenerator>(); var server = new Mock <IServer>(); var value = new Graph("a"); value.Nodes.Add(new DependencyVisualizationNode(Guid.NewGuid().ToString(), 2, 2, true, false)); value.Nodes.Add(new DependencyVisualizationNode(Guid.NewGuid().ToString(), 2, 2, true, false)); depGrap.Setup(generator => generator.BuildGraph(It.IsAny <StringBuilder>(), It.IsAny <string>(), It.IsAny <double>(), It.IsAny <double>(), It.IsAny <int>())) .Returns(value); resourceModel.SetupGet(model => model.ResourceName).Returns("a"); var envMock = new Mock <IServer>(); var resourceRepo = new Mock <IResourceRepository>(); resourceRepo.Setup(repository => repository.GetDependenciesXmlAsync(It.IsAny <IContextualResourceModel>(), It.IsAny <bool>())) .Returns(ValueFunction); envMock.SetupGet(model => model.ResourceRepository).Returns(resourceRepo.Object); resourceModel.SetupGet(model => model.Environment).Returns(envMock.Object); var dependencyVisualiserViewModel = new DependencyVisualiserViewModel(depGrap.Object, aggreMock.Object, server.Object); var mock = new Mock <IExplorerItemNodeViewModel>(); var explorerItemNodeViewModels = new List <ExplorerItemNodeViewModel>(); var guids = new List <Guid>(); //---------------Assert Precondition---------------- Assert.IsNotNull(dependencyVisualiserViewModel); //---------------Execute Test ---------------------- var itemNodeViewModels = dependencyVisualiserViewModel.GetItems(new List <IDependencyVisualizationNode>(), mock.Object, explorerItemNodeViewModels, guids); //---------------Test Result ----------------------- Assert.AreEqual(0, itemNodeViewModels.Count); }
public void GetItems_GivenNodesAndChilrenWithDependencies_ShouldReturnNodesAndChildDependencies() { //---------------Set up test pack------------------- var aggreMock = new Mock <IEventAggregator>(); var resourceModel = new Mock <IContextualResourceModel>(); var depGrap = new Mock <IDependencyGraphGenerator>(); var resourceId = Guid.NewGuid(); var resourceId1 = Guid.NewGuid(); var server = new Mock <IServer>(); var mVm = new Mock <IShellViewModel>(); var env = new Mock <IEnvironmentViewModel>(); var exploreItm = new Mock <IExplorerItemViewModel>(); exploreItm.SetupGet(model => model.ResourceName).Returns("a"); exploreItm.SetupGet(model => model.ResourceType).Returns("a"); exploreItm.SetupGet(model => model.ResourceId).Returns(resourceId); exploreItm.SetupGet(model => model.UnfilteredChildren).Returns(new BindableCollection <IExplorerItemViewModel>()); var exploreItm1 = new Mock <IExplorerItemViewModel>(); exploreItm1.SetupGet(model => model.ResourceName).Returns("a"); exploreItm1.SetupGet(model => model.ResourceType).Returns("a"); exploreItm1.SetupGet(model => model.ResourceId).Returns(resourceId1); exploreItm1.SetupGet(model => model.UnfilteredChildren).Returns(new BindableCollection <IExplorerItemViewModel>()); env.SetupGet(model => model.UnfilteredChildren).Returns(new BindableCollection <IExplorerItemViewModel>() { exploreItm.Object, exploreItm1.Object }); mVm.SetupGet(model => model.ExplorerViewModel).Returns(new Mock <IExplorerViewModel>().Object); mVm.SetupGet(model => model.ExplorerViewModel.Environments).Returns(new BindableCollection <IEnvironmentViewModel>() { env.Object }); CustomContainer.Register(mVm.Object); var value = new Graph("a"); value.Nodes.Add(new DependencyVisualizationNode(resourceId.ToString(), 2, 2, true, false)); value.Nodes.Add(new DependencyVisualizationNode(resourceId.ToString(), 2, 2, true, false)); depGrap.Setup(generator => generator.BuildGraph(It.IsAny <StringBuilder>(), It.IsAny <string>(), It.IsAny <double>(), It.IsAny <double>(), It.IsAny <int>())) .Returns(value); resourceModel.SetupGet(model => model.ResourceName).Returns("a"); var envMock = new Mock <IServer>(); var resourceRepo = new Mock <IResourceRepository>(); resourceRepo.Setup(repository => repository.GetDependenciesXmlAsync(It.IsAny <IContextualResourceModel>(), It.IsAny <bool>())) .Returns(ValueFunction); envMock.SetupGet(model => model.ResourceRepository).Returns(resourceRepo.Object); resourceModel.SetupGet(model => model.Environment).Returns(envMock.Object); var dependencyVisualiserViewModel = new DependencyVisualiserViewModel(depGrap.Object, aggreMock.Object, server.Object); var mock = new Mock <IExplorerItemNodeViewModel>(); var explorerItemNodeViewModels = new List <ExplorerItemNodeViewModel>(); var guids = new List <Guid>(); var item = new DependencyVisualizationNode(resourceId.ToString(), 2, 2, true, true); item.NodeDependencies.Add(new DependencyVisualizationNode(resourceId1.ToString(), 50, 50, true, true)); var nodes = new List <IDependencyVisualizationNode> { item, }; dependencyVisualiserViewModel.ResourceModel = resourceModel.Object; //---------------Assert Precondition---------------- Assert.IsNotNull(dependencyVisualiserViewModel); //---------------Execute Test ---------------------- var itemNodeViewModels = dependencyVisualiserViewModel.GetItems(nodes, mock.Object, explorerItemNodeViewModels, guids); //---------------Test Result ----------------------- Assert.AreEqual(1, itemNodeViewModels.Count); Assert.AreEqual(2, explorerItemNodeViewModels.Count); Assert.AreEqual(2, guids.Count); }