Ejemplo n.º 1
0
        public void DependencyGraphGenerator_BuildGraph_WhenIdEqualsName_ExpectCenterCoordinates()
        {
            //------------Setup for test--------------------------
            const string graphData = "<graph title=\"Local Dependants Graph: 45e1fcc5-9f68-4d4a-9e01-20d587dee532\">" +
                                     "<node id=\"Test Model\" x=\"\" y=\"\" broken=\"false\">" +
                                     "<dependency id=\"a839fe54-3f33-482a-b3e4-de74189e9f00\" />" +
                                     "</node>" +
                                     "<node id=\"a839fe54-3f33-482a-b3e4-de74189e9f00\" x=\"\" y=\"\" broken=\"false\">" +
                                     "<dependency id=\"e0e2cb45-aa63-417f-bc41-2fe4e906ba56\" />" +
                                     "</node>" +
                                     "<node id=\"a839fe54-3f33-482a-b3e4-de74189e9g00\" x=\"\" y=\"\" broken=\"false\">" +
                                     "<dependency id=\"e0e2cb45-aa63-417f-bc41-1fe4e906ba56\" />" +
                                     "</node>" +
                                     "</graph>";

            var data = new StringBuilder(graphData);
            var dependencyGraphGenerator = new DependencyGraphGenerator();


            //------------Execute Test---------------------------
            // for some silly reason this is what comes through when you debug?
            var result = dependencyGraphGenerator.BuildGraph(data, "Test Model", 4, 4, -1);

            //------------Assert Results-------------------------
            var x = result.Nodes.Any(node => node.LocationX == -98);
            var y = result.Nodes.Any(node => node.LocationY == -98);

            Assert.IsTrue(x);
            Assert.IsTrue(y);
        }
Ejemplo n.º 2
0
        public void DependencyGraphGenerator_BuildGraph_WhenGraphDataValidAndNestingLevel_ExpectValidGraph()
        {
            //------------Setup for test--------------------------
            const string graphData = "<graph title=\"Local Dependants Graph: 45e1fcc5-9f68-4d4a-9e01-20d587dee532\">" +
                                     "<node id=\"45e1fcc5-9f68-4d4a-9e01-20d587dee532\" x=\"\" y=\"\" broken=\"false\">" +
                                     "<dependency id=\"a839fe54-3f33-482a-b3e4-de74189e9f00\" />" +
                                     "</node>" +
                                     "<node id=\"a839fe54-3f33-482a-b3e4-de74189e9f00\" x=\"\" y=\"\" broken=\"false\">" +
                                     "<dependency id=\"e0e2cb45-aa63-417f-bc41-2fe4e906ba56\" />" +
                                     "</node>" +
                                     "<node id=\"a839fe54-3f33-482a-b3e4-de74189e9g00\" x=\"\" y=\"\" broken=\"false\">" +
                                     "<dependency id=\"e0e2cb45-aa63-417f-bc41-1fe4e906ba56\" />" +
                                     "</node>" +
                                     "</graph>";

            var data = new StringBuilder(graphData);
            var dependencyGraphGenerator = new DependencyGraphGenerator();

            const string expected = "<graph title=\"Local Dependants Graph: 45e1fcc5-9f68-4d4a-9e01-20d587dee532\"><node id=\"45e1fcc5-9f68-4d4a-9e01-20d587dee532\" x=\"-100\" y=\"-400\" broken=\"False\"><dependency id=\"a839fe54-3f33-482a-b3e4-de74189e9f00\" /></node><node id=\"a839fe54-3f33-482a-b3e4-de74189e9f00\" x=\"-352\" y=\"-262\" broken=\"False\"></node></graph>";

            //------------Execute Test---------------------------
            // for some silly reason this is what comes through when you debug?
            var result = dependencyGraphGenerator.BuildGraph(data, "Test Model", 0, 0, 1);

            //------------Assert Results-------------------------
            Assert.AreEqual(expected, result.ToString());
        }
        public void DependencyGraphGenerator_BuildGraph_WhenGraphDataNull_ExpectErrorGraph()
        {
            //------------Setup for test--------------------------
            const string expected = "Dependency information could not be retrieved";
            var          dependencyGraphGenerator = new DependencyGraphGenerator();

            //------------Execute Test---------------------------
            var result = dependencyGraphGenerator.BuildGraph(null, "Test Model", 0, 0);

            //------------Assert Results-------------------------
            StringAssert.Contains(result.Title, expected);
        }
        // NOTE: This method is invoked from DependencyVisualiser.xaml
        public void BuildGraphs()
        {
            Graphs.Clear();

            var repo      = ResourceModel.Environment.ResourceRepository;
            var graphData = repo.GetDependenciesXml(ResourceModel, GetDependsOnMe);

            if (graphData == null)
            {
                throw new Exception(string.Format(GlobalConstants.NetworkCommunicationErrorTextFormat, "GetDependenciesXml"));
            }

            var graphGenerator = new DependencyGraphGenerator();

            var graph = graphGenerator.BuildGraph(graphData.Message, ResourceModel.ResourceName, AvailableWidth, AvailableHeight);

            Graphs.Add(graph);
        }
        public void DependencyGraphGenerator_BuildGraph_WhenGraphContainsMalformedGraphTag_ExpectErrorGraph()
        {
            //------------Setup for test--------------------------
            const string graphData = @"<graphz title=""Local Dependants Graph: MyLocalWF"">
  <node id=""9139Local"" x="""" y="""" broken=""false"">
    <dependency id=""MyLocalWF"" />
  </node>
  <node id=""MyLocalWF"" x="""" y="""" broken=""false""></node>
</graphz>";
            var          data      = new StringBuilder(graphData);
            var          expected  = "Dependency information is malformed";
            var          dependencyGraphGenerator = new DependencyGraphGenerator();

            //------------Execute Test---------------------------
            var result = dependencyGraphGenerator.BuildGraph(data, "Test Model", 0, 0);

            //------------Assert Results-------------------------
            StringAssert.Contains(result.Title, expected);
        }
