public void ProjectFileModelWatcher_Initialize_SubscribesAndCausesCallback() { var editorState = IProjectFileEditorPresenterFactory.Create(); var unconfiguredProject = UnconfiguredProjectFactory.CreateWithUnconfiguredProjectAdvanced(); var watcher = new ProjectFileModelWatcher(editorState, unconfiguredProject); watcher.InitializeModelWatcher(); var unconfiguredProjectAdvanced = Mock.Get(unconfiguredProject).As <UnconfiguredProjectAdvanced>(); unconfiguredProjectAdvanced.Raise(u => u.ChangingProjectFile += null, EventArgs.Empty); Mock.Get(editorState).Verify(e => e.ScheduleProjectFileUpdate(), Times.Once); }
public async Task FrameOpenCloseListener_InitializeEventsAsync_SetsUpWindowFrameEvents() { var uiShell = IVsUIShell7Factory.ImplementAdviseWindowEvents(l => 1); uint eventsCookie = 2; var solution = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(eventsCookie); var serviceProvider = IServiceProviderFactory.ImplementGetService(ServiceTypeChecker(uiShell, solution)); var listener = new FrameOpenCloseListener(serviceProvider, IProjectFileEditorPresenterFactory.Create(), new IProjectThreadingServiceMock(), UnconfiguredProjectFactory.Create()); await listener.InitializeEventsAsync(IVsWindowFrameFactory.Create()); Mock.Get(uiShell).Verify(u => u.AdviseWindowFrameEvents(listener), Times.Once); Mock.Get(solution).Verify(s => s.AdviseSolutionEvents(listener, out eventsCookie), Times.Once); }
public async Task FrameOpenCloseListener_Dispose_UnsubscribesCorrectly() { var uiShell = IVsUIShell7Factory.ImplementAdviseUnadviseWindowEvents(l => 1234, c => Assert.Equal <uint>(1234, c)); var solution = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(4321); var serviceProvider = IServiceProviderFactory.ImplementGetService(ServiceTypeChecker(uiShell, solution)); var listener = new FrameOpenCloseListener(serviceProvider, IProjectFileEditorPresenterFactory.Create(), new IProjectThreadingServiceMock(), UnconfiguredProjectFactory.Create()); await listener.InitializeEventsAsync(IVsWindowFrameFactory.Create()); await listener.DisposeAsync(); Mock.Get(uiShell).Verify(u => u.UnadviseWindowFrameEvents(1234), Times.Once); Mock.Get(solution).Verify(s => s.UnadviseSolutionEvents(4321), Times.Once); }
public void ProjectFileModelWatcher_Dispose_Unsubscribes() { var editorState = IProjectFileEditorPresenterFactory.Create(); var unconfiguredProject = UnconfiguredProjectFactory.CreateWithUnconfiguredProjectAdvanced(); var watcher = new ProjectFileModelWatcher(editorState, unconfiguredProject); watcher.InitializeModelWatcher(); var unconfiguredProjectAdvanced = Mock.Get(unconfiguredProject).As <UnconfiguredProjectAdvanced>(); unconfiguredProjectAdvanced.Raise(u => u.ChangingProjectFile += null, EventArgs.Empty); Mock.Get(editorState).Verify(e => e.ScheduleProjectFileUpdate(), Times.Once); watcher.Dispose(); // Still should have only had one call to ScheduleProjectFileUpdate, as the watcher should be unsubscribed unconfiguredProjectAdvanced.Raise(u => u.ChangingProjectFile += null, EventArgs.Empty); Mock.Get(editorState).Verify(e => e.ScheduleProjectFileUpdate(), Times.Once); }
public void FrameOpenCloseListener_QueryUnloadCorrectProjectNoCancel_CallsCloseOnEditor() { var uiShell = IVsUIShell7Factory.ImplementAdviseUnadviseWindowEvents(l => 1234, c => Assert.Equal <uint>(1234, c)); var solution = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(4321); var serviceProvider = IServiceProviderFactory.ImplementGetService(ServiceTypeChecker(uiShell, solution)); var editorState = IProjectFileEditorPresenterFactory.ImplementCloseWindowAsync(true); var projPath = @"C:\ConsoleApp\ConsoleApp1\ConsoleApp1.csproj"; var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projPath); var hierarchy = IVsHierarchyFactory.ImplementAsUnconfiguredProject(unconfiguredProject); int shouldCancel = -1; var listener = new FrameOpenCloseListener(serviceProvider, editorState, new IProjectThreadingServiceMock(), unconfiguredProject); Assert.Equal(VSConstants.S_OK, listener.OnQueryUnloadProject(hierarchy, ref shouldCancel)); Assert.Equal(0, shouldCancel); Mock.Get(editorState).Verify(e => e.CanCloseWindowAsync(), Times.Once); }
public async Task FrameOpenCloseListener_NullFrame_Throws() { await Assert.ThrowsAsync <ArgumentNullException>("frame", async() => { var listener = new FrameOpenCloseListener(IServiceProviderFactory.Create(), IProjectFileEditorPresenterFactory.Create(), IProjectThreadingServiceFactory.Create(), UnconfiguredProjectFactory.Create()); await listener.InitializeEventsAsync(null); }); }
public void FrameOpenCloseListener_NullProject_Throws() { Assert.Throws <ArgumentNullException>("unconfiguredProject", () => new FrameOpenCloseListener(IServiceProviderFactory.Create(), IProjectFileEditorPresenterFactory.Create(), IProjectThreadingServiceFactory.Create(), null)); }
public void ProjectFileModelWatcher_NullUnconfiguredProject_Throws() { Assert.Throws <ArgumentNullException>("unconfiguredProject", () => new ProjectFileModelWatcher(IProjectFileEditorPresenterFactory.Create(), null)); }