From b69d0fd50464db70847588fe51f2210f837ba0ce Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sat, 9 Dec 2006 14:34:29 +0000 Subject: [PATCH] SD2-1241. Fixed two problems in the Unit Tests pad that could occur when opening another solution before the parser has finished parsing the currently open solution. A) The ProjectService.OpenSolution could be null. The unit tests pad now clears the test tree in this case. B) If the project content is null for a project it is not added to the test tree. This can occur if the test tree is in the middle of updating the tree but the parser has cleared the project content as it starts to load another solution. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2145 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Misc/UnitTesting/Src/TestTreeView.cs | 15 +++++---- .../Misc/UnitTesting/Src/UnitTestsPad.cs | 6 +++- .../ClassWithNoRootNamespaceTestFixture.cs | 2 +- .../Test/Tree/GetProjectsTestFixture.cs | 2 +- .../Test/Tree/OneTestClassTestFixture.cs | 2 +- .../Test/Tree/SolutionOpenedTestFixture.cs | 32 ++++++++++++++++++- ...ClassesInDifferentNamespacesTestFixture.cs | 2 +- .../Test/Utils/DerivedUnitTestsPad.cs | 7 ++-- .../Utils/DummyParserServiceTestTreeView.cs | 14 ++++++-- 9 files changed, 65 insertions(+), 17 deletions(-) diff --git a/src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs b/src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs index 1828d4c184..9e195c1ea6 100644 --- a/src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs +++ b/src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs @@ -83,12 +83,15 @@ namespace ICSharpCode.UnitTesting if (TestProject.IsTestProject(project)) { if (GetProjectTreeNode(project) == null) { // Add a new tree node. - TestProject testProject = new TestProject(project, GetProjectContent(project)); - TestProjectTreeNode node = new TestProjectTreeNode(testProject); - node.AddTo(this); - - // Sort the nodes. - SortNodes(Nodes, true); + IProjectContent projectContent = GetProjectContent(project); + if (projectContent != null) { + TestProject testProject = new TestProject(project, projectContent); + TestProjectTreeNode node = new TestProjectTreeNode(testProject); + node.AddTo(this); + + // Sort the nodes. + SortNodes(Nodes, true); + } } } } diff --git a/src/AddIns/Misc/UnitTesting/Src/UnitTestsPad.cs b/src/AddIns/Misc/UnitTesting/Src/UnitTestsPad.cs index 0c7474bc60..386ab2fc00 100644 --- a/src/AddIns/Misc/UnitTesting/Src/UnitTestsPad.cs +++ b/src/AddIns/Misc/UnitTesting/Src/UnitTestsPad.cs @@ -115,7 +115,11 @@ namespace ICSharpCode.UnitTesting /// protected void SolutionLoaded(Solution solution) { - treeView.AddSolution(solution); + if (solution != null) { + treeView.AddSolution(solution); + } else { + treeView.Clear(); + } } /// diff --git a/src/AddIns/Misc/UnitTesting/Test/Tree/ClassWithNoRootNamespaceTestFixture.cs b/src/AddIns/Misc/UnitTesting/Test/Tree/ClassWithNoRootNamespaceTestFixture.cs index fb9d43dd10..e38de59608 100644 --- a/src/AddIns/Misc/UnitTesting/Test/Tree/ClassWithNoRootNamespaceTestFixture.cs +++ b/src/AddIns/Misc/UnitTesting/Test/Tree/ClassWithNoRootNamespaceTestFixture.cs @@ -58,7 +58,7 @@ namespace UnitTesting.Tests.Tree // Init mock project content to be returned. dummyTreeView = new DummyParserServiceTestTreeView(); - dummyTreeView.AddProjectContentForProject(projectContent); + dummyTreeView.ProjectContentForProject = projectContent; // Load the projects into the test tree view. treeView = dummyTreeView as TestTreeView; diff --git a/src/AddIns/Misc/UnitTesting/Test/Tree/GetProjectsTestFixture.cs b/src/AddIns/Misc/UnitTesting/Test/Tree/GetProjectsTestFixture.cs index 8f7cf716bb..930987751d 100644 --- a/src/AddIns/Misc/UnitTesting/Test/Tree/GetProjectsTestFixture.cs +++ b/src/AddIns/Misc/UnitTesting/Test/Tree/GetProjectsTestFixture.cs @@ -49,7 +49,7 @@ namespace UnitTesting.Tests.Tree projectContent.Project = project1; treeView = new DummyParserServiceTestTreeView(); - treeView.AddProjectContentForProject(projectContent); + treeView.ProjectContentForProject = projectContent; treeView.AddSolution(solution); projects = treeView.GetProjects(); } diff --git a/src/AddIns/Misc/UnitTesting/Test/Tree/OneTestClassTestFixture.cs b/src/AddIns/Misc/UnitTesting/Test/Tree/OneTestClassTestFixture.cs index 606ac473e7..1f99e296a3 100644 --- a/src/AddIns/Misc/UnitTesting/Test/Tree/OneTestClassTestFixture.cs +++ b/src/AddIns/Misc/UnitTesting/Test/Tree/OneTestClassTestFixture.cs @@ -81,7 +81,7 @@ namespace UnitTesting.Tests.Tree // Init mock project content to be returned. dummyTreeView = new DummyParserServiceTestTreeView(); - dummyTreeView.AddProjectContentForProject(projectContent); + dummyTreeView.ProjectContentForProject = projectContent; // Load the projects into the test tree view. treeView = dummyTreeView as TestTreeView; diff --git a/src/AddIns/Misc/UnitTesting/Test/Tree/SolutionOpenedTestFixture.cs b/src/AddIns/Misc/UnitTesting/Test/Tree/SolutionOpenedTestFixture.cs index 659c1e5280..2aee58a97b 100644 --- a/src/AddIns/Misc/UnitTesting/Test/Tree/SolutionOpenedTestFixture.cs +++ b/src/AddIns/Misc/UnitTesting/Test/Tree/SolutionOpenedTestFixture.cs @@ -26,6 +26,7 @@ namespace UnitTesting.Tests.Tree DerivedUnitTestsPad pad; Solution solution; MSBuildBasedProject project; + MockProjectContent projectContent; [TestFixtureSetUp] public void SetUpFixture() @@ -36,9 +37,10 @@ namespace UnitTesting.Tests.Tree [SetUp] public void Init() { + projectContent = new MockProjectContent(); + pad.ProjectContent = projectContent; solution = new Solution(); project = new MockCSharpProject(); - MockProjectContent projectContent = pad.ProjectContent; projectContent.Project = project; projectContent.Language = LanguageProperties.None; ReferenceProjectItem refProjectItem = new ReferenceProjectItem(project); @@ -340,5 +342,33 @@ namespace UnitTesting.Tests.Tree { Assert.IsTrue(pad.GetOpenSolutionCalled); } + + /// + /// Tests that a null solution clears the test tree. + /// + [Test] + public void NullSolution() + { + pad.CallSolutionLoaded(null); + Assert.AreEqual(0, pad.TestTreeView.Nodes.Count); + } + + /// + /// If the user opens another solution before the parser thread + /// has finished we can sometimes get into a state where the + /// first solution is being loaded into the test tree view but + /// its project content has been removed since the parser is working + /// on the next solution that was opened. In this case the test + /// tree view should ignore any project's that have null project + /// contents. + /// + [Test] + public void NullProjectContent() + { + DummyParserServiceTestTreeView tree = (DummyParserServiceTestTreeView)pad.TestTreeView; + tree.ProjectContentForProject = null; + + pad.CallSolutionLoaded(solution); + } } } diff --git a/src/AddIns/Misc/UnitTesting/Test/Tree/TwoTestClassesInDifferentNamespacesTestFixture.cs b/src/AddIns/Misc/UnitTesting/Test/Tree/TwoTestClassesInDifferentNamespacesTestFixture.cs index cc194a0070..6ac3ccd51d 100644 --- a/src/AddIns/Misc/UnitTesting/Test/Tree/TwoTestClassesInDifferentNamespacesTestFixture.cs +++ b/src/AddIns/Misc/UnitTesting/Test/Tree/TwoTestClassesInDifferentNamespacesTestFixture.cs @@ -65,7 +65,7 @@ namespace UnitTesting.Tests.Tree // Init mock project content to be returned. dummyTreeView = new DummyParserServiceTestTreeView(); - dummyTreeView.AddProjectContentForProject(projectContent); + dummyTreeView.ProjectContentForProject = projectContent; // Load the projects into the test tree view. treeView = dummyTreeView as TestTreeView; diff --git a/src/AddIns/Misc/UnitTesting/Test/Utils/DerivedUnitTestsPad.cs b/src/AddIns/Misc/UnitTesting/Test/Utils/DerivedUnitTestsPad.cs index 20899cff5e..57d2ceb250 100644 --- a/src/AddIns/Misc/UnitTesting/Test/Utils/DerivedUnitTestsPad.cs +++ b/src/AddIns/Misc/UnitTesting/Test/Utils/DerivedUnitTestsPad.cs @@ -26,6 +26,7 @@ namespace UnitTesting.Tests.Utils Solution openSolution; bool loadSolutionProjectsThreadEndedHandled; bool addedLoadSolutionProjectsThreadEndedHandler; + DummyParserServiceTestTreeView treeView = new DummyParserServiceTestTreeView(); public DerivedUnitTestsPad(Solution openSolution) { @@ -44,6 +45,10 @@ namespace UnitTesting.Tests.Utils get { return projectContent; } + set { + projectContent = value; + treeView.ProjectContentForProject = projectContent; + } } public bool GetOpenSolutionCalled { @@ -130,8 +135,6 @@ namespace UnitTesting.Tests.Utils /// protected override TestTreeView CreateTestTreeView() { - DummyParserServiceTestTreeView treeView = new DummyParserServiceTestTreeView(); - treeView.AddProjectContentForProject(projectContent); return treeView; } diff --git a/src/AddIns/Misc/UnitTesting/Test/Utils/DummyParserServiceTestTreeView.cs b/src/AddIns/Misc/UnitTesting/Test/Utils/DummyParserServiceTestTreeView.cs index 388144f250..39f5544c88 100644 --- a/src/AddIns/Misc/UnitTesting/Test/Utils/DummyParserServiceTestTreeView.cs +++ b/src/AddIns/Misc/UnitTesting/Test/Utils/DummyParserServiceTestTreeView.cs @@ -20,9 +20,17 @@ namespace UnitTesting.Tests.Utils { IProjectContent projectContent; - public void AddProjectContentForProject(IProjectContent projectContent) - { - this.projectContent = projectContent; + /// + /// Gets or sets the project content that will be returned from the + /// GetProjectContent method. + /// + public IProjectContent ProjectContentForProject { + get { + return projectContent; + } + set { + projectContent = value; + } } public override IProjectContent GetProjectContent(IProject project)