public void VsWhidbey604087()
        {
            // Make sure that an exception during a flush doesn't crash
            //   VS.

            //Prepare
            const string basePath = "c:\\temp\\Fake\\";

            ServiceProviderMock spMock = new ServiceProviderMock();

            spMock.Fake_AddUiServiceFake();
            Mock <IComponentChangeService> componentChangeServiceMock = new Mock <IComponentChangeService>();

            componentChangeServiceMock.Implement("add_ComponentChanged",
                                                 new object[] { MockConstraint.IsAnything <ComponentChangedEventHandler>() });
            componentChangeServiceMock.Implement("add_ComponentRename",
                                                 new object[] { MockConstraint.IsAnything <ComponentRenameEventHandler>() });
            componentChangeServiceMock.Implement("add_ComponentRemoved",
                                                 new object[] { MockConstraint.IsAnything <ComponentEventHandler>() });
            componentChangeServiceMock.Implement("add_ComponentAdded",
                                                 new object[] { MockConstraint.IsAnything <ComponentEventHandler>() });
            spMock.Fake_AddService(typeof(IComponentChangeService), componentChangeServiceMock.Instance);
            Mock <IVsHierarchy> hierarchyMock = new Mock <IVsHierarchy>(typeof(IVsProject));

            hierarchyMock.Implement(new MethodId(typeof(IVsProject), "GetItemContext"),
                                    new object[] { (uint)VSITEMID.ROOT, MockConstraint.IsAnything <Microsoft.VisualStudio.OLE.Interop.IServiceProvider>() },
                                    new object[] { (uint)0, null },
                                    VSConstants.E_FAIL);
            spMock.Fake_AddService(typeof(IVsHierarchy), hierarchyMock.Instance);

            ResourceEditorRootComponent rootComponent = new ResourceEditorRootComponent();

            Mock <ResourceFile> resourceFileMock = new Mock <ResourceFile>();

            resourceFileMock.SetCreateArguments(new object[] { null, rootComponent, spMock.Instance, basePath });
            SequenceMock <ResourceEditorDesignerLoader> designerLoaderMock = new SequenceMock <ResourceEditorDesignerLoader>();
            ResourceEditorViewMock view = new ResourceEditorViewMock(spMock.Instance);

            view.Fake_designerLoader = designerLoaderMock.Instance;
            resourceFileMock.Implement("get_View", view);
            Dictionary <string, object> styles = new Dictionary <string, object>();

            //Make The RunSingleFileGenerator call throw an exception, and make sure we don't
            //  blow up because of it.
            designerLoaderMock.AddExpectation("RunSingleFileGenerator",
                                              new object[] { true },
                                              new Exception("Whoops"));

            //Run test
            Microsoft_VisualStudio_Editors_ResourceEditor_ResourceFileAccessor accessor = new Microsoft_VisualStudio_Editors_ResourceEditor_ResourceFileAccessor(resourceFileMock.Instance);

            accessor.DelayFlushAndRunCustomToolImpl();

            //Verify
            Assert.AreEqual("Whoops", view.FakeResult_DSMsgBoxWasCalledWithThisString);
            designerLoaderMock.Verify();
        }
        public static IServiceProvider CreateServiceProviderWithIVSMDCodeDomProvider(CodeDomProvider codeProvider)
        {
            Mock <IVSMDCodeDomProvider> vsmdCodeDomProviderMock = new Mock <IVSMDCodeDomProvider>();

            vsmdCodeDomProviderMock.Implement("get_CodeDomProvider", codeProvider);

            ServiceProviderMock spMock = new ServiceProviderMock();

            if (codeProvider != null)
            {
                spMock.Fake_AddService(typeof(IVSMDCodeDomProvider), vsmdCodeDomProviderMock.Instance);
            }
            else
            {
                spMock.Fake_AddService(typeof(IVSMDCodeDomProvider), null);
            }

            return(spMock.Instance);
        }
