コード例 #1
0
        public void Synchronize_ReferenceFolderRemoved(bool libraries, bool projects)
        {
            var declarations = CodeExplorerTestSetup.GetProjectDeclarationsWithReferences(libraries, projects, out var state);

            using (state)
            {
                var updates            = declarations.ToList();
                var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

                var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, state, null, state.ProjectsProvider);

                var references = state.ProjectsProvider.Project(projectDeclaration.ProjectId).References;
                foreach (var reference in references.ToList())
                {
                    references.Remove(reference);
                }

                project.Synchronize(ref updates);

                var libraryFolder = project.Children.OfType <CodeExplorerReferenceFolderViewModel>()
                                    .SingleOrDefault(folder => folder.ReferenceKind == ReferenceKind.TypeLibrary);
                var projectFolder = project.Children.OfType <CodeExplorerReferenceFolderViewModel>()
                                    .SingleOrDefault(folder => folder.ReferenceKind == ReferenceKind.Project);

                Assert.IsNull(libraryFolder);
                Assert.IsNull(projectFolder);
            }
        }
コード例 #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 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));
        }
コード例 #4
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());
        }
コード例 #5
0
        public void Constructor_SetsDeclaration()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            Assert.AreSame(projectDeclaration, project.Declaration);
        }
コード例 #6
0
        public void Constructor_NameWithSignatureIsSet()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            Assert.IsFalse(string.IsNullOrEmpty(project.NameWithSignature));
        }
コード例 #7
0
        public void Constructor_ToolTipIsSet()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            Assert.IsFalse(string.IsNullOrEmpty(project.ToolTip));
        }
コード例 #8
0
        public void Constructor_SetsIsExpandedTrue()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            Assert.IsTrue(project.IsExpanded);
        }
コード例 #9
0
        public void Constructor_SetsName()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            Assert.AreEqual(CodeExplorerTestSetup.TestProjectOneName, project.Name);
        }
コード例 #10
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());
        }
コード例 #11
0
        public void Constructor_ClearsDeclarationList()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

            // ReSharper disable once UnusedVariable
            var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);

            Assert.AreEqual(0, declarations.Count);
        }
コード例 #12
0
        public void Constructor_CreatesDefaultProjectFolder()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

            var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
            var folder  = project.Children.OfType <CodeExplorerCustomFolderViewModel>().Single();

            Assert.AreEqual(projectDeclaration.IdentifierName, folder.Name);
        }
コード例 #13
0
        public void SortComparerIsNodeType(CodeExplorerSortOrder order)
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            Assert.AreEqual(CodeExplorerItemComparer.NodeType.GetType(), project.SortComparer.GetType());
        }
コード例 #14
0
        public void Synchronize_ClearsPassedDeclarationList_NoChanges()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            project.Synchronize(ref updates);

            Assert.AreEqual(0, updates.Count);
        }
コード例 #15
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());
        }
コード例 #16
0
        public void IsNotFiltered(string filter)
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            Assert.IsFalse(project.Filtered);
        }
コード例 #17
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);
        }
コード例 #18
0
        public void Synchronize_UsesDefaultProjectFolder_NoChanges()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
            var updates            = declarations.ToList();

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

            project.Synchronize(ref updates);

            var folder = project.Children.OfType <CodeExplorerCustomFolderViewModel>().Single();

            Assert.AreEqual(projectDeclaration.IdentifierName, folder.Name);
        }
コード例 #19
0
        public void Constructor_CreatesReferenceFolders(bool libraries, bool projects)
        {
            var declarations       = CodeExplorerTestSetup.GetProjectDeclarationsWithReferences(libraries, projects);
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            var libraryFolder = project.Children.OfType <CodeExplorerReferenceFolderViewModel>()
                                .SingleOrDefault(folder => folder.ReferenceKind == ReferenceKind.TypeLibrary);
            var projectFolder = project.Children.OfType <CodeExplorerReferenceFolderViewModel>()
                                .SingleOrDefault(folder => folder.ReferenceKind == ReferenceKind.Project);

            Assert.AreEqual(libraries, libraryFolder != null);
            Assert.AreEqual(projects, projectFolder != null);
        }
コード例 #20
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)));
        }
コード例 #21
0
        public void Synchronize_ReferenceFolders_NoChanges(bool libraries, bool projects)
        {
            var declarations       = CodeExplorerTestSetup.GetProjectDeclarationsWithReferences(libraries, projects);
            var updates            = declarations.ToList();
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

            var expected = GetReferencesFromProjectDeclaration(projectDeclaration).Select(reference => reference.Name).ToList();

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

            project.Synchronize(ref updates);

            var actual = GetReferencesFromProjectViewModel(project).OrderBy(reference => reference.Priority).Select(reference => reference.Name);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
コード例 #22
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());
        }
コード例 #23
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);
        }
コード例 #24
0
        public void Synchronize_AddedComponent_SingleProjectFolderExists(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 _);

            project.Synchronize(ref updates);

            var actual = project.Children.OfType <CodeExplorerCustomFolderViewModel>()
                         .Count(folder => folder.Name.Equals(CodeExplorerTestSetup.TestProjectOneName));

            Assert.AreEqual(1, actual);
        }
コード例 #25
0
        public void Synchronize_SetsDeclarationNull_DeclarationsForDifferentProject()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            if (project.Declaration is null)
            {
                Assert.Inconclusive("Project declaration is null. Fix test setup and see why no other tests failed.");
            }

            var updates = CodeExplorerTestSetup.TestProjectTwoDeclarations;

            project.Synchronize(ref updates);

            Assert.IsNull(project.Declaration);
        }
コード例 #26
0
        public void Synchronize_DoesNotAlterDeclarationList_DifferentProject()
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            project.Synchronize(ref updates);

            var expected = CodeExplorerTestSetup.TestProjectTwoDeclarations
                           .Select(declaration => declaration.QualifiedName.ToString())
                           .OrderBy(_ => _);

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

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
コード例 #27
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));
        }
コード例 #28
0
        public void Synchronize_RemovesComponent(string removed)
        {
            var declarations       = CodeExplorerTestSetup.TestProjectOneDeclarations;
            var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);

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

            var updates  = CodeExplorerTestSetup.TestProjectOneDeclarations.TestProjectWithComponentRemoved(removed);
            var expected = updates.Select(declaration => declaration.QualifiedName.ToString())
                           .OrderBy(_ => _)
                           .ToList();

            project.Synchronize(ref updates);

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

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