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


TypeScript autoOAuthDialogController.AutoOAuthDialogController類代碼示例

本文整理匯總了TypeScript中sql/parts/accountManagement/autoOAuthDialog/autoOAuthDialogController.AutoOAuthDialogController的典型用法代碼示例。如果您正苦於以下問題:TypeScript AutoOAuthDialogController類的具體用法?TypeScript AutoOAuthDialogController怎麽用?TypeScript AutoOAuthDialogController使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: suite

suite('auto OAuth dialog controller tests', () => {
	let instantiationService: TypeMoq.Mock<InstantiationService>;
	let mockAutoOAuthDialog: TypeMoq.Mock<AutoOAuthDialog>;
	let mockAccountManagementService: TypeMoq.Mock<AccountManagementTestService>;
	let mockErrorMessageService: TypeMoq.Mock<ErrorMessageServiceStub>;
	let autoOAuthDialogController: AutoOAuthDialogController;

	let mockOnCancelEvent: Emitter<void>;
	let mockOnAddAccountEvent: Emitter<void>;
	let mockOnCloseEvent: Emitter<void>;

	let providerId = 'azure';
	let title = 'Add Account';
	let message = 'This is the dialog description';
	let userCode = 'abcde';
	let uri = 'uri';

	setup(() => {
		mockOnCancelEvent = new Emitter<void>();
		mockOnAddAccountEvent = new Emitter<void>();
		mockOnCloseEvent = new Emitter<void>();

		// Create a mock auto OAuth dialog
		let autoOAuthDialog = new AutoOAuthDialog(null, null, null, null, new ContextKeyServiceStub());
		mockAutoOAuthDialog = TypeMoq.Mock.ofInstance(autoOAuthDialog);

		mockAutoOAuthDialog.setup(x => x.onCancel).returns(() => mockOnCancelEvent.event);
		mockAutoOAuthDialog.setup(x => x.onHandleAddAccount).returns(() => mockOnAddAccountEvent.event);
		mockAutoOAuthDialog.setup(x => x.onCloseEvent).returns(() => mockOnCloseEvent.event);
		mockAutoOAuthDialog.setup(x => x.render());
		mockAutoOAuthDialog.setup(x => x.open(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()));
		mockAutoOAuthDialog.setup(x => x.close()).callback(() => {
			mockOnCloseEvent.fire();
		});

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


		// Create a mocked account management service
		let accountManagementTestService = new AccountManagementTestService();
		mockAccountManagementService = TypeMoq.Mock.ofInstance(accountManagementTestService);
		mockAccountManagementService.setup(x => x.copyUserCodeAndOpenBrowser(TypeMoq.It.isAny(), TypeMoq.It.isAny()));

		// Create a mocked error message service
		let errorMessageServiceStub = new ErrorMessageServiceStub();
		mockErrorMessageService = TypeMoq.Mock.ofInstance(errorMessageServiceStub);
		mockErrorMessageService.setup(x => x.showDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()));

		// Create a mocked auto OAuth dialog controller
		autoOAuthDialogController = new AutoOAuthDialogController(instantiationService.object, mockAccountManagementService.object, mockErrorMessageService.object);

	});

	test('Open auto OAuth when the flyout is already open, return an error', () => {

		// If: Open auto OAuth dialog first time
		autoOAuthDialogController.openAutoOAuthDialog(providerId, title, message, userCode, uri);

		// Then: It should open the flyout successfully
		mockAutoOAuthDialog.verify(x => x.open(title, message, userCode, uri), TypeMoq.Times.once());
		mockErrorMessageService.verify(x => x.showDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.never());

		// If: a oauth flyout is already open
		autoOAuthDialogController.openAutoOAuthDialog(providerId, title, message, userCode, uri);

		// Then: An error dialog should have been opened
		mockErrorMessageService.verify(x => x.showDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.once());
	});

	test('Close auto OAuth dialog successfully', () => {
		let title = 'Add Account';
		let message = 'This is the dialog description';
		let userCode = 'abcde';
		let uri = 'uri';

		autoOAuthDialogController.openAutoOAuthDialog(providerId, title, message, userCode, uri);

		// If: closeAutoOAuthDialog is called
		autoOAuthDialogController.closeAutoOAuthDialog();

		// Then: it should close the dialog
		mockAutoOAuthDialog.verify(x => x.close(), TypeMoq.Times.once());
	});

	test('Open and close auto OAuth dialog multiple times should work properly', () => {
		let title = 'Add Account';
		let message = 'This is the dialog description';
		let userCode = 'abcde';
		let uri = 'uri';

		autoOAuthDialogController.openAutoOAuthDialog(providerId, title, message, userCode, uri);
		autoOAuthDialogController.closeAutoOAuthDialog();

		// If: Open the flyout second time
		autoOAuthDialogController.openAutoOAuthDialog(providerId, title, message, userCode, uri);

		// Then: It should open the flyout twice successfully
//.........這裏部分代碼省略.........
開發者ID:AlexxNica,項目名稱:sqlopsstudio,代碼行數:101,代碼來源:autoOAuthDialogController.test.ts

示例2:

	test('Close auto OAuth dialog successfully', () => {
		let title = 'Add Account';
		let message = 'This is the dialog description';
		let userCode = 'abcde';
		let uri = 'uri';

		autoOAuthDialogController.openAutoOAuthDialog(providerId, title, message, userCode, uri);

		// If: closeAutoOAuthDialog is called
		autoOAuthDialogController.closeAutoOAuthDialog();

		// Then: it should close the dialog
		mockAutoOAuthDialog.verify(x => x.close(), TypeMoq.Times.once());
	});
開發者ID:AlexxNica,項目名稱:sqlopsstudio,代碼行數:14,代碼來源:autoOAuthDialogController.test.ts


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