-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix persisting connection even when file is renamed (#540)
* added new onDidRename function for connection reuse * detection for renamed file logic started * simplifying logic for passing connection between a renamed file * adding a timer check for verifying a file was actually renamed * adding a constant for the threshold of time for a rename to occur * reworked previous logic to fit all cases * updating comments to match function * adding comments to untitled and rename logic * test framework setup * setting up functions to be accessible for testing * tests to cover onDidCloseTestDoc * merged into one function called transferFileConnection
- Loading branch information
Showing
4 changed files
with
127 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict'; | ||
import * as TypeMoq from 'typemoq'; | ||
|
||
import vscode = require('vscode'); | ||
import MainController from '../src/controllers/mainController'; | ||
import ConnectionManager from '../src/controllers/connectionManager'; | ||
import * as Extension from '../src/extension'; | ||
import Constants = require('../src/models/constants'); | ||
|
||
// import assert = require('assert'); | ||
|
||
suite('MainController Tests', () => { | ||
let document: vscode.TextDocument; | ||
let mainController: MainController; | ||
let connectionManager: TypeMoq.Mock<ConnectionManager>; | ||
|
||
setup(() => { | ||
// Setup a standard document | ||
document = <vscode.TextDocument> { | ||
uri : { | ||
toString(skipEncoding?: boolean): string { | ||
return 'testingURI.sql'; | ||
} | ||
} | ||
}; | ||
|
||
connectionManager = TypeMoq.Mock.ofType(ConnectionManager); | ||
|
||
mainController = Extension.getController(); | ||
mainController.connectionManager = connectionManager.object; | ||
connectionManager.setup(x => x.onDidCloseTextDocument(TypeMoq.It.isAny())); | ||
connectionManager.setup(x => x.transferFileConnection(TypeMoq.It.isAny(), TypeMoq.It.isAny())); | ||
}); | ||
|
||
test('onDidCloseTextDocument should propogate onDidCloseTextDocument to connectionManager' , done => { | ||
mainController.onDidCloseTextDocument(document); | ||
try { | ||
connectionManager.verify(x => x.onDidCloseTextDocument(TypeMoq.It.isAny()), TypeMoq.Times.once()); | ||
done(); | ||
} catch (err) { | ||
done(new Error(err)); | ||
} | ||
}); | ||
|
||
test('onDidCloseTextDocument should call renamedDoc function when rename occurs' , done => { | ||
// A renamed doc constitutes an openDoc event directly followed by a closeDoc event | ||
mainController.onDidOpenTextDocument(document); | ||
mainController.onDidCloseTextDocument(document); | ||
|
||
// Verify renameDoc function was called | ||
try { | ||
connectionManager.verify(x => x.transferFileConnection(TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.once()); | ||
done(); | ||
} catch (err) { | ||
done(new Error(err)); | ||
} | ||
}); | ||
|
||
test('onDidCloseTextDocument should untitledDoc function when an untitled file is saved' , done => { | ||
// Scheme of older doc must be untitled | ||
document.uri.scheme = Constants.untitledScheme; | ||
|
||
// A save untitled doc constitutes an saveDoc event directly followed by a closeDoc event | ||
mainController.onDidSaveTextDocument(document); | ||
mainController.onDidCloseTextDocument(document); | ||
try { | ||
connectionManager.verify(x => x.transferFileConnection(TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.once()); | ||
done(); | ||
} catch (err) { | ||
done(new Error(err)); | ||
} | ||
}); | ||
|
||
}); |