예제 #3
0
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        #region "Utilities"

        public void TestGetCurrentValue(string expectedCurrentValue, object customToolValue, bool supportCustomToolValueInProject, CodeDomProvider codeProvider)
        {
            SD.SettingsDesigner designer = new SD.SettingsDesigner();
            ProjectItemFake     projectItem;

            if (supportCustomToolValueInProject)
            {
                projectItem = new ProjectItemWithCustomToolFake(customToolValue);
            }
            else
            {
                projectItem = new ProjectItemFake();
            }

            Mock <IVSMDCodeDomProvider> vsmdCodeDomProviderMock = new Mock <IVSMDCodeDomProvider>();

            vsmdCodeDomProviderMock.Implement("get_CodeDomProvider", codeProvider);

            ServiceProviderMock spMock = new ServiceProviderMock();

            if (codeProvider != null)
            {
                spMock.Fake_AddService(typeof(IVSMDCodeDomProvider), vsmdCodeDomProviderMock.Instance);
            }
            else
            {
                spMock.Fake_AddService(typeof(IVSMDCodeDomProvider), null);
            }

            SD.SettingsDesignerView.SettingsDesignerAccessModifierCombobox combo =
                new SD.SettingsDesignerView.SettingsDesignerAccessModifierCombobox(
                    designer,
                    spMock.Instance,
                    projectItem,
                    codeProvider is VBCodeProvider ? "My" : null);
            Microsoft_VisualStudio_Editors_DesignerFramework_AccessModifierComboboxAccessor accessor =
                new Microsoft_VisualStudio_Editors_DesignerFramework_AccessModifierComboboxAccessor(combo);

            Assert.AreEqual(expectedCurrentValue, accessor.GetCurrentValue());
        }
예제 #4
0
        static void TestSetCurrentValue(CodeDomProvider codeProvider, string initialCustomTool, string initialNamespace, string newCurrentValue, string expectedCustomTool, string expectedNamespace)
        {
            SD.SettingsDesigner designer = new SD.SettingsDesigner();
            ProjectItemFake     projectItem;

            projectItem = new ProjectItemWithCustomToolFake(initialCustomTool, initialNamespace);

            Mock <IVSMDCodeDomProvider> vsmdCodeDomProviderMock = new Mock <IVSMDCodeDomProvider>();

            vsmdCodeDomProviderMock.Implement("get_CodeDomProvider", codeProvider);

            ServiceProviderMock spMock = new ServiceProviderMock();

            if (codeProvider != null)
            {
                spMock.Fake_AddService(typeof(IVSMDCodeDomProvider), vsmdCodeDomProviderMock.Instance);
            }
            else
            {
                spMock.Fake_AddService(typeof(IVSMDCodeDomProvider), null);
            }

            SD.SettingsDesignerView.SettingsDesignerAccessModifierCombobox combo =
                new SD.SettingsDesignerView.SettingsDesignerAccessModifierCombobox(
                    designer,
                    spMock.Instance,
                    projectItem,
                    codeProvider is VBCodeProvider ? "My" : null);
            Microsoft_VisualStudio_Editors_DesignerFramework_AccessModifierComboboxAccessor accessor =
                new Microsoft_VisualStudio_Editors_DesignerFramework_AccessModifierComboboxAccessor(combo);

            // Call the method under test
            accessor.SetCurrentValue(newCurrentValue);

            // Verify results
            Assert.AreEqual(expectedCustomTool, projectItem.Fake_PropertiesCollection.Item("CustomTool").Value);
            Assert.AreEqual(expectedNamespace, projectItem.Fake_PropertiesCollection.Item("CustomToolNamespace").Value);
        }
