コード例 #1
0
        public void Synchronize_PlacesAllTrackedDeclarations_AddedComponent(string component, string added)
        {
            var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations
                               .TestProjectWithComponentDeclarations(new[] { component }, out var projectDeclaration);

            var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);

            var updates = CodeExplorerTestSetup.TestProjectOneDeclarations
                          .TestProjectWithComponentDeclarations(new[] { component, added }, out _).ToList();

            var results  = updates.ToList();
            var expected =
                CodeExplorerProjectViewModel.ExtractTrackedDeclarationsForProject(projectDeclaration, ref results)
                .Select(declaration => declaration.QualifiedName.ToString())
                .OrderBy(_ => _)
                .ToList();

            project.Synchronize(ref updates);

            var children = project.GetAllChildDeclarations();
            var actual   = children
                           .Select(declaration => declaration.QualifiedName.ToString())
                           .OrderBy(_ => _);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
コード例 #2
0
        public void Synchronize_RemovedComponent_HasCorrectSubFolderStructure(params object[] parameters)
        {
            var structure = ToFolderStructure(parameters.Cast <string>());
            var root      = structure.First().Folder;
            var path      = root.Split(FolderExtensions.FolderDelimiter);

            var declarations = CodeExplorerTestSetup.TestProjectWithFolderStructure(structure, out var projectDeclaration, out var state);

            using (state)
            {
                var contents =
                    CodeExplorerProjectViewModel.ExtractTrackedDeclarationsForProject(projectDeclaration,
                                                                                      ref declarations);
                var component     = contents.TestComponentDeclarations(structure.Last().Name);
                var synchronizing = contents.Except(component).ToList();

                var project = new CodeExplorerProjectViewModel(projectDeclaration, ref contents, state, null, state.ProjectsProvider);
                var folder  = project.Children.OfType <CodeExplorerCustomFolderViewModel>()
                              .Single(item => item.Name.Equals(path.First()));

                project.Synchronize(ref synchronizing);

                AssertFolderStructureIsCorrect(folder, structure.Take(structure.Count - 1).ToList());
            }
        }
コード例 #3
0
        public static List <Declaration> TestProjectWithComponentRemoved(this List <Declaration> declarations, string moduleName)
        {
            var projectDeclaration = declarations.Single(declaration => declaration.DeclarationType == DeclarationType.Project);
            var removing           = declarations.ToList().TestComponentDeclarations(moduleName);
            var candidates         = CodeExplorerProjectViewModel.ExtractTrackedDeclarationsForProject(projectDeclaration, ref declarations).ToList();

            return(candidates.Except(removing).ToList());
        }
コード例 #4
0
        public static List <Declaration> TestComponentDeclarations(this List <Declaration> declarations, string moduleName)
        {
            var projectDeclaration = declarations.Single(declaration => declaration.DeclarationType == DeclarationType.Project);
            var candidates         = CodeExplorerProjectViewModel.ExtractTrackedDeclarationsForProject(projectDeclaration, ref declarations);

            return(candidates.Where(declaration =>
                                    declaration.DeclarationType != DeclarationType.Project &&
                                    declaration.QualifiedModuleName.ComponentName.Equals(moduleName)).ToList());
        }
コード例 #5
0
        public static List <Declaration> TestProjectWithMemberRemoved(this List <Declaration> declarations,
                                                                      string memberName, out Declaration componentDeclaration, DeclarationType type = DeclarationType.Member)
        {
            var projectDeclaration = declarations.Single(declaration => declaration.DeclarationType == DeclarationType.Project);
            var removing           = declarations.ToList().TestMemberDeclarations(memberName, out var member, type);

            componentDeclaration = member.ParentDeclaration;

            var candidates = CodeExplorerProjectViewModel.ExtractTrackedDeclarationsForProject(projectDeclaration, ref declarations).ToList();

            return(candidates.Except(removing).ToList());
        }
コード例 #6
0
        public void Constructor_CreatesCorrectSubFolderStructure(params object[] parameters)
        {
            var structure = ToFolderStructure(parameters.Cast <string>());
            var root      = structure.First().Folder;
            var path      = root.Split(FolderExtensions.FolderDelimiter);

            var declarations = CodeExplorerTestSetup.TestProjectWithFolderStructure(structure, out var projectDeclaration);
            var contents     = CodeExplorerProjectViewModel.ExtractTrackedDeclarationsForProject(projectDeclaration, ref declarations);

            var folder = new CodeExplorerCustomFolderViewModel(null, path.First(), path.First(), null, ref contents);

            AssertFolderStructureIsCorrect(folder, structure);
        }
コード例 #7
0
        public void TrackedDeclarations_ExcludesMemberEnclosedTypes(DeclarationType excluded)
        {
            var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;

            // Validate test setup:
            if (declarations.All(declaration => declaration.DeclarationType != excluded))
            {
                Assert.Inconclusive("DeclarationType under test not found in test declarations.");
            }

            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
            var tracked            = CodeExplorerProjectViewModel.ExtractTrackedDeclarationsForProject(projectDeclaration, ref declarations);

            Assert.IsFalse(tracked.Any(declaration => declaration.DeclarationType == excluded && !declaration.ParentDeclaration.DeclarationType.HasFlag(DeclarationType.Module)));
        }
コード例 #8
0
        public static List <Declaration> TestMemberDeclarations(this List <Declaration> declarations,
                                                                string memberName, out Declaration memberDeclaration, DeclarationType type = DeclarationType.Member)
        {
            var member = declarations.Single(declaration =>
                                             declaration.IdentifierName.Equals(memberName) &&
                                             (type == DeclarationType.Member || declaration.DeclarationType == type));

            var projectDeclaration = declarations.Single(declaration => declaration.DeclarationType == DeclarationType.Project);

            memberDeclaration = member;

            var candidates = CodeExplorerProjectViewModel.ExtractTrackedDeclarationsForProject(projectDeclaration, ref declarations);

            return(candidates.Where(declaration =>
                                    ReferenceEquals(declaration, member) ||
                                    ReferenceEquals(declaration.ParentDeclaration, member)).ToList());
        }
コード例 #9
0
        public static List <Declaration> TestProjectWithComponentDeclarations(this List <Declaration> declarations, IEnumerable <string> moduleNames, out Declaration projectDeclaration)
        {
            projectDeclaration = declarations.Single(declaration => declaration.DeclarationType == DeclarationType.Project);
            var candidates = CodeExplorerProjectViewModel.ExtractTrackedDeclarationsForProject(projectDeclaration, ref declarations).ToList();

            var output = new List <Declaration> {
                projectDeclaration
            };

            foreach (var component in moduleNames)
            {
                output.AddRange(candidates.Where(declaration =>
                                                 declaration.DeclarationType != DeclarationType.Project &&
                                                 declaration.QualifiedModuleName.ComponentName.Equals(component)));
            }
            return(output);
        }
コード例 #10
0
        public void Constructor_PlacesAllTrackedDeclarations()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
            var results            = declarations.ToList();

            var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);

            var expected =
                CodeExplorerProjectViewModel.ExtractTrackedDeclarationsForProject(projectDeclaration, ref results)
                .Select(declaration => declaration.QualifiedName.ToString())
                .OrderBy(_ => _);

            var actual = project.GetAllChildDeclarations()
                         .Select(declaration => declaration.QualifiedName.ToString())
                         .OrderBy(_ => _);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }