Skip to content

Commit

Permalink
Give Insert and Remove EndOfFile integration tests unique names since…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
codecadwallader committed Nov 23, 2014
1 parent 64c976c commit d4629c3
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 123 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Insert.Data
{
public class EndOfFileTrailingNewLine
public class InsertEndOfFileTrailingNewLine
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Insert.Data
{
public class EndOfFileTrailingNewLine
public class InsertEndOfFileTrailingNewLine
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Remove.Data
{
public class EndOfFileTrailingNewLine
{
}
}
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Remove.Data
{
public class RemoveEndOfFileTrailingNewLine
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Remove.Data
{
public class EndOfFileTrailingNewLine
{
}
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.Remove.Data
{
public class RemoveEndOfFileTrailingNewLine
{
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

#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 <http://www.gnu.org/licenses/>.

#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
}
}
12 changes: 6 additions & 6 deletions CodeMaid.IntegrationTests/CodeMaid.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Compile Include="Cleaning\FileTypes\SCSSTests.cs" />
<Content Include="Cleaning\Insert\Data\EndOfFileTrailingNewLine.cs">
<Content Include="Cleaning\Insert\Data\InsertEndOfFileTrailingNewLine.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Cleaning\Insert\Data\EndOfFileTrailingNewLine_Cleaned.cs">
<Content Include="Cleaning\Insert\Data\InsertEndOfFileTrailingNewLine_Cleaned.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Compile Include="Cleaning\Insert\EndOfFileTrailingNewLineTests.cs" />
<Compile Include="Cleaning\Insert\InsertEndOfFileTrailingNewLineTests.cs" />
<Compile Include="Cleaning\Remove\RemoveAllRegionsTests.cs" />
<Compile Include="Cleaning\Remove\RemoveCurrentRegionTests.cs" />
<Compile Include="Cleaning\Remove\RemoveEmptyRegionsTests.cs" />
Expand Down Expand Up @@ -532,10 +532,10 @@
<Content Include="Cleaning\Remove\Data\BlankSpacesBeforeClosingAngleBracket_Cleaned.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Cleaning\Remove\Data\EndOfFileTrailingNewLine_Cleaned.cs">
<Content Include="Cleaning\Remove\Data\RemoveEndOfFileTrailingNewLine_Cleaned.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Cleaning\Remove\Data\EndOfFileTrailingNewLine.cs">
<Content Include="Cleaning\Remove\Data\RemoveEndOfFileTrailingNewLine.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Compile Include="Cleaning\Remove\BlankLinesBetweenChainedStatementsTests.cs" />
Expand All @@ -547,7 +547,7 @@
<Content Include="Cleaning\Remove\Data\BlankLinesBetweenChainedStatements_Cleaned.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Compile Include="Cleaning\Remove\EndOfFileTrailingNewLineTests.cs" />
<Compile Include="Cleaning\Remove\RemoveEndOfFileTrailingNewLineTests.cs" />
<Compile Include="Cleaning\Remove\EndOfLineWhitespaceTests.cs" />
<Compile Include="Cleaning\Remove\MultipleConsecutiveBlankLinesTests.cs" />
<Content Include="Cleaning\Remove\Data\EndOfLineWhitespace.cs">
Expand Down
20 changes: 14 additions & 6 deletions CodeMaid/Logic/Digging/OutliningSynchronizationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/// <summary>
Expand Down

0 comments on commit d4629c3

Please sign in to comment.