Ejemplo n.º 6
0
 static void ShowDependencies(DependencyGraphGenerator graphGenerator, DeletedFileMetadata deleteFileMetaData, bool showDependenciesApplyToAll, IExplorerItemViewModel itemViewModel, Dev2.Common.Interfaces.Infrastructure.Communication.IExecuteMessage dependants, IDeletedFileMetadata deletedFileMetadata)
 {
     if (dependants != null)
     {
         if (showDependenciesApplyToAll)
         {
             var graph = graphGenerator.BuildGraph(dependants.Message, "", 1000, 1000, 1);
             if (graph.Nodes.Count > 1)
             {
                 itemViewModel.ShowDependencies();
             }
         }
         else
         {
             if (deletedFileMetadata.DeleteAnyway && deletedFileMetadata.ApplyToAll)
             {
                 deleteFileMetaData.IsDeleted  = true;
                 deleteFileMetaData.ResourceId = itemViewModel.ResourceId;
             }
         }
     }
 }
        public void DependencyGraphGenerator_BuildGraph_WhenGraphDataValid_ExpectValidGraph()
        {
            //------------Setup for test--------------------------
            const string graphData = @"<graph title=""Local Dependants Graph: MyLocalWF"">
  <node id=""9139Local"" x="""" y="""" broken=""false"">
    <dependency id=""MyLocalWF"" />
  </node>
  <node id=""MyLocalWF"" x="""" y="""" broken=""false""></node>
</graph>";

            var data = new StringBuilder(graphData);
            var dependencyGraphGenerator = new DependencyGraphGenerator();

            const string expected = @"<graph title=""Local Dependants Graph: MyLocalWF""><node id=""9139Local"" x=""-100"" y=""-400"" broken=""False""><dependency id=""MyLocalWF"" /></node><node id=""MyLocalWF"" x=""-352"" y=""-262"" broken=""False""></node></graph>";

            //------------Execute Test---------------------------
            // for some silly reason this is what comes through when you debug?
            var result = dependencyGraphGenerator.BuildGraph(data, "Test Model", 0, 0);

            //------------Assert Results-------------------------
            Assert.AreEqual(expected, result.ToString());
        }
        public IDeletedFileMetadata Delete(IExplorerItemViewModel explorerItemViewModel)
        {
            try
            {
                if (explorerItemViewModel != null)
                {
                    var graphGenerator = new DependencyGraphGenerator();
                    if (explorerItemViewModel.ResourceType != "Version" && explorerItemViewModel.ResourceType != "Folder")
                    {
                        var dep            = _repository.QueryManagerProxy.FetchDependants(explorerItemViewModel.ResourceId);
                        var deleteFileMeta = _repository.HasDependencies(explorerItemViewModel, graphGenerator, dep);
                        if (deleteFileMeta.IsDeleted || deleteFileMeta.DeleteAnyway)
                        {
                            deleteFileMeta.IsDeleted = true;
                            _repository.UpdateManagerProxy.DeleteResource(explorerItemViewModel.ResourceId);
                        }
                        return(deleteFileMeta);
                    }
                    if (explorerItemViewModel.ResourceType == "Version")
                    {
                        _repository.VersionManager.DeleteVersion(explorerItemViewModel.ResourceId, explorerItemViewModel.VersionNumber, explorerItemViewModel.ResourcePath);
                    }
                    else if (explorerItemViewModel.ResourceType == "Folder")
                    {
                        var explorerItemViewModels = explorerItemViewModel.AsList();
                        // ReSharper disable once LoopCanBeConvertedToQuery
                        var deleteFileMetaData = new DeletedFileMetadata
                        {
                            IsDeleted        = true,
                            ShowDependencies = false
                        };
                        bool showDependenciesApplyToAll = false;
                        foreach (IExplorerItemViewModel itemViewModel in explorerItemViewModels)
                        {
                            if (itemViewModel.ResourceType != "Folder")
                            {
                                var dependants = _repository.QueryManagerProxy.FetchDependants(itemViewModel.ResourceId);
                                if (dependants != null)
                                {
                                    if (showDependenciesApplyToAll)
                                    {
                                        var graph = graphGenerator.BuildGraph(dependants.Message, "", 1000, 1000, 1);
                                        if (graph.Nodes.Count > 1)
                                        {
                                            itemViewModel.ShowDependencies();
                                        }
                                    }
                                    else
                                    {
                                        var deletedFileMetadata = _repository.HasDependencies(itemViewModel, graphGenerator, dependants);

                                        if (deletedFileMetadata.DeleteAnyway && deletedFileMetadata.ApplyToAll)
                                        {
                                            deleteFileMetaData.IsDeleted  = true;
                                            deleteFileMetaData.ResourceId = itemViewModel.ResourceId;
                                            break;
                                        }
                                        if (deletedFileMetadata.DeleteAnyway && !deletedFileMetadata.ApplyToAll)
                                        {
                                            explorerItemViewModel.RemoveChild(itemViewModel);
                                            _repository.UpdateManagerProxy.DeleteResource(itemViewModel.ResourceId);
                                        }

                                        if (!deletedFileMetadata.IsDeleted)
                                        {
                                            deleteFileMetaData.IsDeleted        = false;
                                            deleteFileMetaData.ShowDependencies = true;
                                            deleteFileMetaData.ResourceId       = itemViewModel.ResourceId;

                                            if (deletedFileMetadata.ApplyToAll && deletedFileMetadata.ShowDependencies)
                                            {
                                                showDependenciesApplyToAll = deletedFileMetadata.ShowDependencies;
                                            }
                                            else if (deletedFileMetadata.ApplyToAll)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (deleteFileMetaData.IsDeleted)
                        {
                            if (!string.IsNullOrWhiteSpace(explorerItemViewModel.ResourcePath))
                            {
                                _repository.UpdateManagerProxy.DeleteFolder(explorerItemViewModel.ResourcePath);
                            }
                        }
                        return(deleteFileMetaData);
                    }
                }
                return(new DeletedFileMetadata
                {
                    IsDeleted = true
                });
            }
            catch (Exception)
            {
                return(new DeletedFileMetadata
                {
                    IsDeleted = false
                });
            }
        }