Skip to content

Commit 31c017e

Browse files
committed
Fixed tests, moved commandbar locations to AddIn
1 parent 5229b77 commit 31c017e

File tree

11 files changed

+86
-48
lines changed

11 files changed

+86
-48
lines changed

Rubberduck.Main/Root/RubberduckIoCInstaller.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private void RegisterParseTreeInspections(IWindsorContainer container, Assembly[
314314

315315
private void RegisterRubberduckMenu(IWindsorContainer container)
316316
{
317-
var location = _vbe.CommandBarLocations[CommandBarSite.MenuBar];
317+
var location = _addin.CommandBarLocations[CommandBarSite.MenuBar];
318318
var controls = MainCommandBarControls(location.ParentId);
319319
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, location.BeforeControlId);
320320
var menuItemTypes = RubberduckMenuItems();
@@ -380,7 +380,7 @@ private ICommandBarControls MainCommandBarControls(int commandBarIndex)
380380

381381
private void RegisterCodePaneContextMenu(IWindsorContainer container)
382382
{
383-
var location = _vbe.CommandBarLocations[CommandBarSite.CodeWindow];
383+
var location = _addin.CommandBarLocations[CommandBarSite.CodeWindow];
384384
var controls = MainCommandBarControls(location.ParentId);
385385
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, location.BeforeControlId);
386386
var menuItemTypes = CodePaneContextMenuItems();
@@ -401,7 +401,7 @@ private Type[] CodePaneContextMenuItems()
401401

402402
private void RegisterFormDesignerContextMenu(IWindsorContainer container)
403403
{
404-
var location = _vbe.CommandBarLocations[CommandBarSite.MsForms];
404+
var location = _addin.CommandBarLocations[CommandBarSite.MsForms];
405405
var controls = MainCommandBarControls(location.ParentId);
406406
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, location.BeforeControlId);
407407
var menuItemTypes = FormDesignerContextMenuItems();
@@ -419,7 +419,7 @@ private Type[] FormDesignerContextMenuItems()
419419

420420
private void RegisterFormDesignerControlContextMenu(IWindsorContainer container)
421421
{
422-
var location = _vbe.CommandBarLocations[CommandBarSite.MsFormsControl];
422+
var location = _addin.CommandBarLocations[CommandBarSite.MsFormsControl];
423423
var controls = MainCommandBarControls(location.ParentId);
424424
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, location.BeforeControlId);
425425
var menuItemTypes = FormDesignerContextMenuItems();
@@ -428,7 +428,7 @@ private void RegisterFormDesignerControlContextMenu(IWindsorContainer container)
428428

429429
private void RegisterProjectExplorerContextMenu(IWindsorContainer container)
430430
{
431-
var location = _vbe.CommandBarLocations[CommandBarSite.ProjectExplorer];
431+
var location = _addin.CommandBarLocations[CommandBarSite.ProjectExplorer];
432432
var controls = MainCommandBarControls(location.ParentId);
433433
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, location.BeforeControlId);
434434
var menuItemTypes = ProjectWindowContextMenuItems();

Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract/IAddIn.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using Rubberduck.VBEditor.Host;
24

35
namespace Rubberduck.VBEditor.SafeComWrappers.Abstract
46
{
@@ -12,5 +14,6 @@ public interface IAddIn : ISafeComWrapper, IEquatable<IAddIn>
1214

1315
IVBE VBE { get; }
1416
IAddIns Collection { get; }
17+
IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
1518
}
1619
}

Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract/IVBE.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Rubberduck.VBEditor.Host;
21
using System;
3-
using System.Collections.Generic;
42

53
namespace Rubberduck.VBEditor.SafeComWrappers.Abstract
64
{
@@ -22,7 +20,6 @@ public interface IVBE : ISafeComWrapper, IEquatable<IVBE>
2220
IWindows Windows { get; }
2321
IHostApplication HostApplication();
2422
IWindow ActiveMDIChild();
25-
IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
2623
QualifiedSelection? GetActiveSelection();
2724

2825
bool IsInDesignMode { get; }

Rubberduck.VBEditor.VB6/SafeComWrappers/VB/AddIn.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using Rubberduck.VBEditor.Host;
4+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
25
using VB = Microsoft.Vbe.Interop.VB6;
36

47
// ReSharper disable once CheckNamespace - Special dispensation due to conflicting file vs namespace priorities
@@ -9,8 +12,18 @@ public class AddIn : SafeComWrapper<VB.AddIn>, IAddIn
912
public AddIn(VB.AddIn target, bool rewrapping = false)
1013
: base(target, rewrapping)
1114
{
15+
CommandBarLocations = new ReadOnlyDictionary<CommandBarSite, CommandBarLocation>(new Dictionary<CommandBarSite, CommandBarLocation>
16+
{
17+
{CommandBarSite.MenuBar, new CommandBarLocation(1, 30009)},
18+
{CommandBarSite.CodeWindow, new CommandBarLocation(15, 2529)},
19+
{CommandBarSite.ProjectExplorer, new CommandBarLocation(22, 2578)},
20+
{CommandBarSite.MsForms, new CommandBarLocation(20, 746)},
21+
{CommandBarSite.MsFormsControl, new CommandBarLocation(21, 2558)}
22+
});
1223
}
1324

25+
public IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
26+
1427
public string ProgId => IsWrappingNullReference ? string.Empty : Target.ProgId;
1528

1629
public string Guid => IsWrappingNullReference ? string.Empty : Target.Guid;

Rubberduck.VBEditor.VB6/SafeComWrappers/VB/VBE.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Collections.ObjectModel;
42
using System.Linq;
53
using System.Runtime.InteropServices;
64
using System.Text;
7-
using Rubberduck.VBEditor.Host;
85
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
96
using Rubberduck.VBEditor.SafeComWrappers.Office8;
107
using Rubberduck.VBEditor.VB6;
@@ -20,20 +17,11 @@ public VBE(VB.VBE target, bool rewrapping = false)
2017
: base(target, rewrapping)
2118
{
2219
SourceCodeHandler = new SourceCodeHandler();
23-
CommandBarLocations = new ReadOnlyDictionary<CommandBarSite, CommandBarLocation>(new Dictionary<CommandBarSite, CommandBarLocation>
24-
{
25-
{CommandBarSite.MenuBar, new CommandBarLocation(1, 30009)},
26-
{CommandBarSite.CodeWindow, new CommandBarLocation(15, 2529)},
27-
{CommandBarSite.ProjectExplorer, new CommandBarLocation(22, 2578)},
28-
{CommandBarSite.MsForms, new CommandBarLocation(20, 746)},
29-
{CommandBarSite.MsFormsControl, new CommandBarLocation(21, 2558)}
30-
});
3120
}
3221

3322
public VBEKind Kind => VBEKind.Standalone;
3423
public object HardReference => Target;
3524
public ISourceCodeHandler SourceCodeHandler { get; }
36-
public IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
3725

3826
public string Version => IsWrappingNullReference ? string.Empty : Target.Version;
3927

Rubberduck.VBEditor.VBA/SafeComWrappers/VB/AddIn.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using Rubberduck.VBEditor.Host;
4+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
25
using VB = Microsoft.Vbe.Interop;
36

47
// ReSharper disable once CheckNamespace - Special dispensation due to conflicting file vs namespace priorities
@@ -9,8 +12,20 @@ public class AddIn : SafeComWrapper<VB.AddIn>, IAddIn
912
public AddIn(VB.AddIn target, bool rewrapping = false)
1013
: base(target, rewrapping)
1114
{
15+
CommandBarLocations = new ReadOnlyDictionary<CommandBarSite, CommandBarLocation>(new Dictionary<CommandBarSite, CommandBarLocation>
16+
{
17+
{CommandBarSite.MenuBar, new CommandBarLocation(1, 30009)},
18+
{CommandBarSite.CodeWindow, new CommandBarLocation(9, 2529)},
19+
{CommandBarSite.ProjectExplorer, new CommandBarLocation(14, 2578)},
20+
{CommandBarSite.MsForms, new CommandBarLocation(17, 2558)},
21+
{CommandBarSite.MsFormsControl, new CommandBarLocation(18, 2558)}
22+
});
23+
1224
}
1325

26+
27+
public IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
28+
1429
public string ProgId => IsWrappingNullReference ? string.Empty : Target.ProgId;
1530

1631
public string Guid => IsWrappingNullReference ? string.Empty : Target.Guid;

Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBE.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Collections.ObjectModel;
43
using System.IO;
54
using System.Linq;
65
using System.Runtime.InteropServices;
76
using System.Text;
8-
using Rubberduck.VBEditor.Host;
97
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
108
using Rubberduck.VBEditor.SafeComWrappers.Office12;
119
using Rubberduck.VBEditor.VBA;
@@ -21,21 +19,11 @@ public VBE(VB.VBE target, bool rewrapping = false)
2119
: base(target, rewrapping)
2220
{
2321
SourceCodeHandler = new SourceCodeHandler();
24-
CommandBarLocations = new ReadOnlyDictionary<CommandBarSite, CommandBarLocation>(new Dictionary<CommandBarSite, CommandBarLocation>
25-
{
26-
{CommandBarSite.MenuBar, new CommandBarLocation(1, 30009)},
27-
{CommandBarSite.CodeWindow, new CommandBarLocation(9, 2529)},
28-
{CommandBarSite.ProjectExplorer, new CommandBarLocation(14, 2578)},
29-
{CommandBarSite.MsForms, new CommandBarLocation(17, 2558)},
30-
{CommandBarSite.MsFormsControl, new CommandBarLocation(18, 2558)}
31-
});
32-
3322
}
3423

3524
public VBEKind Kind => VBEKind.Hosted;
3625
public object HardReference => Target;
3726
public ISourceCodeHandler SourceCodeHandler { get; }
38-
public IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
3927

4028
public string Version => IsWrappingNullReference ? string.Empty : Target.Version;
4129

RubberduckTests/IoCContainer/IoCRegistrationTests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
23
using Castle.Windsor;
34
using NUnit.Framework;
45
using Moq;
56
using Rubberduck.Settings;
67
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
78
using Rubberduck.Root;
89
using Rubberduck.UI;
10+
using Rubberduck.VBEditor.Host;
911
using RubberduckTests.Mocks;
1012

1113
namespace RubberduckTests.IoCContainer
@@ -18,8 +20,9 @@ public class IoCRegistrationTests
1820
public void RegistrationOfRubberduckIoCContainerWithSC_NoException()
1921
{
2022
var vbeBuilder = new MockVbeBuilder();
21-
var ide = vbeBuilder.Build().Object;
22-
var addin = new Mock<IAddIn>().Object;
23+
var addInBuilder = new MockAddInBuilder();
24+
var ide = vbeBuilder.Build().Object;
25+
var addin = addInBuilder.Build().Object;
2326
var initialSettings = new GeneralSettings
2427
{
2528
EnableExperimentalFeatures = new List<ExperimentalFeatures>
@@ -41,8 +44,9 @@ public void RegistrationOfRubberduckIoCContainerWithSC_NoException()
4144
public void RegistrationOfRubberduckIoCContainerWithoutSC_NoException()
4245
{
4346
var vbeBuilder = new MockVbeBuilder();
47+
var addInBuilder = new MockAddInBuilder();
4448
var ide = vbeBuilder.Build().Object;
45-
var addin = new Mock<IAddIn>().Object;
49+
var addin = addInBuilder.Build().Object;
4650
var initialSettings = new GeneralSettings {EnableExperimentalFeatures = new List<ExperimentalFeatures>()};
4751

4852
using (var container =
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using Moq;
4+
using Rubberduck.VBEditor.Host;
5+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
6+
7+
namespace RubberduckTests.Mocks
8+
{
9+
public class MockAddInBuilder
10+
{
11+
private readonly Mock<IAddIn> _addIn;
12+
13+
public MockAddInBuilder()
14+
{
15+
_addIn = CreateAddInMock();
16+
}
17+
18+
private Mock<IAddIn> CreateAddInMock()
19+
{
20+
var addIn = new Mock<IAddIn>();
21+
22+
addIn.Setup(a => a.CommandBarLocations).Returns(new ReadOnlyDictionary<CommandBarSite, CommandBarLocation>(new Dictionary<CommandBarSite, CommandBarLocation>
23+
{
24+
{CommandBarSite.MenuBar, new CommandBarLocation(1, 1)},
25+
{CommandBarSite.CodeWindow, new CommandBarLocation(2, 2)},
26+
{CommandBarSite.ProjectExplorer, new CommandBarLocation(3, 3)},
27+
{CommandBarSite.MsForms, new CommandBarLocation(4, 4)},
28+
{CommandBarSite.MsFormsControl, new CommandBarLocation(5, 5)}
29+
}));
30+
31+
return addIn;
32+
}
33+
34+
public Mock<IAddIn> Build()
35+
{
36+
return _addIn;
37+
}
38+
}
39+
}

RubberduckTests/Mocks/MockVbeBuilder.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ public class MockVbeBuilder
6060
private Mock<ICodePanes> _vbCodePanes;
6161
private readonly ICollection<ICodePane> _codePanes = new List<ICodePane>();
6262

63-
private const int MenuBar = 1;
64-
private const int CodeWindow = 9;
65-
private const int ProjectWindow = 14;
66-
private const int MsForms = 17;
67-
private const int MsFormsControl = 18;
68-
6963
public MockVbeBuilder()
7064
{
7165
_vbe = CreateVbeMock();
@@ -232,11 +226,7 @@ private static ICommandBars DummyCommandBars()
232226

233227
var dummyCommandBar = DummyCommandBar();
234228

235-
commandBars.SetupGet(m => m[MenuBar]).Returns(dummyCommandBar);
236-
commandBars.SetupGet(m => m[CodeWindow]).Returns(dummyCommandBar);
237-
commandBars.SetupGet(m => m[ProjectWindow]).Returns(dummyCommandBar);
238-
commandBars.SetupGet(m => m[MsForms]).Returns(dummyCommandBar);
239-
commandBars.SetupGet(m => m[MsFormsControl]).Returns(dummyCommandBar);
229+
commandBars.SetupGet(m => m[It.IsAny<int>()]).Returns(dummyCommandBar);
240230

241231
return commandBars.Object;
242232
}

0 commit comments

Comments
 (0)