예제 #5
0
        public PropertyPageSiteFake(IPropertyPageSiteOwner view, OleInterop.IPropertyPage page) : base(view, page)
        {
            Fake_serviceProviderMock.Fake_AddService(typeof(OLEInterop.IServiceProvider), this);
            Fake_serviceProviderMock.Fake_AddService(typeof(OLEInterop.IPropertyPageSite), (OLEInterop.IPropertyPageSite) this);
            Fake_serviceProviderMock.Fake_AddService(typeof(IUIService), Fake_uiService);
            Fake_serviceProviderMock.Fake_AddService(typeof(IVsMonitorSelection), Fake_vsMonitorSelection);
            Fake_serviceProviderMock.Fake_AddService(typeof(ObjectExtenders), Fake_objectExtenders);
            Fake_serviceProviderMock.Fake_AddService(typeof(SVsQueryEditQuerySave), Fake_vsQueryEditQuerySave2);

            base.BackingServiceProvider = Fake_serviceProviderMock.Instance;
        }
        public void CreateDesignerWhenPropertyPageInfoTryLoadPropertyPageFailsSoSiteIsNothing_DevDivBugs17865()
        {
            SequenceMock <IVsWindowFrame> outerWindowFrameMock = new SequenceMock <IVsWindowFrame>(typeof(IVsWindowFrame2));
            SequenceMock <IVsWindowFrame> innerWindowFrameMock = new SequenceMock <IVsWindowFrame>(typeof(IVsWindowFrame2));

            Control parentControl = new Control();

            parentControl.Size = new Size(10, 10);
            ServiceProviderMock spMock = new ServiceProviderMock();

            spMock.Fake_AddService(typeof(IVsWindowFrame), outerWindowFrameMock.Instance);
            UIShellService2FakeWithColors shellServiceFake = new UIShellService2FakeWithColors();

            spMock.Fake_AddService(typeof(IVsUIShell), shellServiceFake);
            VsShellFake shellFake = new VsShellFake();

            spMock.Fake_AddService(typeof(IVsShell), shellFake);
            UIServiceFake uiServiceFake = new UIServiceFake();

            spMock.Fake_AddService(typeof(IUIService), uiServiceFake);
            SequenceMock <IVsUIShellOpenDocument> uiShellOpenDocumentMock = new SequenceMock <IVsUIShellOpenDocument>();

            spMock.Fake_AddService(typeof(IVsUIShellOpenDocument), uiShellOpenDocumentMock.Instance);
            Mock <OLE.Interop.IServiceProvider> oleServiceProviderMock = new Mock <Microsoft.VisualStudio.OLE.Interop.IServiceProvider>();

            spMock.Fake_AddService(typeof(OLE.Interop.IServiceProvider), oleServiceProviderMock.Instance);
            ApplicationDesignerView view      = new ApplicationDesignerView(spMock.Instance);
            IVsHierarchy            hierarchy = new Mock <IVsHierarchy>(typeof(IVsUIHierarchy)).Instance;
            Guid guid = new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
            Mock <PropertyPageInfo> infoMock = new Mock <PropertyPageInfo>();

            infoMock.SetCreateArguments(view, guid, false);
            infoMock.Implement("TryLoadPropertyPage"); // TryLoadPropertyPage is a NOOP, so Site will remain NULL
            uint itemid = 123;
            ApplicationDesignerPanelFake panel = new ApplicationDesignerPanelFake(view, hierarchy, itemid, infoMock.Instance);

            parentControl.Controls.Add(panel);
            panel.MkDocument = "my moniker";

            // Fail the IsDocumentInAProject call
            uiShellOpenDocumentMock.AddExpectation("IsDocumentInAProject",
                                                   //string pszMkDocument, out IVsUIHierarchy ppUIH, out uint pitemid, out Microsoft.VisualStudio.OLE.Interop.IServiceProvider ppSP, out int pDocInProj)
                                                   new object[] { MockConstraint.IsAnything <string>(),
                                                                  null,
                                                                  (uint)0,
                                                                  null,
                                                                  0 },
                                                   new object[] { null,
                                                                  null,
                                                                  (uint)0,
                                                                  null,
                                                                  0 },
                                                   VSConstants.S_OK);

            // OpenSpecificEditor call should succeed

            uiShellOpenDocumentMock.AddExpectation("OpenSpecificEditor",
                                                                            //int OpenSpecificEditor(uint grfOpenSpecific, string pszMkDocument, ref Guid rguidEditorType, string pszPhysicalView, ref Guid rguidLogicalView, string pszOwnerCaption, IVsUIHierarchy pHier, uint itemid, IntPtr punkDocDataExisting, Microsoft.VisualStudio.OLE.Interop.IServiceProvider pSPHierContext, out IVsWindowFrame ppWindowFrame);
                                                   new object[] {
                MockConstraint.IsAnything <uint>(),                         //uint grfOpenSpecific
                MockConstraint.IsAnything <string>(),                       //string pszMkDocument
                MockConstraint.IsAnything <Guid>(),                         //ref Guid rguidEditorType
                MockConstraint.IsAnything <string>(),                       //string pszPhysicalView
                MockConstraint.IsAnything <Guid>(),                         //ref Guid rguidLogicalView
                MockConstraint.IsAnything <string>(),                       //string pszOwnerCaption
                MockConstraint.IsAnything <IVsUIHierarchy>(),               //IVsUIHierarchy pHier
                MockConstraint.IsAnything <uint>(),                         //uint itemid
                MockConstraint.IsAnything <IntPtr>(),                       //IntPtr punkDocDataExisting
                MockConstraint.IsAnything <OLE.Interop.IServiceProvider>(), //OLE.Interop.IServiceProvider> pSPHierContext
                null                                                        //out IVsWindowFrame ppWindowFrame
            },
                                                   new object[] {
                (uint)0,                      //uint grfOpenSpecific
                null,                         //string pszMkDocument
                Guid.Empty,                   //ref Guid rguidEditorType
                null,                         //string pszPhysicalView
                Guid.Empty,                   //ref Guid rguidLogicalView
                null,                         //string pszOwnerCaption
                null,                         //IVsUIHierarchy pHier
                (uint)0,                      //uint itemid
                IntPtr.Zero,                  //IntPtr punkDocDataExisting
                null,                         //OLE.Interop.IServiceProvider> pSPHierContext
                innerWindowFrameMock.Instance //out IVsWindowFrame ppWindowFrame
            },
                                                   VSConstants.S_OK);

            innerWindowFrameMock.Implement("GetProperty",
                                           new object[] { (int)__VSFPROPID.VSFPROPID_Hierarchy, null },
                                           new object[] { (int)0, hierarchy },
                                           VSConstants.S_OK);
            innerWindowFrameMock.Implement("GetProperty",
                                           new object[] { (int)__VSFPROPID.VSFPROPID_ItemID, null },
                                           new object[] { (int)0, 321 },
                                           VSConstants.S_OK);

            innerWindowFrameMock.Implement("GetProperty",
                                           new object[] { (int)__VSFPROPID2.VSFPROPID_ParentHwnd, null },
                                           new object[] { (int)0, (int)0 },
                                           VSConstants.S_OK);

            innerWindowFrameMock.AddExpectation("SetProperty",
                                                new object[] { (int)__VSFPROPID2.VSFPROPID_ParentHwnd, MockConstraint.IsAnything <object>() },
                                                VSConstants.S_OK);
            innerWindowFrameMock.AddExpectation("SetProperty",
                                                new object[] { (int)__VSFPROPID2.VSFPROPID_ParentFrame, MockConstraint.IsAnything <object>() },
                                                VSConstants.S_OK);

            innerWindowFrameMock.Implement(new MethodId(typeof(IVsWindowFrame2), "Advise"),
                                           new object[] { MockConstraint.IsAnything <IVsWindowFrameNotify>(), MockConstraint.IsAnything <uint>() },
                                           new object[] { null, (uint)432 },
                                           VSConstants.S_OK);
            innerWindowFrameMock.Implement(new MethodId(typeof(IVsWindowFrame2), "Unadvise"),
                                           new object[] { (uint)432 },
                                           VSConstants.S_OK);

            innerWindowFrameMock.AddExpectation("GetProperty",
                                                new object[] { (int)__VSFPROPID.VSFPROPID_DocData, null },
                                                new object[] { (int)0, null },
                                                VSConstants.S_OK);
            innerWindowFrameMock.AddExpectation("GetProperty",
                                                new object[] { (int)__VSFPROPID.VSFPROPID_DocCookie, null },
                                                new object[] { (int)0, (uint)678 },
                                                VSConstants.S_OK);
            innerWindowFrameMock.AddExpectation("GetProperty",
                                                new object[] { (int)__VSFPROPID.VSFPROPID_DocView, null },
                                                new object[] { (int)0, null },
                                                VSConstants.S_OK);
            innerWindowFrameMock.Implement("GetProperty",
                                           new object[] { (int)__VSFPROPID.VSFPROPID_EditorCaption, null },
                                           new object[] { (int)0, null },
                                           VSConstants.S_OK);

            panel.CreateDesigner();

            //Verify
            uiShellOpenDocumentMock.Verify();
            innerWindowFrameMock.Verify();
            outerWindowFrameMock.Verify();

            Assert.IsTrue(panel.Fake_wasShowWindowFrameCalled);
        }