From d4629c377fd64ea12e19a777a84d62af7994d76f Mon Sep 17 00:00:00 2001 From: Steve Cadwallader Date: Sun, 23 Nov 2014 08:41:15 -0500 Subject: [PATCH] Give Insert and Remove EndOfFile integration tests unique names since the test files are copied to the same folder. Also add a try/catch block around an outlining synchronization section that was failing in the integration test context. --- ...e.cs => InsertEndOfFileTrailingNewLine.cs} | 2 +- ...InsertEndOfFileTrailingNewLine_Cleaned.cs} | 2 +- ...=> InsertEndOfFileTrailingNewLineTests.cs} | 10 +- ...e.cs => RemoveEndOfFileTrailingNewLine.cs} | 12 +- ...RemoveEndOfFileTrailingNewLine_Cleaned.cs} | 10 +- ...=> RemoveEndOfFileTrailingNewLineTests.cs} | 186 +++++++++--------- .../CodeMaid.IntegrationTests.csproj | 12 +- .../OutliningSynchronizationManager.cs | 20 +- 8 files changed, 131 insertions(+), 123 deletions(-) rename CodeMaid.IntegrationTests/Cleaning/Insert/Data/{EndOfFileTrailingNewLine.cs => InsertEndOfFileTrailingNewLine.cs} (65%) rename CodeMaid.IntegrationTests/Cleaning/Insert/Data/{EndOfFileTrailingNewLine_Cleaned.cs => InsertEndOfFileTrailingNewLine_Cleaned.cs} (65%) rename CodeMaid.IntegrationTests/Cleaning/Insert/{EndOfFileTrailingNewLineTests.cs => InsertEndOfFileTrailingNewLineTests.cs} (88%) rename CodeMaid.IntegrationTests/Cleaning/Remove/Data/{EndOfFileTrailingNewLine.cs => RemoveEndOfFileTrailingNewLine.cs} (65%) rename CodeMaid.IntegrationTests/Cleaning/Remove/Data/{EndOfFileTrailingNewLine_Cleaned.cs => RemoveEndOfFileTrailingNewLine_Cleaned.cs} (65%) rename CodeMaid.IntegrationTests/Cleaning/Remove/{EndOfFileTrailingNewLineTests.cs => RemoveEndOfFileTrailingNewLineTests.cs} (87%) diff --git a/CodeMaid.IntegrationTests/Cleaning/Insert/Data/EndOfFileTrailingNewLine.cs b/CodeMaid.IntegrationTests/Cleaning/Insert/Data/InsertEndOfFileTrailingNewLine.cs similarity index 65% rename from CodeMaid.IntegrationTests/Cleaning/Insert/Data/EndOfFileTrailingNewLine.cs rename to CodeMaid.IntegrationTests/Cleaning/Insert/Data/InsertEndOfFileTrailingNewLine.cs index 17827b9e..2918fcc8 100644 --- a/CodeMaid.IntegrationTests/Cleaning/Insert/Data/EndOfFileTrailingNewLine.cs +++ b/CodeMaid.IntegrationTests/Cleaning/Insert/Data/InsertEndOfFileTrailingNewLine.cs @@ -1,6 +1,6 @@ namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Insert.Data { - public class EndOfFileTrailingNewLine + public class InsertEndOfFileTrailingNewLine { } } \ No newline at end of file diff --git a/CodeMaid.IntegrationTests/Cleaning/Insert/Data/EndOfFileTrailingNewLine_Cleaned.cs b/CodeMaid.IntegrationTests/Cleaning/Insert/Data/InsertEndOfFileTrailingNewLine_Cleaned.cs similarity index 65% rename from CodeMaid.IntegrationTests/Cleaning/Insert/Data/EndOfFileTrailingNewLine_Cleaned.cs rename to CodeMaid.IntegrationTests/Cleaning/Insert/Data/InsertEndOfFileTrailingNewLine_Cleaned.cs index 609a75c5..00294bc3 100644 --- a/CodeMaid.IntegrationTests/Cleaning/Insert/Data/EndOfFileTrailingNewLine_Cleaned.cs +++ b/CodeMaid.IntegrationTests/Cleaning/Insert/Data/InsertEndOfFileTrailingNewLine_Cleaned.cs @@ -1,6 +1,6 @@ namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Insert.Data { - public class EndOfFileTrailingNewLine + public class InsertEndOfFileTrailingNewLine { } } diff --git a/CodeMaid.IntegrationTests/Cleaning/Insert/EndOfFileTrailingNewLineTests.cs b/CodeMaid.IntegrationTests/Cleaning/Insert/InsertEndOfFileTrailingNewLineTests.cs similarity index 88% rename from CodeMaid.IntegrationTests/Cleaning/Insert/EndOfFileTrailingNewLineTests.cs rename to CodeMaid.IntegrationTests/Cleaning/Insert/InsertEndOfFileTrailingNewLineTests.cs index 67e16186..2982aaef 100644 --- a/CodeMaid.IntegrationTests/Cleaning/Insert/EndOfFileTrailingNewLineTests.cs +++ b/CodeMaid.IntegrationTests/Cleaning/Insert/InsertEndOfFileTrailingNewLineTests.cs @@ -18,9 +18,9 @@ namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Insert { [TestClass] - [DeploymentItem(@"Cleaning\Insert\Data\EndOfFileTrailingNewLine.cs", "Data")] - [DeploymentItem(@"Cleaning\Insert\Data\EndOfFileTrailingNewLine_Cleaned.cs", "Data")] - public class EndOfFileTrailingNewLineTests + [DeploymentItem(@"Cleaning\Insert\Data\InsertEndOfFileTrailingNewLine.cs", "Data")] + [DeploymentItem(@"Cleaning\Insert\Data\InsertEndOfFileTrailingNewLine_Cleaned.cs", "Data")] + public class InsertEndOfFileTrailingNewLineTests { #region Setup @@ -38,7 +38,7 @@ public static void ClassInitialize(TestContext testContext) public void TestInitialize() { TestEnvironment.CommonTestInitialize(); - _projectItem = TestEnvironment.LoadFileIntoProject(@"Data\EndOfFileTrailingNewLine.cs"); + _projectItem = TestEnvironment.LoadFileIntoProject(@"Data\InsertEndOfFileTrailingNewLine.cs"); } [TestCleanup] @@ -57,7 +57,7 @@ public void CleaningInsertEndOfFileTrailingNewLine_CleansAsExpected() { Settings.Default.Cleaning_InsertEndOfFileTrailingNewLine = true; - TestOperations.ExecuteCommandAndVerifyResults(RunInsertEndOfFileTrailingNewLine, _projectItem, @"Data\EndOfFileTrailingNewLine_Cleaned.cs"); + TestOperations.ExecuteCommandAndVerifyResults(RunInsertEndOfFileTrailingNewLine, _projectItem, @"Data\InsertEndOfFileTrailingNewLine_Cleaned.cs"); } [TestMethod] diff --git a/CodeMaid.IntegrationTests/Cleaning/Remove/Data/EndOfFileTrailingNewLine.cs b/CodeMaid.IntegrationTests/Cleaning/Remove/Data/RemoveEndOfFileTrailingNewLine.cs similarity index 65% rename from CodeMaid.IntegrationTests/Cleaning/Remove/Data/EndOfFileTrailingNewLine.cs rename to CodeMaid.IntegrationTests/Cleaning/Remove/Data/RemoveEndOfFileTrailingNewLine.cs index e10f058b..f0152a2b 100644 --- a/CodeMaid.IntegrationTests/Cleaning/Remove/Data/EndOfFileTrailingNewLine.cs +++ b/CodeMaid.IntegrationTests/Cleaning/Remove/Data/RemoveEndOfFileTrailingNewLine.cs @@ -1,6 +1,6 @@ -namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Remove.Data -{ - public class EndOfFileTrailingNewLine - { - } -} +namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Remove.Data +{ + public class RemoveEndOfFileTrailingNewLine + { + } +} diff --git a/CodeMaid.IntegrationTests/Cleaning/Remove/Data/EndOfFileTrailingNewLine_Cleaned.cs b/CodeMaid.IntegrationTests/Cleaning/Remove/Data/RemoveEndOfFileTrailingNewLine_Cleaned.cs similarity index 65% rename from CodeMaid.IntegrationTests/Cleaning/Remove/Data/EndOfFileTrailingNewLine_Cleaned.cs rename to CodeMaid.IntegrationTests/Cleaning/Remove/Data/RemoveEndOfFileTrailingNewLine_Cleaned.cs index c5bc4cde..8169e7a6 100644 --- a/CodeMaid.IntegrationTests/Cleaning/Remove/Data/EndOfFileTrailingNewLine_Cleaned.cs +++ b/CodeMaid.IntegrationTests/Cleaning/Remove/Data/RemoveEndOfFileTrailingNewLine_Cleaned.cs @@ -1,6 +1,6 @@ -namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Remove.Data -{ - public class EndOfFileTrailingNewLine - { - } +namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Remove.Data +{ + public class RemoveEndOfFileTrailingNewLine + { + } } \ No newline at end of file diff --git a/CodeMaid.IntegrationTests/Cleaning/Remove/EndOfFileTrailingNewLineTests.cs b/CodeMaid.IntegrationTests/Cleaning/Remove/RemoveEndOfFileTrailingNewLineTests.cs similarity index 87% rename from CodeMaid.IntegrationTests/Cleaning/Remove/EndOfFileTrailingNewLineTests.cs rename to CodeMaid.IntegrationTests/Cleaning/Remove/RemoveEndOfFileTrailingNewLineTests.cs index bd97f204..f0b88bbc 100644 --- a/CodeMaid.IntegrationTests/Cleaning/Remove/EndOfFileTrailingNewLineTests.cs +++ b/CodeMaid.IntegrationTests/Cleaning/Remove/RemoveEndOfFileTrailingNewLineTests.cs @@ -1,94 +1,94 @@ -#region CodeMaid is Copyright 2007-2014 Steve Cadwallader. - -// CodeMaid is free software: you can redistribute it and/or modify it under the terms of the GNU -// Lesser General Public License version 3 as published by the Free Software Foundation. -// -// CodeMaid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without -// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details . - -#endregion CodeMaid is Copyright 2007-2014 Steve Cadwallader. - -using EnvDTE; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using SteveCadwallader.CodeMaid.IntegrationTests.Helpers; -using SteveCadwallader.CodeMaid.Logic.Cleaning; -using SteveCadwallader.CodeMaid.Properties; - -namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Remove -{ - [TestClass] - [DeploymentItem(@"Cleaning\Remove\Data\EndOfFileTrailingNewLine.cs", "Data")] - [DeploymentItem(@"Cleaning\Remove\Data\EndOfFileTrailingNewLine_Cleaned.cs", "Data")] - public class EndOfFileTrailingNewLineTests - { - #region Setup - - private static RemoveWhitespaceLogic _removeWhitespaceLogic; - private ProjectItem _projectItem; - - [ClassInitialize] - public static void ClassInitialize(TestContext testContext) - { - _removeWhitespaceLogic = RemoveWhitespaceLogic.GetInstance(TestEnvironment.Package); - Assert.IsNotNull(_removeWhitespaceLogic); - } - - [TestInitialize] - public void TestInitialize() - { - TestEnvironment.CommonTestInitialize(); - _projectItem = TestEnvironment.LoadFileIntoProject(@"Data\EndOfFileTrailingNewLine.cs"); - } - - [TestCleanup] - public void TestCleanup() - { - TestEnvironment.RemoveFromProject(_projectItem); - } - - #endregion Setup - - #region Tests - - [TestMethod] - [HostType("VS IDE")] - public void CleaningRemoveEndOfFileTrailingNewLine_CleansAsExpected() - { - Settings.Default.Cleaning_RemoveEndOfFileTrailingNewLine = true; - - TestOperations.ExecuteCommandAndVerifyResults(RunRemoveEndOfFileTrailingNewLine, _projectItem, @"Data\EndOfFileTrailingNewLine_Cleaned.cs"); - } - - [TestMethod] - [HostType("VS IDE")] - public void CleaningRemoveEndOfFileTrailingNewLine_DoesNothingOnSecondPass() - { - Settings.Default.Cleaning_RemoveEndOfFileTrailingNewLine = true; - - TestOperations.ExecuteCommandTwiceAndVerifyNoChangesOnSecondPass(RunRemoveEndOfFileTrailingNewLine, _projectItem); - } - - [TestMethod] - [HostType("VS IDE")] - public void CleaningRemoveEndOfFileTrailingNewLine_DoesNothingWhenSettingIsDisabled() - { - Settings.Default.Cleaning_RemoveEndOfFileTrailingNewLine = false; - - TestOperations.ExecuteCommandAndVerifyNoChanges(RunRemoveEndOfFileTrailingNewLine, _projectItem); - } - - #endregion Tests - - #region Helpers - - private static void RunRemoveEndOfFileTrailingNewLine(Document document) - { - var textDocument = TestUtils.GetTextDocument(document); - - _removeWhitespaceLogic.RemoveEOFTrailingNewLine(textDocument); - } - - #endregion Helpers - } +#region CodeMaid is Copyright 2007-2014 Steve Cadwallader. + +// CodeMaid is free software: you can redistribute it and/or modify it under the terms of the GNU +// Lesser General Public License version 3 as published by the Free Software Foundation. +// +// CodeMaid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details . + +#endregion CodeMaid is Copyright 2007-2014 Steve Cadwallader. + +using EnvDTE; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SteveCadwallader.CodeMaid.IntegrationTests.Helpers; +using SteveCadwallader.CodeMaid.Logic.Cleaning; +using SteveCadwallader.CodeMaid.Properties; + +namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Remove +{ + [TestClass] + [DeploymentItem(@"Cleaning\Remove\Data\RemoveEndOfFileTrailingNewLine.cs", "Data")] + [DeploymentItem(@"Cleaning\Remove\Data\RemoveEndOfFileTrailingNewLine_Cleaned.cs", "Data")] + public class RemoveEndOfFileTrailingNewLineTests + { + #region Setup + + private static RemoveWhitespaceLogic _removeWhitespaceLogic; + private ProjectItem _projectItem; + + [ClassInitialize] + public static void ClassInitialize(TestContext testContext) + { + _removeWhitespaceLogic = RemoveWhitespaceLogic.GetInstance(TestEnvironment.Package); + Assert.IsNotNull(_removeWhitespaceLogic); + } + + [TestInitialize] + public void TestInitialize() + { + TestEnvironment.CommonTestInitialize(); + _projectItem = TestEnvironment.LoadFileIntoProject(@"Data\RemoveEndOfFileTrailingNewLine.cs"); + } + + [TestCleanup] + public void TestCleanup() + { + TestEnvironment.RemoveFromProject(_projectItem); + } + + #endregion Setup + + #region Tests + + [TestMethod] + [HostType("VS IDE")] + public void CleaningRemoveEndOfFileTrailingNewLine_CleansAsExpected() + { + Settings.Default.Cleaning_RemoveEndOfFileTrailingNewLine = true; + + TestOperations.ExecuteCommandAndVerifyResults(RunRemoveEndOfFileTrailingNewLine, _projectItem, @"Data\RemoveEndOfFileTrailingNewLine_Cleaned.cs"); + } + + [TestMethod] + [HostType("VS IDE")] + public void CleaningRemoveEndOfFileTrailingNewLine_DoesNothingOnSecondPass() + { + Settings.Default.Cleaning_RemoveEndOfFileTrailingNewLine = true; + + TestOperations.ExecuteCommandTwiceAndVerifyNoChangesOnSecondPass(RunRemoveEndOfFileTrailingNewLine, _projectItem); + } + + [TestMethod] + [HostType("VS IDE")] + public void CleaningRemoveEndOfFileTrailingNewLine_DoesNothingWhenSettingIsDisabled() + { + Settings.Default.Cleaning_RemoveEndOfFileTrailingNewLine = false; + + TestOperations.ExecuteCommandAndVerifyNoChanges(RunRemoveEndOfFileTrailingNewLine, _projectItem); + } + + #endregion Tests + + #region Helpers + + private static void RunRemoveEndOfFileTrailingNewLine(Document document) + { + var textDocument = TestUtils.GetTextDocument(document); + + _removeWhitespaceLogic.RemoveEOFTrailingNewLine(textDocument); + } + + #endregion Helpers + } } \ No newline at end of file diff --git a/CodeMaid.IntegrationTests/CodeMaid.IntegrationTests.csproj b/CodeMaid.IntegrationTests/CodeMaid.IntegrationTests.csproj index 2f3de666..5a5af96a 100644 --- a/CodeMaid.IntegrationTests/CodeMaid.IntegrationTests.csproj +++ b/CodeMaid.IntegrationTests/CodeMaid.IntegrationTests.csproj @@ -153,13 +153,13 @@ PreserveNewest - + PreserveNewest - + PreserveNewest - + @@ -532,10 +532,10 @@ PreserveNewest - + PreserveNewest - + PreserveNewest @@ -547,7 +547,7 @@ PreserveNewest - + diff --git a/CodeMaid/Logic/Digging/OutliningSynchronizationManager.cs b/CodeMaid/Logic/Digging/OutliningSynchronizationManager.cs index 7d99e614..e0bb06a6 100644 --- a/CodeMaid/Logic/Digging/OutliningSynchronizationManager.cs +++ b/CodeMaid/Logic/Digging/OutliningSynchronizationManager.cs @@ -209,13 +209,21 @@ private ICollapsible FindCollapsibleFromCodeItemParent(ICodeItemParent parent) return null; } - var snapshotLine = _wpfTextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(parent.StartLine); - var collapsibles = _outliningManager.GetAllRegions(snapshotLine.Extent); + try + { + var snapshotLine = _wpfTextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(parent.StartLine); + var collapsibles = _outliningManager.GetAllRegions(snapshotLine.Extent); - return (from collapsible in collapsibles - let startLine = GetStartLineForCollapsible(collapsible) - where startLine == parent.StartLine - select collapsible).FirstOrDefault(); + return (from collapsible in collapsibles + let startLine = GetStartLineForCollapsible(collapsible) + where startLine == parent.StartLine + select collapsible).FirstOrDefault(); + } + catch (Exception ex) + { + OutputWindowHelper.ExceptionWriteLine("Unable to find collapsible from ICodeItemParent", ex); + return null; + } } ///