Ejemplo n.º 1
0
    private static IEnumHierarchies CreateHierarchyEnumerator(TreeItem root, IVsSolution solution)
    {
        Mock <IEnumHierarchies> enumerator;
        Queue <TreeItem>        hierarchies;


        hierarchies = new Queue <TreeItem>(root.Descendants());
        enumerator  = new Mock <IEnumHierarchies>();

        enumerator
        .Setup((x) => x.Next(1, It.IsAny <IVsHierarchy[]>(), out It.Ref <uint> .IsAny))
        .Callback(new EnumHierarchiesNextCallback((uint length, IVsHierarchy[] output, out uint count) => {
            if (hierarchies.Count > 0)
            {
                output[0] = EnsureHierarchyExists(hierarchies.Dequeue(), solution);
                count     = 1;
            }
            else
            {
                count = 0;
            }
        }))
        .Returns(VSConstants.S_OK);

        return(enumerator.Object);
    }
Ejemplo n.º 2
0
    private static List <IVsHierarchy> GetProjectDependencies(
        TreeItem root,
        IReadOnlyDictionary <Guid, List <string> > dependencies,
        IVsHierarchy source,
        IVsSolution solution
        )
    {
        if (ErrorHandler.Succeeded(solution.GetGuidOfProject(source, out Guid identifier)))
        {
            if (dependencies.TryGetValue(identifier, out List <string> names))
            {
                return(root
                       .Descendants()
                       .Where((x) => names.Contains(x.Data.Name))
                       .Where((x) => !x.Data.IsShared)
                       .Select((x) => EnsureHierarchyExists(x, solution))
                       .ToList());
            }
        }

        return(new List <IVsHierarchy>());
    }
Ejemplo n.º 3
0
    public static IVsSolution CreateSolution(TreeItem root)
    {
        Mock <IVsSolution> solution;
        IEnumHierarchies   enumerator;


        solution = new Mock <IVsSolution>();

        solution
        .Setup((x) => x.GetGuidOfProject(It.IsAny <IVsHierarchy>(), out It.Ref <Guid> .IsAny))
        .Returns(new GetGuidOfProject((IVsHierarchy hierarchy, out Guid guid) => {
            foreach (var node in root.DescendantsAndSelf())
            {
                if (node.Hierarchy == hierarchy)
                {
                    guid = node.Data.Identifier;
                    return(VSConstants.S_OK);
                }
            }

            guid = default;
            return(VSConstants.E_FAIL);
        }));

        solution
        .Setup((x) => x.GetProjectOfGuid(ref It.Ref <Guid> .IsAny, out It.Ref <IVsHierarchy?> .IsAny))
        .Returns(new GetProjectOfGuid((ref Guid guid, out IVsHierarchy? hierarchy) => {
            foreach (var node in root.DescendantsAndSelf())
            {
                if (node.Data.Identifier == guid)
                {
                    hierarchy = EnsureHierarchyExists(node, solution.Object);
                    return(VSConstants.S_OK);
                }
            }

            hierarchy = null;
            return(VSConstants.E_FAIL);
        }));

        solution
        .Setup((x) => x.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_ALLINSOLUTION, ref It.Ref <Guid> .IsAny, out enumerator))
        .Returns(new GetProjectEnum((uint flags, ref Guid type, out IEnumHierarchies enumerator) => {
            enumerator = CreateHierarchyEnumerator(root, solution.Object);
            return(VSConstants.S_OK);
        }));

        solution
        .As <IVsSolution4>()
        .Setup((x) => x.ReloadProject(ref It.Ref <Guid> .IsAny))
        .Returns(new ReloadProjectCallback((ref Guid identifier) => {
            foreach (var item in root.Descendants())
            {
                if (item.Data.Identifier == identifier)
                {
                    SetType(item, HierarchyType.Project);
                    return(VSConstants.S_OK);
                }
            }
            return(VSConstants.E_FAIL);
        }));

        solution
        .As <IVsSolution4>()
        .Setup((x) => x.UnloadProject(ref It.Ref <Guid> .IsAny, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser))
        .Returns(new UnloadProjectCallback((ref Guid identifier, uint status) => {
            foreach (var item in root.Descendants())
            {
                if (item.Data.Identifier == identifier)
                {
                    SetType(item, HierarchyType.UnloadedProject);
                    return(VSConstants.S_OK);
                }
            }
            return(VSConstants.E_FAIL);
        }));

        solution.As <IVsHierarchy>();

        return(solution.Object);
    }