|
1 | 1 | using System.Collections.Generic; |
| 2 | +using System.Linq; |
2 | 3 | using System.Windows.Forms; |
3 | 4 | using Microsoft.Vbe.Interop; |
4 | 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
@@ -949,6 +950,52 @@ public void Factory_SelectionIsNotNull_PassInTarget_Reject() |
949 | 950 | Assert.AreEqual(null, presenter.Show(model.Target)); |
950 | 951 | } |
951 | 952 |
|
| 953 | + [TestMethod] |
| 954 | + public void RenameRefactoring_RenameProject() |
| 955 | + { |
| 956 | + const string newName = "RenameProject"; |
| 957 | + |
| 958 | + //Input |
| 959 | + const string inputCode = |
| 960 | +@"Private Sub Foo(ByVal a As Integer, ByVal b As String) |
| 961 | +End Sub"; |
| 962 | + |
| 963 | + var selection = new Selection(3, 27, 3, 27); //startLine, startCol, endLine, endCol |
| 964 | + |
| 965 | + //Arrange |
| 966 | + var component = CreateMockComponent(inputCode, "Class1", |
| 967 | + vbext_ComponentType.vbext_ct_ClassModule); |
| 968 | + |
| 969 | + var vbe = MockFactory.CreateVbeMock(); |
| 970 | + var project = CreateMockProject("VBAProject", vbext_ProjectProtection.vbext_pp_none, |
| 971 | + new List<Mock<VBComponent>>() { component }); |
| 972 | + var projects = MockFactory.CreateProjectsMock(new List<VBProject>() { project.Object }); |
| 973 | + |
| 974 | + vbe.Setup(v => v.VBProjects).Returns(projects.Object); |
| 975 | + var codePaneFactory = new RubberduckCodePaneFactory(); |
| 976 | + var parseResult = new RubberduckParser(codePaneFactory).Parse(project.Object); |
| 977 | + |
| 978 | + var qualifiedSelection = GetQualifiedSelection(selection); |
| 979 | + |
| 980 | + var messageBox = new Mock<IMessageBox>(); |
| 981 | + messageBox.Setup( |
| 982 | + m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxButtons>(), It.IsAny<MessageBoxIcon>())) |
| 983 | + .Returns(DialogResult.Yes); |
| 984 | + |
| 985 | + var model = new RenameModel(vbe.Object, parseResult, qualifiedSelection, messageBox.Object) { NewName = newName }; |
| 986 | + model.Target = model.Declarations.Items.First(i => i.DeclarationType == DeclarationType.Project && !i.IsBuiltIn); |
| 987 | + |
| 988 | + //SetupFactory |
| 989 | + var factory = SetupFactory(model); |
| 990 | + |
| 991 | + //Act |
| 992 | + var refactoring = new RenameRefactoring(factory.Object); |
| 993 | + refactoring.Refactor(model.Target); |
| 994 | + |
| 995 | + //Assert |
| 996 | + Assert.AreSame(newName, project.Object.Name); |
| 997 | + } |
| 998 | + |
952 | 999 | #region setup |
953 | 1000 | private static Mock<IRefactoringPresenterFactory<IRenamePresenter>> SetupFactory(RenameModel model) |
954 | 1001 | { |
|
0 commit comments