@@ -9,7 +9,7 @@ import { interfaces } from 'inversify';
99import * as os from 'os' ;
1010import * as path from 'path' ;
1111import { SemVer } from 'semver' ;
12- import { anything , instance , mock , reset , when } from 'ts-mockito' ;
12+ import { anyString , anything , instance , mock , reset , when } from 'ts-mockito' ;
1313import * as TypeMoq from 'typemoq' ;
1414import {
1515 CancellationTokenSource ,
@@ -20,6 +20,7 @@ import {
2020 FileSystemWatcher ,
2121 Memento ,
2222 Uri ,
23+ WindowState ,
2324 WorkspaceFolder ,
2425 WorkspaceFoldersChangeEvent
2526} from 'vscode' ;
@@ -68,6 +69,7 @@ import {
6869 IDiagnosticsService
6970} from '../../client/application/diagnostics/types' ;
7071import { ApplicationEnvironment } from '../../client/common/application/applicationEnvironment' ;
72+ import { ApplicationShell } from '../../client/common/application/applicationShell' ;
7173import { ClipboardService } from '../../client/common/application/clipboard' ;
7274import { VSCodeNotebook } from '../../client/common/application/notebook' ;
7375import { TerminalManager } from '../../client/common/application/terminalManager' ;
@@ -158,6 +160,7 @@ import {
158160 ICryptoUtils ,
159161 ICurrentProcess ,
160162 IDataScienceSettings ,
163+ IDisposable ,
161164 IExperimentService ,
162165 IExperimentsManager ,
163166 IExtensionContext ,
@@ -424,7 +427,7 @@ export class DataScienceIocContainer extends UnitTestIocContainer {
424427 }
425428 private static jupyterInterpreters : PythonInterpreter [ ] = [ ] ;
426429 private static foundPythonPath : string | undefined ;
427- public applicationShell ! : TypeMoq . IMock < IApplicationShell > ;
430+ public applicationShell ! : ApplicationShell ;
428431 // tslint:disable-next-line:no-any
429432 public datascience ! : TypeMoq . IMock < IDataScience > ;
430433 public shouldMockJupyter : boolean ;
@@ -938,7 +941,7 @@ export class DataScienceIocContainer extends UnitTestIocContainer {
938941 this . serviceManager . addSingletonInstance < ICommandManager > ( ICommandManager , this . commandManager ) ;
939942
940943 // Mock the app shell
941- const appShell = ( this . applicationShell = TypeMoq . Mock . ofType < IApplicationShell > ( ) ) ;
944+ this . applicationShell = mock ( ApplicationShell ) ;
942945 const configurationService = TypeMoq . Mock . ofType < IConfigurationService > ( ) ;
943946
944947 configurationService . setup ( ( c ) => c . getSettings ( TypeMoq . It . isAny ( ) ) ) . returns ( this . getSettings . bind ( this ) ) ;
@@ -948,7 +951,7 @@ export class DataScienceIocContainer extends UnitTestIocContainer {
948951 EnvironmentVariablesProvider
949952 ) ;
950953
951- this . serviceManager . addSingletonInstance < IApplicationShell > ( IApplicationShell , appShell . object ) ;
954+ this . serviceManager . addSingletonInstance < IApplicationShell > ( IApplicationShell , instance ( this . applicationShell ) ) ;
952955 this . serviceManager . addSingleton < IClipboard > ( IClipboard , ClipboardService ) ;
953956 this . serviceManager . addSingletonInstance < IDocumentManager > ( IDocumentManager , this . documentManager ) ;
954957 this . serviceManager . addSingletonInstance < IConfigurationService > (
@@ -1131,35 +1134,52 @@ export class DataScienceIocContainer extends UnitTestIocContainer {
11311134 }
11321135 } ;
11331136
1134- appShell . setup ( ( a ) => a . showErrorMessage ( TypeMoq . It . isAnyString ( ) ) ) . returns ( ( ) => Promise . resolve ( '' ) ) ;
1135- appShell
1136- . setup ( ( a ) => a . showErrorMessage ( TypeMoq . It . isAnyString ( ) , anything ( ) ) )
1137- . returns ( ( ) => Promise . resolve ( '' ) ) ;
1138- appShell
1139- . setup ( ( a ) => a . showErrorMessage ( TypeMoq . It . isAnyString ( ) , anything ( ) , anything ( ) ) )
1140- . returns ( ( ) => Promise . resolve ( '' ) ) ;
1141- appShell
1142- . setup ( ( a ) => a . showInformationMessage ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
1143- . returns ( ( ) => Promise . resolve ( '' ) ) ;
1144- appShell
1145- . setup ( ( a ) => a . showInformationMessage ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
1146- . returns ( ( _a1 : string , a2 : string , _a3 : string ) => Promise . resolve ( a2 ) ) ;
1147- appShell
1148- . setup ( ( a ) =>
1149- a . showInformationMessage ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) )
1150- )
1151- . returns ( ( _a1 : string , a2 : any , _a3 : string , a4 : string ) => {
1137+ when ( this . applicationShell . showErrorMessage ( anyString ( ) ) ) . thenReturn ( Promise . resolve ( '' ) ) ;
1138+ when ( this . applicationShell . showErrorMessage ( anyString ( ) , anything ( ) ) ) . thenReturn ( Promise . resolve ( '' ) ) ;
1139+ when ( this . applicationShell . showErrorMessage ( anyString ( ) , anything ( ) , anything ( ) ) ) . thenReturn (
1140+ Promise . resolve ( '' )
1141+ ) ;
1142+ when ( this . applicationShell . showInformationMessage ( anyString ( ) ) ) . thenReturn ( Promise . resolve ( '' ) ) ;
1143+ when ( this . applicationShell . showInformationMessage ( anyString ( ) , anything ( ) ) ) . thenReturn ( Promise . resolve ( '' ) ) ;
1144+ when (
1145+ this . applicationShell . showInformationMessage ( anyString ( ) , anything ( ) , anything ( ) )
1146+ ) . thenCall ( ( _a1 , a2 , _a3 ) => Promise . resolve ( a2 ) ) ;
1147+ when ( this . applicationShell . showInformationMessage ( anyString ( ) , anything ( ) , anything ( ) , anything ( ) ) ) . thenCall (
1148+ ( _a1 , a2 , _a3 , a4 ) => {
11521149 if ( typeof a2 === 'string' ) {
11531150 return Promise . resolve ( a2 ) ;
11541151 } else {
11551152 return Promise . resolve ( a4 ) ;
11561153 }
1157- } ) ;
1158- appShell
1159- . setup ( ( a ) => a . showSaveDialog ( TypeMoq . It . isAny ( ) ) )
1160- . returns ( ( ) => Promise . resolve ( Uri . file ( 'test.ipynb' ) ) ) ;
1161- appShell . setup ( ( a ) => a . setStatusBarMessage ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => dummyDisposable ) ;
1162- appShell . setup ( ( a ) => a . showInputBox ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => Promise . resolve ( 'Python' ) ) ;
1154+ }
1155+ ) ;
1156+ when ( this . applicationShell . showWarningMessage ( anyString ( ) ) ) . thenReturn ( Promise . resolve ( '' ) ) ;
1157+ when ( this . applicationShell . showWarningMessage ( anyString ( ) , anything ( ) ) ) . thenReturn ( Promise . resolve ( '' ) ) ;
1158+ when ( this . applicationShell . showWarningMessage ( anyString ( ) , anything ( ) , anything ( ) ) ) . thenCall ( ( _a1 , a2 , _a3 ) =>
1159+ Promise . resolve ( a2 )
1160+ ) ;
1161+ when ( this . applicationShell . showWarningMessage ( anyString ( ) , anything ( ) , anything ( ) , anything ( ) ) ) . thenCall (
1162+ ( _a1 , a2 , _a3 , a4 ) => {
1163+ if ( typeof a2 === 'string' ) {
1164+ return Promise . resolve ( a2 ) ;
1165+ } else {
1166+ return Promise . resolve ( a4 ) ;
1167+ }
1168+ }
1169+ ) ;
1170+ when ( this . applicationShell . showSaveDialog ( anything ( ) ) ) . thenReturn ( Promise . resolve ( Uri . file ( 'test.ipynb' ) ) ) ;
1171+ when ( this . applicationShell . setStatusBarMessage ( anything ( ) ) ) . thenReturn ( dummyDisposable ) ;
1172+ when ( this . applicationShell . showInputBox ( anything ( ) ) ) . thenReturn ( Promise . resolve ( 'Python' ) ) ;
1173+ const eventCallback = (
1174+ _listener : ( e : WindowState ) => any ,
1175+ _thisArgs ?: any ,
1176+ _disposables ?: IDisposable [ ] | Disposable
1177+ ) => {
1178+ return {
1179+ dispose : noop
1180+ } ;
1181+ } ;
1182+ when ( this . applicationShell . onDidChangeWindowState ) . thenReturn ( eventCallback ) ;
11631183
11641184 const interpreterManager = this . serviceContainer . get < IInterpreterService > ( IInterpreterService ) ;
11651185 interpreterManager . initialize ( ) ;
0 commit comments