@@ -1131,6 +1131,178 @@ public void RemoveParams_RefactorDeclaration_FailsInvalidTarget()
11311131 }
11321132 }
11331133
1134+ [ TestMethod ]
1135+ public void Presenter_Accept_ReturnsModelWithParametersChanged ( )
1136+ {
1137+ //Input
1138+ const string inputCode =
1139+ @"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
1140+ End Sub" ;
1141+ var selection = new Selection ( 1 , 15 , 1 , 15 ) ; //startLine, startCol, endLine, endCol
1142+
1143+ //Arrange
1144+ var project = SetupMockProject ( inputCode ) ;
1145+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1146+
1147+ var qualifiedSelection = GetQualifiedSelection ( selection ) ;
1148+
1149+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1150+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( qualifiedSelection ) ;
1151+
1152+ var model = new RemoveParametersModel ( parseResult , qualifiedSelection , new RubberduckMessageBox ( ) ) ;
1153+ model . Parameters [ 1 ] . IsRemoved = true ;
1154+
1155+ var view = new Mock < IRemoveParametersView > ( ) ;
1156+ view . Setup ( v => v . ShowDialog ( ) ) . Returns ( DialogResult . OK ) ;
1157+ view . Setup ( v => v . Parameters ) . Returns ( model . Parameters ) ;
1158+
1159+ var factory = new RemoveParametersPresenterFactory ( editor . Object , view . Object ,
1160+ parseResult , null ) ;
1161+
1162+ var presenter = factory . Create ( ) ;
1163+
1164+ Assert . AreEqual ( model . Parameters , presenter . Show ( ) . Parameters ) ;
1165+ }
1166+
1167+ [ TestMethod ]
1168+ public void Presenter_Reject_ReturnsNull ( )
1169+ {
1170+ //Input
1171+ const string inputCode =
1172+ @"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
1173+ End Sub" ;
1174+ var selection = new Selection ( 1 , 15 , 1 , 15 ) ; //startLine, startCol, endLine, endCol
1175+
1176+ //Arrange
1177+ var project = SetupMockProject ( inputCode ) ;
1178+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1179+
1180+ var qualifiedSelection = GetQualifiedSelection ( selection ) ;
1181+
1182+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1183+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( qualifiedSelection ) ;
1184+
1185+ var model = new RemoveParametersModel ( parseResult , qualifiedSelection , new RubberduckMessageBox ( ) ) ;
1186+ model . Parameters [ 1 ] . IsRemoved = true ;
1187+
1188+ var view = new Mock < IRemoveParametersView > ( ) ;
1189+ view . Setup ( v => v . ShowDialog ( ) ) . Returns ( DialogResult . Cancel ) ;
1190+ view . Setup ( v => v . Parameters ) . Returns ( model . Parameters ) ;
1191+
1192+ var factory = new RemoveParametersPresenterFactory ( editor . Object , view . Object ,
1193+ parseResult , null ) ;
1194+
1195+ var presenter = factory . Create ( ) ;
1196+
1197+ Assert . AreEqual ( null , presenter . Show ( ) ) ;
1198+ }
1199+
1200+ [ TestMethod ]
1201+ public void Presenter_Accept_AutoMarksSingleParamAsRemoved ( )
1202+ {
1203+ //Input
1204+ const string inputCode =
1205+ @"Private Sub Foo(ByVal arg1 As Integer)
1206+ End Sub" ;
1207+ var selection = new Selection ( 1 , 15 , 1 , 15 ) ; //startLine, startCol, endLine, endCol
1208+
1209+ //Arrange
1210+ var project = SetupMockProject ( inputCode ) ;
1211+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1212+
1213+ var qualifiedSelection = GetQualifiedSelection ( selection ) ;
1214+
1215+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1216+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( qualifiedSelection ) ;
1217+
1218+ var model = new RemoveParametersModel ( parseResult , qualifiedSelection , new RubberduckMessageBox ( ) ) ;
1219+ model . Parameters [ 0 ] . IsRemoved = true ;
1220+
1221+ var factory = new RemoveParametersPresenterFactory ( editor . Object , null ,
1222+ parseResult , null ) ;
1223+
1224+ var presenter = factory . Create ( ) ;
1225+
1226+ Assert . IsTrue ( model . Parameters [ 0 ] . Declaration . Equals ( presenter . Show ( ) . Parameters [ 0 ] . Declaration ) ) ;
1227+ }
1228+
1229+ [ TestMethod ]
1230+ public void Presenter_NoParams ( )
1231+ {
1232+ //Input
1233+ const string inputCode =
1234+ @"Private Sub Foo()
1235+ End Sub" ;
1236+ var selection = new Selection ( 1 , 15 , 1 , 15 ) ; //startLine, startCol, endLine, endCol
1237+
1238+ //Arrange
1239+ var project = SetupMockProject ( inputCode ) ;
1240+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1241+
1242+ var qualifiedSelection = GetQualifiedSelection ( selection ) ;
1243+
1244+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1245+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( qualifiedSelection ) ;
1246+
1247+ var messageBox = new Mock < IMessageBox > ( ) ;
1248+ messageBox . Setup ( m => m . Show ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < MessageBoxButtons > ( ) , It . IsAny < MessageBoxIcon > ( ) ) ) . Returns ( DialogResult . OK ) ;
1249+
1250+ var factory = new RemoveParametersPresenterFactory ( editor . Object , null ,
1251+ parseResult , messageBox . Object ) ;
1252+
1253+ var presenter = factory . Create ( ) ;
1254+
1255+ Assert . AreEqual ( null , presenter . Show ( ) ) ;
1256+ }
1257+
1258+ [ TestMethod ]
1259+ public void Presenter_TargetIsNull ( )
1260+ {
1261+ //Input
1262+ const string inputCode =
1263+ @"
1264+ Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
1265+ End Sub" ;
1266+ var selection = new Selection ( 1 , 1 , 1 , 1 ) ; //startLine, startCol, endLine, endCol
1267+
1268+ //Arrange
1269+ var project = SetupMockProject ( inputCode ) ;
1270+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1271+
1272+ var qualifiedSelection = GetQualifiedSelection ( selection ) ;
1273+
1274+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1275+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( qualifiedSelection ) ;
1276+
1277+ var factory = new RemoveParametersPresenterFactory ( editor . Object , null ,
1278+ parseResult , null ) ;
1279+
1280+ var presenter = factory . Create ( ) ;
1281+
1282+ Assert . AreEqual ( null , presenter . Show ( ) ) ;
1283+ }
1284+
1285+ [ TestMethod ]
1286+ public void Factory_SelectionIsNull ( )
1287+ {
1288+ //Input
1289+ const string inputCode =
1290+ @"Private Sub Foo()
1291+ End Sub" ;
1292+
1293+ //Arrange
1294+ var project = SetupMockProject ( inputCode ) ;
1295+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1296+
1297+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1298+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( ( QualifiedSelection ? ) null ) ;
1299+
1300+ var factory = new RemoveParametersPresenterFactory ( editor . Object , null ,
1301+ parseResult , null ) ;
1302+
1303+ Assert . AreEqual ( null , factory . Create ( ) ) ;
1304+ }
1305+
11341306 #region setup
11351307 private static Mock < IRefactoringPresenterFactory < IRemoveParametersPresenter > > SetupFactory ( RemoveParametersModel model )
11361308 {
0 commit comments