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(); }