當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Mock.ofInstance方法代碼示例

本文整理匯總了TypeScript中typemoq.Mock.ofInstance方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Mock.ofInstance方法的具體用法?TypeScript Mock.ofInstance怎麽用?TypeScript Mock.ofInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在typemoq.Mock的用法示例。


在下文中一共展示了Mock.ofInstance方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: test

	test('getCurrentGlobalConnection returns the selected OE database if a database or its children is selected', () => {
		let connectionProfile = { databaseName: 'test_database', id: 'test_id', authenticationType: 'SQL Login', password: 'test_password', serverName: 'test_server', userName: 'test_user' } as IConnectionProfile;
		let mockObjectExplorerService = TypeMoq.Mock.ofInstance({ isFocused: () => undefined, getSelectedProfileAndDatabase: () => undefined } as IObjectExplorerService);
		let mockConnectionManagementService = TypeMoq.Mock.ofType(TestConnectionManagementService);
		let mockWorkbenchEditorService = TypeMoq.Mock.ofType(WorkbenchEditorTestService);
		let serverProfile = new ConnectionProfile(undefined, connectionProfile);
		let dbName = 'test_database';
		mockObjectExplorerService.setup(x => x.isFocused()).returns(() => true);
		mockObjectExplorerService.setup(x => x.getSelectedProfileAndDatabase()).returns(() => {
			return { profile: serverProfile, databaseName: dbName };
		});
		mockConnectionManagementService.setup(x => x.isProfileConnected(TypeMoq.It.is(profile => profile === serverProfile))).returns(() => true);
		mockWorkbenchEditorService.setup(x => x.getActiveEditorInput()).returns(() => undefined);

		// If I call getCurrentGlobalConnection, it should return the expected database profile
		let actualProfile = TaskUtilities.getCurrentGlobalConnection(mockObjectExplorerService.object, mockConnectionManagementService.object, mockWorkbenchEditorService.object);
		assert.equal(actualProfile.databaseName, dbName);
		assert.notEqual(actualProfile.id, serverProfile.id);
		// Other connection attributes still match
		assert.equal(actualProfile.authenticationType, serverProfile.authenticationType);
		assert.equal(actualProfile.password, serverProfile.password);
		assert.equal(actualProfile.serverName, serverProfile.serverName);
		assert.equal(actualProfile.userName, serverProfile.userName);
	});
開發者ID:jumpinjackie,項目名稱:sqlopsstudio,代碼行數:24,代碼來源:taskUtilities.test.ts

