|
1 | 1 | using System.Collections.Generic;
|
2 | 2 | using System.Linq;
|
| 3 | +using System.Windows.Forms; |
3 | 4 | using System.Windows.Input;
|
4 | 5 | using Microsoft.Vbe.Interop;
|
5 | 6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
6 | 7 | using Moq;
|
7 | 8 | using Rubberduck.Navigation.CodeExplorer;
|
8 | 9 | using Rubberduck.Parsing.VBA;
|
9 | 10 | using Rubberduck.Settings;
|
| 11 | +using Rubberduck.UI; |
10 | 12 | using Rubberduck.UI.CodeExplorer.Commands;
|
11 | 13 | using Rubberduck.UnitTesting;
|
12 | 14 | using Rubberduck.VBEditor.VBEHost;
|
@@ -101,6 +103,39 @@ public void AddTestModule()
|
101 | 103 | Assert.IsTrue(vbComponents.Count(c => c.Type == vbext_ComponentType.vbext_ct_StdModule) == 2);
|
102 | 104 | }
|
103 | 105 |
|
| 106 | + [TestMethod] |
| 107 | + public void RemoveModule_Cancel() |
| 108 | + { |
| 109 | + var builder = new MockVbeBuilder(); |
| 110 | + var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) |
| 111 | + .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, "") |
| 112 | + .Build(); |
| 113 | + var vbe = builder.AddProject(project).Build(); |
| 114 | + |
| 115 | + var messageBox = new Mock<IMessageBox>(); |
| 116 | + messageBox.Setup(m => |
| 117 | + m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxButtons>(), |
| 118 | + It.IsAny<MessageBoxIcon>())).Returns(DialogResult.No); |
| 119 | + |
| 120 | + var commands = new List<ICommand> |
| 121 | + { |
| 122 | + new CodeExplorer_RemoveCommand(null, messageBox.Object) |
| 123 | + }; |
| 124 | + |
| 125 | + var state = new RubberduckParserState(); |
| 126 | + var vm = new CodeExplorerViewModel(state, commands); |
| 127 | + |
| 128 | + var parser = MockParser.Create(vbe.Object, state); |
| 129 | + parser.Parse(); |
| 130 | + if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } |
| 131 | + |
| 132 | + vm.SelectedItem = vm.Projects.First().Items.First().Items.First(); |
| 133 | + vm.RemoveCommand.Execute(vm.SelectedItem); |
| 134 | + |
| 135 | + var vbComponents = vbe.Object.VBProjects.Item(0).VBComponents.Cast<VBComponent>(); |
| 136 | + Assert.IsTrue(vbComponents.Count(c => c.Type == vbext_ComponentType.vbext_ct_StdModule) == 0); |
| 137 | + } |
| 138 | + |
104 | 139 | #region
|
105 | 140 | private Configuration GetDefaultUnitTestConfig()
|
106 | 141 | {
|
|
0 commit comments