@@ -1256,13 +1256,7 @@ Private Sub abc_Foo(ByVal arg2 As String, ByVal arg1 As Integer)
12561256
12571257 //Specify Params to remove
12581258 var model = new ReorderParametersModel ( parseResult , qualifiedSelection , null ) ;
1259- var reorderedParams = new List < Parameter > ( )
1260- {
1261- model . Parameters [ 1 ] ,
1262- model . Parameters [ 0 ]
1263- } ;
1264-
1265- model . Parameters = reorderedParams ;
1259+ model . Parameters . Reverse ( ) ;
12661260
12671261 //SetupFactory
12681262 var factory = SetupFactory ( model ) ;
@@ -1276,6 +1270,179 @@ Private Sub abc_Foo(ByVal arg2 As String, ByVal arg1 As Integer)
12761270 Assert . AreEqual ( expectedCode2 , module2 . Lines ( ) ) ;
12771271 }
12781272
1273+
1274+
1275+ [ TestMethod ]
1276+ public void Presenter_Accept_ReturnsModelWithParametersChanged ( )
1277+ {
1278+ //Input
1279+ const string inputCode =
1280+ @"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
1281+ End Sub" ;
1282+ var selection = new Selection ( 1 , 15 , 1 , 15 ) ; //startLine, startCol, endLine, endCol
1283+
1284+ //Arrange
1285+ var project = SetupMockProject ( inputCode ) ;
1286+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1287+
1288+ var qualifiedSelection = GetQualifiedSelection ( selection ) ;
1289+
1290+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1291+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( qualifiedSelection ) ;
1292+
1293+ var model = new ReorderParametersModel ( parseResult , qualifiedSelection , new RubberduckMessageBox ( ) ) ;
1294+ model . Parameters . Reverse ( ) ;
1295+
1296+ var view = new Mock < IReorderParametersView > ( ) ;
1297+ view . Setup ( v => v . ShowDialog ( ) ) . Returns ( DialogResult . OK ) ;
1298+ view . Setup ( v => v . Parameters ) . Returns ( model . Parameters ) ;
1299+
1300+ var factory = new ReorderParametersPresenterFactory ( editor . Object , view . Object ,
1301+ parseResult , null ) ;
1302+
1303+ var presenter = factory . Create ( ) ;
1304+
1305+ Assert . AreEqual ( model . Parameters , presenter . Show ( ) . Parameters ) ;
1306+ }
1307+
1308+ [ TestMethod ]
1309+ public void Presenter_Reject_ReturnsNull ( )
1310+ {
1311+ //Input
1312+ const string inputCode =
1313+ @"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
1314+ End Sub" ;
1315+ var selection = new Selection ( 1 , 15 , 1 , 15 ) ; //startLine, startCol, endLine, endCol
1316+
1317+ //Arrange
1318+ var project = SetupMockProject ( inputCode ) ;
1319+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1320+
1321+ var qualifiedSelection = GetQualifiedSelection ( selection ) ;
1322+
1323+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1324+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( qualifiedSelection ) ;
1325+
1326+ var model = new ReorderParametersModel ( parseResult , qualifiedSelection , new RubberduckMessageBox ( ) ) ;
1327+
1328+ var view = new Mock < IReorderParametersView > ( ) ;
1329+ view . Setup ( v => v . ShowDialog ( ) ) . Returns ( DialogResult . Cancel ) ;
1330+ view . Setup ( v => v . Parameters ) . Returns ( model . Parameters ) ;
1331+
1332+ var factory = new ReorderParametersPresenterFactory ( editor . Object , view . Object ,
1333+ parseResult , null ) ;
1334+
1335+ var presenter = factory . Create ( ) ;
1336+
1337+ Assert . AreEqual ( null , presenter . Show ( ) ) ;
1338+ }
1339+
1340+ [ TestMethod ]
1341+ public void Presenter_NoParams ( )
1342+ {
1343+ //Input
1344+ const string inputCode =
1345+ @"Private Sub Foo()
1346+ End Sub" ;
1347+ var selection = new Selection ( 1 , 15 , 1 , 15 ) ; //startLine, startCol, endLine, endCol
1348+
1349+ //Arrange
1350+ var project = SetupMockProject ( inputCode ) ;
1351+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1352+
1353+ var qualifiedSelection = GetQualifiedSelection ( selection ) ;
1354+
1355+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1356+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( qualifiedSelection ) ;
1357+
1358+ var messageBox = new Mock < IMessageBox > ( ) ;
1359+ messageBox . Setup ( m => m . Show ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < MessageBoxButtons > ( ) , It . IsAny < MessageBoxIcon > ( ) ) ) . Returns ( DialogResult . OK ) ;
1360+
1361+ var factory = new ReorderParametersPresenterFactory ( editor . Object , null ,
1362+ parseResult , messageBox . Object ) ;
1363+
1364+ var presenter = factory . Create ( ) ;
1365+
1366+ Assert . AreEqual ( null , presenter . Show ( ) ) ;
1367+ }
1368+
1369+ [ TestMethod ]
1370+ public void Presenter_OneParam ( )
1371+ {
1372+ //Input
1373+ const string inputCode =
1374+ @"Private Sub Foo(ByVal arg1 As Integer)
1375+ End Sub" ;
1376+ var selection = new Selection ( 1 , 15 , 1 , 15 ) ; //startLine, startCol, endLine, endCol
1377+
1378+ //Arrange
1379+ var project = SetupMockProject ( inputCode ) ;
1380+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1381+
1382+ var qualifiedSelection = GetQualifiedSelection ( selection ) ;
1383+
1384+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1385+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( qualifiedSelection ) ;
1386+
1387+ var messageBox = new Mock < IMessageBox > ( ) ;
1388+ messageBox . Setup ( m => m . Show ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < MessageBoxButtons > ( ) , It . IsAny < MessageBoxIcon > ( ) ) ) . Returns ( DialogResult . OK ) ;
1389+
1390+ var factory = new ReorderParametersPresenterFactory ( editor . Object , null ,
1391+ parseResult , messageBox . Object ) ;
1392+
1393+ var presenter = factory . Create ( ) ;
1394+
1395+ Assert . AreEqual ( null , presenter . Show ( ) ) ;
1396+ }
1397+
1398+ [ TestMethod ]
1399+ public void Presenter_TargetIsNull ( )
1400+ {
1401+ //Input
1402+ const string inputCode =
1403+ @"
1404+ Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
1405+ End Sub" ;
1406+ var selection = new Selection ( 1 , 1 , 1 , 1 ) ; //startLine, startCol, endLine, endCol
1407+
1408+ //Arrange
1409+ var project = SetupMockProject ( inputCode ) ;
1410+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1411+
1412+ var qualifiedSelection = GetQualifiedSelection ( selection ) ;
1413+
1414+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1415+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( qualifiedSelection ) ;
1416+
1417+ var factory = new ReorderParametersPresenterFactory ( editor . Object , null ,
1418+ parseResult , null ) ;
1419+
1420+ var presenter = factory . Create ( ) ;
1421+
1422+ Assert . AreEqual ( null , presenter . Show ( ) ) ;
1423+ }
1424+
1425+ [ TestMethod ]
1426+ public void Factory_SelectionIsNull ( )
1427+ {
1428+ //Input
1429+ const string inputCode =
1430+ @"Private Sub Foo()
1431+ End Sub" ;
1432+
1433+ //Arrange
1434+ var project = SetupMockProject ( inputCode ) ;
1435+ var parseResult = new RubberduckParser ( ) . Parse ( project . Object ) ;
1436+
1437+ var editor = new Mock < IActiveCodePaneEditor > ( ) ;
1438+ editor . Setup ( e => e . GetSelection ( ) ) . Returns ( ( QualifiedSelection ? ) null ) ;
1439+
1440+ var factory = new ReorderParametersPresenterFactory ( editor . Object , null ,
1441+ parseResult , null ) ;
1442+
1443+ Assert . AreEqual ( null , factory . Create ( ) ) ;
1444+ }
1445+
12791446 #region setup
12801447 private static Mock < IRefactoringPresenterFactory < IReorderParametersPresenter > > SetupFactory ( ReorderParametersModel model )
12811448 {
0 commit comments