Skip to content

Commit 8db3c37

Browse files
committed
Fix bug, add more remove tests
1 parent ad8e1e8 commit 8db3c37

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

RetailCoder.VBE/Refactorings/RemoveParameters/RemoveParametersRefactoring.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Rubberduck.Parsing;
77
using Rubberduck.Parsing.Grammar;
88
using Rubberduck.Parsing.Symbols;
9+
using Rubberduck.UI;
910
using Rubberduck.VBA;
1011
using Rubberduck.VBEditor;
1112

@@ -57,7 +58,7 @@ public void Refactor(Declaration target)
5758

5859
public void QuickFix(VBProjectParseResult parseResult, QualifiedSelection selection)
5960
{
60-
_model = new RemoveParametersModel(parseResult, selection, null);
61+
_model = new RemoveParametersModel(parseResult, selection, new RubberduckMessageBox());
6162
var target = _model.Declarations.FindSelection(selection, new[] { DeclarationType.Parameter });
6263

6364
// ReSharper disable once PossibleUnintendedReferenceComparison
@@ -67,7 +68,7 @@ public void QuickFix(VBProjectParseResult parseResult, QualifiedSelection select
6768

6869
private void RemoveParameters()
6970
{
70-
if (_model.TargetDeclaration == null) { throw new NullReferenceException("Parameter is null."); }
71+
if (_model.TargetDeclaration == null) { throw new NullReferenceException("Parameter is null"); }
7172

7273
AdjustReferences(_model.TargetDeclaration.References, _model.TargetDeclaration);
7374
AdjustSignatures();

RubberduckTests/Refactoring/RemoveParametersTests.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,64 @@ public void RemoveParams_RefactorDeclaration_FailsInvalidTarget()
11291129
{
11301130
Assert.AreEqual("Invalid declaration type", e.Message);
11311131
}
1132+
1133+
Assert.IsTrue(false);
1134+
}
1135+
1136+
[TestMethod]
1137+
public void RemoveParams_PresenterIsNull()
1138+
{
1139+
//Input
1140+
const string inputCode =
1141+
@"Private Sub Foo()
1142+
End Sub";
1143+
1144+
//Arrange
1145+
var project = SetupMockProject(inputCode);
1146+
var module = project.Object.VBComponents.Item(0).CodeModule;
1147+
var parseResult = new RubberduckParser().Parse(project.Object);
1148+
1149+
var editor = new Mock<IActiveCodePaneEditor>();
1150+
editor.Setup(e => e.GetSelection()).Returns((QualifiedSelection?)null);
1151+
1152+
var factory = new RemoveParametersPresenterFactory(editor.Object, null,
1153+
parseResult, null);
1154+
1155+
//act
1156+
var refactoring = new RemoveParametersRefactoring(factory);
1157+
refactoring.Refactor();
1158+
1159+
Assert.AreEqual(inputCode, module.Lines());
1160+
}
1161+
1162+
[TestMethod]
1163+
public void RemoveParams_ModelIsNull()
1164+
{
1165+
//Input
1166+
const string inputCode =
1167+
@"Private Sub Foo()
1168+
End Sub";
1169+
var selection = new Selection(1, 23, 1, 27); //startLine, startCol, endLine, endCol
1170+
1171+
//Arrange
1172+
var project = SetupMockProject(inputCode);
1173+
var module = project.Object.VBComponents.Item(0).CodeModule;
1174+
var parseResult = new RubberduckParser().Parse(project.Object);
1175+
1176+
var qualifiedSelection = GetQualifiedSelection(selection);
1177+
1178+
//Specify Param(s) to remove
1179+
var model = new RemoveParametersModel(parseResult, qualifiedSelection, null);
1180+
1181+
//SetupFactory
1182+
var factory = SetupFactory(model);
1183+
1184+
//Act
1185+
var refactoring = new RemoveParametersRefactoring(factory.Object);
1186+
refactoring.Refactor(qualifiedSelection);
1187+
1188+
//Assert
1189+
Assert.AreEqual(inputCode, module.Lines());
11321190
}
11331191

11341192
[TestMethod]

0 commit comments

Comments
 (0)