@@ -864,48 +864,68 @@ Private Sub Foo()
864
864
[ Category ( "Refactorings" ) ]
865
865
public void MoveCloser_RespectsObjectProperties_InUsages ( )
866
866
{
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
+
868
893
869
894
Public Sub Test()
870
- Dim foo As Object
871
895
Debug.Print ""Some statements between""
872
896
Debug.Print ""Declaration and first usage!""
873
- Set foo = CreateObject(""Some.Object"")
897
+ Set foo = new Class1
874
898
foo.Name = ""FooName""
875
899
foo.OtherProperty = 1626
876
900
End Sub" ;
877
901
878
- const string expected = @"Option Explicit
902
+ var selection = new Selection ( 1 , 1 ) ;
879
903
880
- Public Sub Test()
904
+ const string expected = @" Public Sub Test()
881
905
Debug.Print ""Some statements between""
882
906
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
885
909
foo.Name = ""FooName""
886
910
foo.OtherProperty = 1626
887
911
End Sub" ;
888
912
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
+
891
923
using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
892
924
{
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
-
905
925
var messageBox = new Mock < IMessageBox > ( ) ;
906
926
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 ) ;
909
929
Assert . AreEqual ( expected , rewriter . GetText ( ) ) ;
910
930
}
911
931
}
0 commit comments