Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="Mock{VBE}"/> that returns the <see cref="Windows"/> collection argument out of the Windows property.
        /// </summary>
        /// <param name="windows">
        /// A <see cref="MockWindowsCollection"/> is expected. 
        /// Other objects implementing the<see cref="Windows"/> interface could cause issues.
        /// </param>
        /// <returns></returns>
        internal static Mock<VBE> CreateVbeMock(MockWindowsCollection windows)
        {
            var vbe = new Mock<VBE>();
            windows.VBE = vbe.Object;
            vbe.Setup(m => m.Windows).Returns(windows);
            vbe.SetupProperty(m => m.ActiveCodePane);
            vbe.SetupProperty(m => m.ActiveVBProject);
            vbe.SetupGet(m => m.SelectedVBComponent).Returns(() => vbe.Object.ActiveCodePane.CodeModule.Parent);
            vbe.SetupGet(m => m.ActiveWindow).Returns(() => vbe.Object.ActiveCodePane.Window);

            //setting up a main window lets the native window functions fun
            var mainWindow = new Mock<Window>();
            mainWindow.Setup(m => m.HWnd).Returns(0);

            vbe.SetupGet(m => m.MainWindow).Returns(mainWindow.Object);

            return vbe;
        }
Ejemplo n.º 2
0
        private Mock<VBE> CreateVbeMock()
        {
            var vbe = new Mock<VBE>();
            var windows = new MockWindowsCollection {VBE = vbe.Object};
            vbe.Setup(m => m.Windows).Returns(() => windows);
            vbe.SetupProperty(m => m.ActiveCodePane);
            vbe.SetupProperty(m => m.ActiveVBProject);
            
            vbe.SetupGet(m => m.SelectedVBComponent).Returns(() => vbe.Object.ActiveCodePane.CodeModule.Parent);
            vbe.SetupGet(m => m.ActiveWindow).Returns(() => vbe.Object.ActiveCodePane.Window);

            var mainWindow = new Mock<Window>();
            mainWindow.Setup(m => m.HWnd).Returns(0);

            vbe.SetupGet(m => m.MainWindow).Returns(() => mainWindow.Object);

            _vbProjects = CreateProjectsMock();
            vbe.SetupGet(m => m.VBProjects).Returns(() => _vbProjects.Object);

            _vbCodePanes = CreateCodePanesMock();
            vbe.SetupGet(m => m.CodePanes).Returns(() => _vbCodePanes.Object);

            return vbe;
        }