コード例 #1
0
 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);
     });
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }