Skip to content

Commit 21447d5

Browse files
#87: Shift captured using statement point by one character to handle scenario where a new statement is added to the same position when two statements are reversed. Also added suite of integration tests for Cleaning VisualStudio actions.
1 parent 13d8465 commit 21447d5

11 files changed

+346
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.VisualStudio.Data
8+
{
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using System;
2+
using System.Linq;
3+
4+
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.VisualStudio.Data
5+
{
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.VisualStudio.Data
8+
{
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+

2+
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.VisualStudio.Data
3+
{
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Threading.Tasks;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using System.Linq;
6+
7+
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.VisualStudio.Data
8+
{
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.VisualStudio.Data
8+
{
9+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#region CodeMaid is Copyright 2007-2015 Steve Cadwallader.
2+
3+
// CodeMaid is free software: you can redistribute it and/or modify it under the terms of the GNU
4+
// Lesser General Public License version 3 as published by the Free Software Foundation.
5+
//
6+
// CodeMaid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
7+
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8+
// Lesser General Public License for more details <http://www.gnu.org/licenses/>.
9+
10+
#endregion CodeMaid is Copyright 2007-2015 Steve Cadwallader.
11+
12+
using EnvDTE;
13+
using Microsoft.VisualStudio.TestTools.UnitTesting;
14+
using SteveCadwallader.CodeMaid.Helpers;
15+
using SteveCadwallader.CodeMaid.IntegrationTests.Helpers;
16+
using SteveCadwallader.CodeMaid.Logic.Cleaning;
17+
using SteveCadwallader.CodeMaid.Properties;
18+
19+
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.VisualStudio
20+
{
21+
[TestClass]
22+
[DeploymentItem(@"Cleaning\VisualStudio\Data\ReinsertAfterRemoveUnusedUsingStatements.cs", "Data")]
23+
[DeploymentItem(@"Cleaning\VisualStudio\Data\ReinsertAfterRemoveUnusedUsingStatements_Cleaned.cs", "Data")]
24+
public class ReinsertAfterRemoveUnusedUsingStatementsTests
25+
{
26+
#region Setup
27+
28+
private static UsingStatementCleanupLogic _usingStatementCleanupLogic;
29+
private ProjectItem _projectItem;
30+
31+
[ClassInitialize]
32+
public static void ClassInitialize(TestContext testContext)
33+
{
34+
_usingStatementCleanupLogic = UsingStatementCleanupLogic.GetInstance(TestEnvironment.Package);
35+
Assert.IsNotNull(_usingStatementCleanupLogic);
36+
}
37+
38+
[TestInitialize]
39+
public void TestInitialize()
40+
{
41+
TestEnvironment.CommonTestInitialize();
42+
_projectItem = TestEnvironment.LoadFileIntoProject(@"Data\ReinsertAfterRemoveUnusedUsingStatements.cs");
43+
}
44+
45+
[TestCleanup]
46+
public void TestCleanup()
47+
{
48+
TestEnvironment.RemoveFromProject(_projectItem);
49+
}
50+
51+
#endregion Setup
52+
53+
#region Tests
54+
55+
[TestMethod]
56+
[HostType("VS IDE")]
57+
public void CleaningVisualStudioReinsertAfterRemoveUnusedUsingStatements_RunsAsExpected()
58+
{
59+
Settings.Default.Cleaning_RunVisualStudioRemoveUnusedUsingStatements = true;
60+
Settings.Default.Cleaning_UsingStatementsToReinsertWhenRemovedExpression = "using System;||using System.Linq;";
61+
62+
TestOperations.ExecuteCommandAndVerifyResults(RunRemoveUnusedUsingStatements, _projectItem, @"Data\ReinsertAfterRemoveUnusedUsingStatements_Cleaned.cs");
63+
}
64+
65+
[TestMethod]
66+
[HostType("VS IDE")]
67+
public void CleaningVisualStudioReinsertAfterRemoveUnusedUsingStatements_DoesNothingWhenSettingIsDisabled()
68+
{
69+
Settings.Default.Cleaning_RunVisualStudioRemoveUnusedUsingStatements = false;
70+
Settings.Default.Cleaning_UsingStatementsToReinsertWhenRemovedExpression = "using System;||using System.Linq;";
71+
72+
TestOperations.ExecuteCommandAndVerifyNoChanges(RunRemoveUnusedUsingStatements, _projectItem);
73+
}
74+
75+
#endregion Tests
76+
77+
#region Helpers
78+
79+
private static void RunRemoveUnusedUsingStatements(Document document)
80+
{
81+
_usingStatementCleanupLogic.RemoveUnusedUsingStatements(document.GetTextDocument(), false);
82+
}
83+
84+
#endregion Helpers
85+
}
86+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#region CodeMaid is Copyright 2007-2015 Steve Cadwallader.
2+
3+
// CodeMaid is free software: you can redistribute it and/or modify it under the terms of the GNU
4+
// Lesser General Public License version 3 as published by the Free Software Foundation.
5+
//
6+
// CodeMaid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
7+
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8+
// Lesser General Public License for more details <http://www.gnu.org/licenses/>.
9+
10+
#endregion CodeMaid is Copyright 2007-2015 Steve Cadwallader.
11+
12+
using EnvDTE;
13+
using Microsoft.VisualStudio.TestTools.UnitTesting;
14+
using SteveCadwallader.CodeMaid.Helpers;
15+
using SteveCadwallader.CodeMaid.IntegrationTests.Helpers;
16+
using SteveCadwallader.CodeMaid.Logic.Cleaning;
17+
using SteveCadwallader.CodeMaid.Properties;
18+
19+
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.VisualStudio
20+
{
21+
[TestClass]
22+
[DeploymentItem(@"Cleaning\VisualStudio\Data\RemoveUnusedUsingStatements.cs", "Data")]
23+
[DeploymentItem(@"Cleaning\VisualStudio\Data\RemoveUnusedUsingStatements_Cleaned.cs", "Data")]
24+
public class RemoveUnusedUsingStatementsTests
25+
{
26+
#region Setup
27+
28+
private static UsingStatementCleanupLogic _usingStatementCleanupLogic;
29+
private ProjectItem _projectItem;
30+
31+
[ClassInitialize]
32+
public static void ClassInitialize(TestContext testContext)
33+
{
34+
_usingStatementCleanupLogic = UsingStatementCleanupLogic.GetInstance(TestEnvironment.Package);
35+
Assert.IsNotNull(_usingStatementCleanupLogic);
36+
}
37+
38+
[TestInitialize]
39+
public void TestInitialize()
40+
{
41+
TestEnvironment.CommonTestInitialize();
42+
_projectItem = TestEnvironment.LoadFileIntoProject(@"Data\RemoveUnusedUsingStatements.cs");
43+
}
44+
45+
[TestCleanup]
46+
public void TestCleanup()
47+
{
48+
TestEnvironment.RemoveFromProject(_projectItem);
49+
}
50+
51+
#endregion Setup
52+
53+
#region Tests
54+
55+
[TestMethod]
56+
[HostType("VS IDE")]
57+
public void CleaningVisualStudioRemoveUnusedUsingStatements_RunsAsExpected()
58+
{
59+
Settings.Default.Cleaning_RunVisualStudioRemoveUnusedUsingStatements = true;
60+
61+
TestOperations.ExecuteCommandAndVerifyResults(RunRemoveUnusedUsingStatements, _projectItem, @"Data\RemoveUnusedUsingStatements_Cleaned.cs");
62+
}
63+
64+
[TestMethod]
65+
[HostType("VS IDE")]
66+
public void CleaningVisualStudioRemoveUnusedUsingStatements_DoesNothingOnSecondPass()
67+
{
68+
Settings.Default.Cleaning_RunVisualStudioRemoveUnusedUsingStatements = true;
69+
70+
TestOperations.ExecuteCommandTwiceAndVerifyNoChangesOnSecondPass(RunRemoveUnusedUsingStatements, _projectItem);
71+
}
72+
73+
[TestMethod]
74+
[HostType("VS IDE")]
75+
public void CleaningVisualStudioRemoveUnusedUsingStatements_DoesNothingWhenSettingIsDisabled()
76+
{
77+
Settings.Default.Cleaning_RunVisualStudioRemoveUnusedUsingStatements = false;
78+
79+
TestOperations.ExecuteCommandAndVerifyNoChanges(RunRemoveUnusedUsingStatements, _projectItem);
80+
}
81+
82+
#endregion Tests
83+
84+
#region Helpers
85+
86+
private static void RunRemoveUnusedUsingStatements(Document document)
87+
{
88+
_usingStatementCleanupLogic.RemoveUnusedUsingStatements(document.GetTextDocument(), false);
89+
}
90+
91+
#endregion Helpers
92+
}
93+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#region CodeMaid is Copyright 2007-2015 Steve Cadwallader.
2+
3+
// CodeMaid is free software: you can redistribute it and/or modify it under the terms of the GNU
4+
// Lesser General Public License version 3 as published by the Free Software Foundation.
5+
//
6+
// CodeMaid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
7+
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8+
// Lesser General Public License for more details <http://www.gnu.org/licenses/>.
9+
10+
#endregion CodeMaid is Copyright 2007-2015 Steve Cadwallader.
11+
12+
using EnvDTE;
13+
using Microsoft.VisualStudio.TestTools.UnitTesting;
14+
using SteveCadwallader.CodeMaid.IntegrationTests.Helpers;
15+
using SteveCadwallader.CodeMaid.Logic.Cleaning;
16+
using SteveCadwallader.CodeMaid.Properties;
17+
18+
namespace SteveCadwallader.CodeMaid.IntegrationTests.Cleaning.VisualStudio
19+
{
20+
[TestClass]
21+
[DeploymentItem(@"Cleaning\VisualStudio\Data\SortUsingStatements.cs", "Data")]
22+
[DeploymentItem(@"Cleaning\VisualStudio\Data\SortUsingStatements_Cleaned.cs", "Data")]
23+
public class SortUsingStatementsTests
24+
{
25+
#region Setup
26+
27+
private static UsingStatementCleanupLogic _usingStatementCleanupLogic;
28+
private ProjectItem _projectItem;
29+
30+
[ClassInitialize]
31+
public static void ClassInitialize(TestContext testContext)
32+
{
33+
_usingStatementCleanupLogic = UsingStatementCleanupLogic.GetInstance(TestEnvironment.Package);
34+
Assert.IsNotNull(_usingStatementCleanupLogic);
35+
}
36+
37+
[TestInitialize]
38+
public void TestInitialize()
39+
{
40+
TestEnvironment.CommonTestInitialize();
41+
_projectItem = TestEnvironment.LoadFileIntoProject(@"Data\SortUsingStatements.cs");
42+
}
43+
44+
[TestCleanup]
45+
public void TestCleanup()
46+
{
47+
TestEnvironment.RemoveFromProject(_projectItem);
48+
}
49+
50+
#endregion Setup
51+
52+
#region Tests
53+
54+
[TestMethod]
55+
[HostType("VS IDE")]
56+
public void CleaningVisualStudioSortUsingStatements_RunsAsExpected()
57+
{
58+
Settings.Default.Cleaning_RunVisualStudioSortUsingStatements = true;
59+
60+
TestOperations.ExecuteCommandAndVerifyResults(RunSortUsingStatements, _projectItem, @"Data\SortUsingStatements_Cleaned.cs");
61+
}
62+
63+
[TestMethod]
64+
[HostType("VS IDE")]
65+
public void CleaningVisualStudioSortUsingStatements_DoesNothingOnSecondPass()
66+
{
67+
Settings.Default.Cleaning_RunVisualStudioSortUsingStatements = true;
68+
69+
TestOperations.ExecuteCommandTwiceAndVerifyNoChangesOnSecondPass(RunSortUsingStatements, _projectItem);
70+
}
71+
72+
[TestMethod]
73+
[HostType("VS IDE")]
74+
public void CleaningVisualStudioSortUsingStatements_DoesNothingWhenSettingIsDisabled()
75+
{
76+
Settings.Default.Cleaning_RunVisualStudioSortUsingStatements = false;
77+
78+
TestOperations.ExecuteCommandAndVerifyNoChanges(RunSortUsingStatements, _projectItem);
79+
}
80+
81+
#endregion Tests
82+
83+
#region Helpers
84+
85+
private static void RunSortUsingStatements(Document document)
86+
{
87+
_usingStatementCleanupLogic.SortUsingStatements(false);
88+
}
89+
90+
#endregion Helpers
91+
}
92+
}

CodeMaid.IntegrationTests/CodeMaid.IntegrationTests.csproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@
170170
<Compile Include="Cleaning\Remove\RemoveEmptyRegionsTests.cs" />
171171
<Compile Include="Cleaning\Remove\RemoveSetOfRegionsTests.cs" />
172172
<Compile Include="Cleaning\Remove\RemoveSelectedRegionsTests.cs" />
173+
<Content Include="Cleaning\VisualStudio\Data\SortUsingStatements.cs">
174+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
175+
</Content>
176+
<Content Include="Cleaning\VisualStudio\Data\SortUsingStatements_Cleaned.cs">
177+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
178+
</Content>
179+
<Content Include="Cleaning\VisualStudio\Data\RemoveUnusedUsingStatements.cs">
180+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
181+
</Content>
182+
<Content Include="Cleaning\VisualStudio\Data\RemoveUnusedUsingStatements_Cleaned.cs">
183+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
184+
</Content>
185+
<Content Include="Cleaning\VisualStudio\Data\ReinsertAfterRemoveUnusedUsingStatements.cs">
186+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
187+
</Content>
188+
<Content Include="Cleaning\VisualStudio\Data\ReinsertAfterRemoveUnusedUsingStatements_Cleaned.cs">
189+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
190+
</Content>
191+
<Compile Include="Cleaning\VisualStudio\ReinsertAfterRemoveUnusedUsingStatementsTests.cs" />
192+
<Compile Include="Cleaning\VisualStudio\RemoveUnusedUsingStatementsTests.cs" />
193+
<Compile Include="Cleaning\VisualStudio\SortUsingStatementsTests.cs" />
173194
<Compile Include="Formatting\StandardCommentFormatTests.cs" />
174195
<Compile Include="Formatting\BaseCommentFormatTests.cs" />
175196
<Compile Include="Formatting\StylecopHeaderFormatTests.cs" />
@@ -741,6 +762,7 @@
741762
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
742763
</Content>
743764
</ItemGroup>
765+
<ItemGroup />
744766
<Choose>
745767
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
746768
<ItemGroup>

0 commit comments

Comments
 (0)