@@ -676,7 +676,7 @@ Public Property Let Buz(ByVal a As Boolean, ByRef value As Integer)
676
676
const string inputCode2 =
677
677
@"Implements Class1" ;
678
678
679
- var selection = new Selection ( 1 , 1 , 1 , 1 ) ;
679
+ var selection = Selection . Home ;
680
680
681
681
//Expectation
682
682
const string expectedCode =
@@ -800,5 +800,82 @@ End Property
800
800
//Assert
801
801
Assert . AreEqual ( expectedCode , module . Content ( ) ) ;
802
802
}
803
+
804
+ [ TestMethod ]
805
+ public void ImplementsInterfaceInDocumentModule ( )
806
+ {
807
+ const string interfaceCode = @"Option Explicit
808
+ Public Sub DoSomething()
809
+ End Sub
810
+ " ;
811
+ const string initialCode = @"Implements IInterface" ;
812
+ const string expectedCode = @"Implements IInterface
813
+
814
+ Private Sub IInterface_DoSomething()
815
+ Err.Raise 5 'TODO implement interface member
816
+ End Sub
817
+ " ;
818
+ var selection = Selection . Home ;
819
+ var vbe = new MockVbeBuilder ( )
820
+ . ProjectBuilder ( "TestProject" , ProjectProtection . Unprotected )
821
+ . AddComponent ( "IInterface" , ComponentType . ClassModule , interfaceCode )
822
+ . AddComponent ( "Sheet1" , ComponentType . Document , initialCode , selection )
823
+ . MockVbeBuilder ( )
824
+ . Build ( ) ;
825
+
826
+ var project = vbe . Object . VBProjects [ 0 ] ;
827
+ var component = project . VBComponents [ "Sheet1" ] ;
828
+
829
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
830
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
831
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
832
+
833
+ var qualifiedSelection = new QualifiedSelection ( new QualifiedModuleName ( component ) , Selection . Home ) ;
834
+ var module = component . CodeModule ;
835
+
836
+ var refactoring = new ImplementInterfaceRefactoring ( vbe . Object , parser . State , null ) ;
837
+ refactoring . Refactor ( qualifiedSelection ) ;
838
+
839
+ Assert . AreEqual ( expectedCode , module . Content ( ) ) ;
840
+ }
841
+
842
+ [ TestMethod ]
843
+ public void ImplementsInterfaceInUserFormModule ( )
844
+ {
845
+ const string interfaceCode = @"Option Explicit
846
+ Public Sub DoSomething()
847
+ End Sub
848
+ " ;
849
+ const string initialCode = @"Implements IInterface" ;
850
+ const string expectedCode = @"Implements IInterface
851
+
852
+ Private Sub IInterface_DoSomething()
853
+ Err.Raise 5 'TODO implement interface member
854
+ End Sub
855
+ " ;
856
+ var selection = Selection . Home ;
857
+ var vbe = new MockVbeBuilder ( )
858
+ . ProjectBuilder ( "TestProject" , ProjectProtection . Unprotected )
859
+ . AddComponent ( "IInterface" , ComponentType . ClassModule , interfaceCode )
860
+ . AddComponent ( "Form1" , ComponentType . UserForm , initialCode , selection )
861
+ . MockVbeBuilder ( )
862
+ . Build ( ) ;
863
+
864
+ var project = vbe . Object . VBProjects [ 0 ] ;
865
+ var component = project . VBComponents [ "Form1" ] ;
866
+
867
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
868
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
869
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
870
+
871
+ var qualifiedSelection = new QualifiedSelection ( new QualifiedModuleName ( component ) , Selection . Home ) ;
872
+ var module = component . CodeModule ;
873
+
874
+ var refactoring = new ImplementInterfaceRefactoring ( vbe . Object , parser . State , null ) ;
875
+ refactoring . Refactor ( qualifiedSelection ) ;
876
+
877
+ Assert . AreEqual ( expectedCode , module . Content ( ) ) ;
878
+ }
803
879
}
804
880
}
881
+
0 commit comments