示例2: setup

	setup(() => {
		defaultNamedProfile = Object.assign({}, {
			serverName: 'namedServer',
			databaseName: 'bcd',
			authenticationType: 'SqlLogin',
			userName: 'cde',
			password: 'asdf!@#$',
			savePassword: true,
			groupId: '',
			groupFullName: '',
			getOptionsKey: undefined,
			matches: undefined,
			providerName: 'MSSQL',
			options: {},
			saveProfile: true,
			id: undefined
		});

		defaultUnnamedProfile = Object.assign({}, {
			serverName: 'unnamedServer',
			databaseName: undefined,
			authenticationType: 'SqlLogin',
			userName: 'aUser',
			password: 'asdf!@#$',
			savePassword: true,
			groupId: '',
			groupFullName: '',
			getOptionsKey: undefined,
			matches: undefined,
			providerName: 'MSSQL',
			options: {},
			saveProfile: true,
			id: undefined
		});

		profileForProvider2 = Object.assign({}, {
			serverName: 'unnamedServer',
			databaseName: undefined,
			authenticationType: 'SqlLogin',
			userName: 'aUser',
			password: 'asdf!@#$',
			savePassword: true,
			groupId: '',
			groupFullName: '',
			getOptionsKey: undefined,
			matches: undefined,
			providerName: 'MSSQL',
			options: {},
			saveProfile: true,
			id: undefined
		});

		let momento = new Memento('ConnectionManagement');
		context = TypeMoq.Mock.ofInstance(momento);
		context.setup(x => x.getMemento(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => mementoArray);

		credentialStore = TypeMoq.Mock.ofType(CredentialsService);
		connectionConfig = TypeMoq.Mock.ofType(ConnectionConfig);

		// setup configuration to return maxRecent for the #MRU items

		let configResult: { [key: string]: any } = {};
		configResult[Constants.configMaxRecentConnections] = maxRecent;

		workspaceConfigurationServiceMock = TypeMoq.Mock.ofType(WorkspaceConfigurationTestService);
		workspaceConfigurationServiceMock.setup(x => x.getValue(Constants.sqlConfigSectionName))
			.returns(() => configResult);

		storageServiceMock = TypeMoq.Mock.ofType(StorageTestService);

		let extensionManagementServiceMock = {
			getInstalled: () => {
				return Promise.resolve([]);
			}
		};

		capabilitiesService = new CapabilitiesTestService();
		let connectionProvider: sqlops.ConnectionOption[] = [
			{
				name: 'serverName',
				displayName: undefined,
				description: undefined,
				groupName: undefined,
				categoryValues: undefined,
				defaultValue: undefined,
				isIdentity: true,
				isRequired: true,
				specialValueType: ConnectionOptionSpecialType.serverName,
				valueType: ServiceOptionType.string
			},
			{
				name: 'databaseName',
				displayName: undefined,
				description: undefined,
				groupName: undefined,
				categoryValues: undefined,
				defaultValue: undefined,
				isIdentity: true,
				isRequired: true,
				specialValueType: ConnectionOptionSpecialType.databaseName,
//.........這裏部分代碼省略.........
開發者ID:jumpinjackie,項目名稱:sqlopsstudio,代碼行數:101,代碼來源:connectionStore.test.ts

示例3: setup

	setup(() => {
		// Setup DOM elements
		let element = DOM.$('queryEditorParent');
		parentBuilder = new Builder(element);

		// Create object to mock the Editor classes
		// QueryResultsEditor fails at runtime due to the way we are importing Angualar,
		// so a {} mock is used here. This mock simply needs to have empty method stubs
		// for all called runtime methods
		mockEditor = {
			_bootstrapAngular: function () { },
			setInput: function () { },
			createEditor: function () { },
			create: function () { },
			setVisible: function () { },
			layout: function () { },
			dispose: function () { }
		};

		// Mock InstantiationService to give us our mockEditor
		instantiationService = TypeMoq.Mock.ofType(InstantiationService, TypeMoq.MockBehavior.Loose);
		instantiationService.setup(x => x.createInstance(TypeMoq.It.isAny())).returns((input) => {
			return new TPromise((resolve) => resolve(mockEditor));
		});
		instantiationService.setup(x => x.createInstance(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((input) => {
			return new TPromise((resolve) => resolve(new RunQueryAction(undefined, undefined, undefined)));
		});
		// Setup hook to capture calls to create the listDatabase action
		instantiationService.setup(x => x.createInstance(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((classDef, editor, action) => {
			if (classDef.ID) {
				if (classDef.ID === 'listDatabaseQueryActionItem') {
					return new ListDatabasesActionItem(editor, action, connectionManagementService.object, undefined, undefined, undefined, configurationService.object);
				}
			}
			// Default
			return new RunQueryAction(undefined, undefined, undefined);
		});

		// Mock EditorDescriptorService to give us a mock editor description
		let descriptor: IEditorDescriptor = {
			getId: function (): string { return 'id'; },
			getName: function (): string { return 'name'; },
			describes: function (obj: any): boolean { return true; },
			instantiate(instantiationService: IInstantiationService): BaseEditor { return undefined; }
		};
		editorDescriptorService = TypeMoq.Mock.ofType(EditorDescriptorService, TypeMoq.MockBehavior.Loose);
		editorDescriptorService.setup(x => x.getEditor(TypeMoq.It.isAny())).returns(() => descriptor);

		configurationService = TypeMoq.Mock.ofInstance({
			getValue: () => undefined,
			onDidChangeConfiguration: () => undefined
		} as any);
		configurationService.setup(x => x.getValue(TypeMoq.It.isAny())).returns(() => {
			return { enablePreviewFeatures: true };
		});

		// Create a QueryInput
		let filePath = 'someFile.sql';
		let uri: URI = URI.parse(filePath);
		let fileInput = new UntitledEditorInput(uri, false, '', '', '', instantiationService.object, undefined, undefined, undefined);
		let queryResultsInput: QueryResultsInput = new QueryResultsInput(uri.fsPath, configurationService.object);
		queryInput = new QueryInput('first', fileInput, queryResultsInput, undefined, undefined, undefined, undefined, undefined);

		// Create a QueryInput to compare to the previous one
		let filePath2 = 'someFile2.sql';
		let uri2: URI = URI.parse(filePath2);
		let fileInput2 = new UntitledEditorInput(uri2, false, '', '', '', instantiationService.object, undefined, undefined, undefined);
		let queryResultsInput2: QueryResultsInput = new QueryResultsInput(uri2.fsPath, configurationService.object);
		queryInput2 = new QueryInput('second', fileInput2, queryResultsInput2, undefined, undefined, undefined, undefined, undefined);

		// Mock IMessageService
		notificationService = TypeMoq.Mock.ofType(TestNotificationService, TypeMoq.MockBehavior.Loose);

		// Mock ConnectionManagementService
		memento = TypeMoq.Mock.ofType(Memento, TypeMoq.MockBehavior.Loose, '');
		memento.setup(x => x.getMemento(TypeMoq.It.isAny())).returns(() => void 0);
		connectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Loose, memento.object, undefined);
		connectionManagementService.callBase = true;
		connectionManagementService.setup(x => x.isConnected(TypeMoq.It.isAny())).returns(() => false);

		// Create a QueryModelService
		queryModelService = new QueryModelService(instantiationService.object, notificationService.object);
	});
開發者ID:burhandodhy,項目名稱:azuredatastudio,代碼行數:83,代碼來源:queryEditor.test.ts

示例4: setup


//.........這裏部分代碼省略.........
					valueType: ServiceOptionType.string
				},
				{
					name: 'encrypt',
					displayName: undefined,
					description: undefined,
					groupName: undefined,
					categoryValues: undefined,
					defaultValue: undefined,
					isIdentity: false,
					isRequired: false,
					specialValueType: undefined,
					valueType: ServiceOptionType.string
				}
			]
		};

		let capabilitiesService = new CapabilitiesTestService();
		capabilitiesService.capabilities['MSSQL'] = { connection: sqlProvider };

		connection = new ConnectionProfile(capabilitiesService, {
			connectionName: 'newName',
			savePassword: false,
			groupFullName: 'testGroup',
			serverName: 'testServerName',
			databaseName: 'testDatabaseName',
			authenticationType: 'inetgrated',
			password: 'test',
			userName: 'testUsername',
			groupId: undefined,
			providerName: 'MSSQL',
			options: {},
			saveProfile: true,
			id: 'testID'
		});
		conProfGroup = new ConnectionProfileGroup('testGroup', undefined, 'testGroup', undefined, undefined);

		connectionToFail = new ConnectionProfile(capabilitiesService, {
			connectionName: 'newName2',
			savePassword: false,
			groupFullName: 'testGroup',
			serverName: 'testServerName2',
			databaseName: 'testDatabaseName2',
			authenticationType: 'inetgrated',
			password: 'test',
			userName: 'testUsername',
			groupId: undefined,
			providerName: 'MSSQL',
			options: {},
			saveProfile: true,
			id: 'testID2'
		});
		conProfGroup = new ConnectionProfileGroup('testGroup', undefined, 'testGroup', undefined, undefined);
		conProfGroup.connections = [connection];
		connectionManagementService = TypeMoq.Mock.ofType(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
		connectionManagementService.setup(x => x.getConnectionGroups()).returns(() => [conProfGroup]);
		connectionManagementService.setup(x => x.getActiveConnections()).returns(() => [connection]);
		connectionManagementService.setup(x => x.addSavedPassword(TypeMoq.It.isAny())).returns(() => new Promise<ConnectionProfile>((resolve) => {
			resolve(connection);
		}));

		connectionManagementService.setup(x => x.getCapabilities('MSSQL')).returns(() => undefined);

		let extensionManagementServiceMock = {
			getInstalled: () => {
				return Promise.resolve([]);
			}
		};

		objectExplorerService = new ObjectExplorerService(connectionManagementService.object, undefined, capabilitiesService);
		objectExplorerService.registerProvider('MSSQL', sqlOEProvider.object);
		sqlOEProvider.setup(x => x.createNewSession(TypeMoq.It.is<sqlops.ConnectionInfo>(x => x.options['serverName'] === connection.serverName))).returns(() => new Promise<any>((resolve) => {
			resolve(response);
		}));
		sqlOEProvider.setup(x => x.createNewSession(TypeMoq.It.is<sqlops.ConnectionInfo>(x => x.options['serverName'] === connectionToFail.serverName))).returns(() => new Promise<any>((resolve) => {
			resolve(failedResponse);
		}));
		sqlOEProvider.setup(x => x.expandNode(TypeMoq.It.isAny())).callback(() => {
			objectExplorerService.onNodeExpanded(1, objectExplorerExpandInfo);
		}).returns(() => TPromise.as(true));
		sqlOEProvider.setup(x => x.refreshNode(TypeMoq.It.isAny())).callback(() => {
			objectExplorerService.onNodeExpanded(1, objectExplorerExpandInfoRefresh);
		}).returns(() => TPromise.as(true));
		sqlOEProvider.setup(x => x.closeSession(TypeMoq.It.isAny())).returns(() => TPromise.as(objectExplorerCloseSessionResponse));

		objectExplorerService.onUpdateObjectExplorerNodes(args => {
			if (args && args.errorMessage !== undefined) {
				numberOfFailedSession++;
			}
		});

		serverTreeView = TypeMoq.Mock.ofInstance({
			setExpandedState: (element, expandedState) => Promise.resolve() as Thenable<void>,
			reveal: element => Promise.resolve() as Thenable<void>,
			setSelected: (element, selected, clearOtherSelections) => undefined,
			isExpanded: element => undefined,
			onSelectionOrFocusChange: Event.None,
			refreshElement: (element) => Promise.resolve() as Thenable<void>
		} as ServerTreeView);
	});
開發者ID:burhandodhy,項目名稱:azuredatastudio,代碼行數:101,代碼來源:objectExplorerService.test.ts

示例5: setup

	setup(() => {
		account = {
			key: { providerId: 'azure', accountId: 'account1' },
			displayInfo: {
				contextualDisplayName: 'Microsoft Account',
				accountType: 'microsoft',
				displayName: 'Account 1'
			},
			properties: [],
			isStale: false
		};

		mockOnAddAccountErrorEvent = new Emitter<string>();
		mockOnCreateFirewallRule = new Emitter<void>();

		// Create a mock firewall rule view model
		let firewallRuleViewModel = new FirewallRuleViewModel();
		mockFirewallRuleViewModel = TypeMoq.Mock.ofInstance(firewallRuleViewModel);
		mockFirewallRuleViewModel.setup(x => x.updateDefaultValues(TypeMoq.It.isAny()))
			.returns((ipAddress) => undefined);
		mockFirewallRuleViewModel.object.selectedAccount = account;
		mockFirewallRuleViewModel.object.isIPAddressSelected = true;

		// Create a mocked out instantiation service
		instantiationService = TypeMoq.Mock.ofType(InstantiationService, TypeMoq.MockBehavior.Strict);
		instantiationService.setup(x => x.createInstance(TypeMoq.It.isValue(FirewallRuleViewModel)))
			.returns(() => mockFirewallRuleViewModel.object);

		// Create a mock account picker
		let firewallRuleDialog = new FirewallRuleDialog(null, null, null, instantiationService.object, null, null, new ContextKeyServiceStub(), null);
		mockFirewallRuleDialog = TypeMoq.Mock.ofInstance(firewallRuleDialog);

		let mockEvent = new Emitter<any>();
		mockFirewallRuleDialog.setup(x => x.onCancel)
			.returns(() => mockEvent.event);
		mockFirewallRuleDialog.setup(x => x.onCreateFirewallRule)
			.returns(() => mockOnCreateFirewallRule.event);
		mockFirewallRuleDialog.setup(x => x.onAddAccountErrorEvent)
			.returns((msg) => mockOnAddAccountErrorEvent.event);
		mockFirewallRuleDialog.setup(x => x.render());
		mockFirewallRuleDialog.setup(x => x.open());
		mockFirewallRuleDialog.setup(x => x.close());

		instantiationService.setup(x => x.createInstance(TypeMoq.It.isValue(FirewallRuleDialog)))
			.returns(() => mockFirewallRuleDialog.object);

		connectionProfile = {
			connectionName: 'new name',
			serverName: 'new server',
			databaseName: 'database',
			userName: 'user',
			password: 'password',
			authenticationType: '',
			savePassword: true,
			groupFullName: 'g2/g2-2',
			groupId: 'group id',
			getOptionsKey: undefined,
			matches: undefined,
			providerName: 'MSSQL',
			options: {},
			saveProfile: true,
			id: undefined
		};
	});
開發者ID:burhandodhy,項目名稱:azuredatastudio,代碼行數:64,代碼來源:firewallRuleDialogController.test.ts

示例6:

const mockVerifyClient = () => {
  const verifyMock = TypeMoq.Mock.ofInstance(container.get<VerificationClientInterface>(VerificationClientType));
  verifyMock.callBase = true;

  const initiateResult: InitiateResult = {
    status: 200,
    verificationId: '123',
    attempts: 0,
    expiredOn: 124545,
    method: 'email'
  };

  const validationResultToEnable2fa: ValidationResult = {
    status: 200,
    data: {
      verificationId: 'enable_2fa_verification',
      consumer: 'activated@test.com',
      expiredOn: 123456,
      attempts: 0,
      payload: {
        scope: ENABLE_2FA_SCOPE
      }
    }
  };

  const validationResultToDisable2fa: ValidationResult = {
    status: 200,
    data: {
      verificationId: 'disable_2fa_verification',
      consumer: '2fa@test.com',
      expiredOn: 123456,
      attempts: 0,
      payload: {
        scope: DISABLE_2FA_SCOPE
      }
    }
  };

  const validationResultToVerifyInvestment: ValidationResult = {
    status: 200,
    data: {
      verificationId: 'verify_invest',
      consumer: 'activated@test.com',
      expiredOn: 123456,
      attempts: 0,
      payload: {
        scope: INVEST_SCOPE,
        ethAmount: '1'
      }
    }
  };

  const validationResultChangePassword: ValidationResult = {
    status: 200,
    data: {
      verificationId: 'change_password_verification',
      consumer: 'activated@test.com',
      expiredOn: 123456,
      attempts: 0,
      payload: {
        scope: CHANGE_PASSWORD_SCOPE
      }
    }
  };

  const validationResultResetPassword: ValidationResult = {
    status: 200,
    data: {
      verificationId: 'reset_password_verification',
      consumer: 'activated@test.com',
      expiredOn: 123456,
      attempts: 0,
      payload: {
        scope: RESET_PASSWORD_SCOPE
      }
    }
  };

  const validationResultActivateUser: ValidationResult = {
    status: 200,
    data: {
      verificationId: 'activated_user_verification',
      consumer: 'existing@test.com',
      expiredOn: 123456,
      attempts: 0,
      payload: {
        scope: ACTIVATE_USER_SCOPE
      }
    }
  };

  const validationResultVerifyLogin: ValidationResult = {
    status: 200,
    data: {
      verificationId: 'verify_login_verification',
      consumer: 'activated@test.com',
      expiredOn: 123456,
      attempts: 0,
      payload: {
        scope: LOGIN_USER_SCOPE
//.........這裏部分代碼省略.........
開發者ID:Norestlabs-Mariya,項目名稱:backend-ico-dashboard,代碼行數:101,代碼來源:test.app.factory.ts


注:本文中的typemoq.Mock.ofInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。