Skip to content

Commit d2c284c

Browse files
committed
No-export remove test.
1 parent 119d31a commit d2c284c

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ private void ParserState_StateChanged(object sender, EventArgs e)
191191
.Where(grouping => grouping.Key != null)
192192
.ToList();
193193

194-
if (
195-
userDeclarations.Any(
194+
if (userDeclarations.Any(
196195
grouping => grouping.All(declaration => declaration.DeclarationType != DeclarationType.Project)))
197196
{
198197
return;

RubberduckTests/CodeExplorer/CodeExplorerTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using System.Windows.Forms;
34
using System.Windows.Input;
45
using Microsoft.Vbe.Interop;
56
using Microsoft.VisualStudio.TestTools.UnitTesting;
67
using Moq;
78
using Rubberduck.Navigation.CodeExplorer;
89
using Rubberduck.Parsing.VBA;
910
using Rubberduck.Settings;
11+
using Rubberduck.UI;
1012
using Rubberduck.UI.CodeExplorer.Commands;
1113
using Rubberduck.UnitTesting;
1214
using Rubberduck.VBEditor.VBEHost;
@@ -101,6 +103,39 @@ public void AddTestModule()
101103
Assert.IsTrue(vbComponents.Count(c => c.Type == vbext_ComponentType.vbext_ct_StdModule) == 2);
102104
}
103105

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+
104139
#region
105140
private Configuration GetDefaultUnitTestConfig()
106141
{

RubberduckTests/Mocks/MockProjectBuilder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ private Mock<VBComponents> CreateComponentsMock()
143143
_components.Add(CreateComponentMock("test", c, "", new Selection()).Object);
144144
});
145145

146+
result.Setup(m => m.Remove(It.IsAny<VBComponent>())).Callback((VBComponent c) =>
147+
{
148+
_components.Remove(c);
149+
});
150+
146151
return result;
147152
}
148153

0 commit comments

Comments
 (0)