Skip to content

Commit c6f1514

Browse files
authored
Update MoveCloserToUsageTests.cs
replacing test as per comments
1 parent f767104 commit c6f1514

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

RubberduckTests/Refactoring/MoveCloserToUsageTests.cs

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -864,48 +864,68 @@ Private Sub Foo()
864864
[Category("Refactorings")]
865865
public void MoveCloser_RespectsObjectProperties_InUsages()
866866
{
867-
const string input = @"Option Explicit
867+
string inputClassCode =
868+
@"
869+
Option Explicit
870+
871+
Private _name As Long
872+
Private _myOtherProperty As Long
873+
874+
Public Property Set Name(name As String)
875+
_name = name
876+
End Property
877+
878+
Public Property Get Name() As String
879+
Name = _name
880+
End Property
881+
882+
Public Property Set OtherProperty(val As Long)
883+
_myOtherProperty = val
884+
End Property
885+
886+
Public Property Get OtherProperty() As Long
887+
OtherProperty = _myOtherProperty
888+
End Property
889+
890+
";
891+
string inputCode = @"Private foo As Class1
892+
868893
869894
Public Sub Test()
870-
Dim foo As Object
871895
Debug.Print ""Some statements between""
872896
Debug.Print ""Declaration and first usage!""
873-
Set foo = CreateObject(""Some.Object"")
897+
Set foo = new Class1
874898
foo.Name = ""FooName""
875899
foo.OtherProperty = 1626
876900
End Sub";
877901

878-
const string expected = @"Option Explicit
902+
var selection = new Selection(1, 1);
879903

880-
Public Sub Test()
904+
const string expected = @"Public Sub Test()
881905
Debug.Print ""Some statements between""
882906
Debug.Print ""Declaration and first usage!""
883-
Dim foo As Object
884-
Set foo = CreateObject(""Some.Object"")
907+
Dim foo As Class1
908+
Set foo = new Class1
885909
foo.Name = ""FooName""
886910
foo.OtherProperty = 1626
887911
End Sub";
888912

889-
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(input, out var component, referenceStdLibs: true);
890-
913+
var builder = new MockVbeBuilder();
914+
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected);
915+
project.AddComponent("Class1", ComponentType.ClassModule, inputClassCode);
916+
project.AddComponent("Module1", ComponentType.StandardModule, inputCode);
917+
builder = builder.AddProject(project.Build());
918+
var vbe = builder.Build();
919+
920+
var testComponent = project.MockComponents.Find(mc => mc.Object.Name.Equals("Module1"));
921+
var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(testComponent.Object), selection);
922+
891923
using (var state = MockParser.CreateAndParse(vbe.Object))
892924
{
893-
// temp: get AppVeyor to spill its beans
894-
var i = 0;
895-
foreach(var d in state.AllUserDeclarations)
896-
{
897-
TestContext.Out.WriteLine($"({i++}): {d.QualifiedName.MemberName}");
898-
TestContext.Out.WriteLine($" DeclarationType: {System.Enum.GetName(d.DeclarationType.GetType(), d.DeclarationType)}");
899-
TestContext.Out.WriteLine($" Scope: {d.Scope}");
900-
TestContext.Out.WriteLine($" Selection: {d.Selection}");
901-
TestContext.Out.WriteLine($" AsTypeName: {d.AsTypeName}");
902-
TestContext.Out.WriteLine("");
903-
}
904-
905925
var messageBox = new Mock<IMessageBox>();
906926
var refactoring = new MoveCloserToUsageRefactoring(vbe.Object, state, messageBox.Object);
907-
refactoring.Refactor(state.AllUserDeclarations.Single(d => d.DeclarationType == DeclarationType.Variable));
908-
var rewriter = state.GetRewriter(component);
927+
refactoring.Refactor(qualifiedSelection);
928+
var rewriter = state.GetRewriter(testComponent.Object);
909929
Assert.AreEqual(expected, rewriter.GetText());
910930
}
911931
}

0 commit comments

Comments
 (0)