Ejemplo n.º 1
0
        private async Task VerifyFileIsNotAddedOnDocOpened(string filePath)
        {
            // setup test workspace
            var workspace        = new ServiceLayer.Workspace.Workspace();
            var workspaceService = new WorkspaceService <SqlToolsSettings> {
                Workspace = workspace
            };

            // send a document open event with git:/ prefix URI
            var openParams = new DidOpenTextDocumentNotification
            {
                TextDocument = new TextDocumentItem {
                    Uri = filePath
                }
            };

            await workspaceService.HandleDidOpenTextDocumentNotification(openParams, eventContext : null);

            // verify the file is not being tracked by workspace
            Assert.False(workspaceService.Workspace.ContainsFile(filePath));

            // send a close event with git:/ prefix URI
            var closeParams = new DidCloseTextDocumentParams
            {
                TextDocument = new TextDocumentItem {
                    Uri = filePath
                }
            };

            await workspaceService.HandleDidCloseTextDocumentNotification(closeParams, eventContext : null);

            // this is not that interesting validation since the open is ignored
            // the main validation is that close doesn't raise an exception
            Assert.False(workspaceService.Workspace.ContainsFile(filePath));
        }
Ejemplo n.º 2
0
        public async Task FileClosedSuccessfully()
        {
            // Given:
            // ... A workspace that has a single file open
            var workspace        = new ServiceLayer.Workspace.Workspace();
            var workspaceService = new WorkspaceService <SqlToolsSettings> {
                Workspace = workspace
            };
            var openedFile = workspace.GetFileBuffer(TestObjects.ScriptUri, string.Empty);

            Assert.NotNull(openedFile);
            Assert.NotEmpty(workspace.GetOpenedFiles());

            // ... And there is a callback registered for the file closed event
            ScriptFile closedFile = null;
            string     closedUri  = null;

            workspaceService.RegisterTextDocCloseCallback((u, f, c) =>
            {
                closedUri  = u;
                closedFile = f;
                return(Task.FromResult(true));
            });

            // If:
            // ... An event to close the open file occurs
            var eventContext  = new Mock <EventContext>().Object;
            var requestParams = new DidCloseTextDocumentParams
            {
                TextDocument = new TextDocumentItem {
                    Uri = TestObjects.ScriptUri
                }
            };
            await workspaceService.HandleDidCloseTextDocumentNotification(requestParams, eventContext);

            // Then:
            // ... The file should no longer be in the open files
            Assert.Empty(workspace.GetOpenedFiles());

            // ... The callback should have been called
            // ... The provided script file should be the one we created
            Assert.NotNull(closedFile);
            Assert.Equal(openedFile, closedFile);
            Assert.Equal(TestObjects.ScriptUri, closedUri);
        }
Ejemplo n.º 3
0
        public async Task FileClosedNotOpen()
        {
            // Given:
            // ... A workspace that has no files open
            var workspace        = new ServiceLayer.Workspace.Workspace();
            var workspaceService = new WorkspaceService <SqlToolsSettings> {
                Workspace = workspace
            };

            Assert.Empty(workspace.GetOpenedFiles());

            // ... And there is a callback registered for the file closed event
            bool callbackCalled = false;

            workspaceService.RegisterTextDocCloseCallback((f, c) =>
            {
                callbackCalled = true;
                return(Task.FromResult(true));
            });

            // If:
            // ... An event to close the a file occurs
            var eventContext  = new Mock <EventContext>().Object;
            var requestParams = new DidCloseTextDocumentParams
            {
                TextDocument = new TextDocumentItem {
                    Uri = TestObjects.ScriptUri
                }
            };
            // Then:
            // ... There should be a file not found exception thrown
            // TODO: This logic should be changed to not create the ScriptFile
            await Assert.ThrowsAnyAsync <IOException>(
                () => workspaceService.HandleDidCloseTextDocumentNotification(requestParams, eventContext));

            // ... There should still be no open files
            // ... The callback should not have been called
            Assert.Empty(workspace.GetOpenedFiles());
            Assert.False(callbackCalled);
        }