本文整理汇总了TypeScript中typemoq.Mock类的典型用法代码示例。如果您正苦于以下问题:TypeScript Mock类的具体用法?TypeScript Mock怎么用?TypeScript Mock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mock类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const mockEmailQueue = () => {
const emailMock = TypeMoq.Mock.ofType(EmailQueue);
emailMock.setup(x => x.addJob(TypeMoq.It.isAny()))
.returns((): any => null);
container.rebind<EmailQueueInterface>(EmailQueueType).toConstantValue(emailMock.object);
};
示例2: getMockErrorMessageService
function getMockErrorMessageService(deferredPromise: Deferred<{}>): TypeMoq.Mock<ErrorMessageServiceStub> {
let errorMessageServiceStub = new ErrorMessageServiceStub();
let mockErrorMessageService = TypeMoq.Mock.ofInstance(errorMessageServiceStub);
mockErrorMessageService.setup(x => x.showDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).callback(() => {
deferredPromise.resolve(true);
});
return mockErrorMessageService;
}
示例3: test
test('getCurrentGlobalConnection returns the connection from OE if there is no active tab, even if OE is not focused', () => {
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 oeProfile = new ConnectionProfile(undefined, connectionProfile);
mockObjectExplorerService.setup(x => x.isFocused()).returns(() => false);
mockObjectExplorerService.setup(x => x.getSelectedProfileAndDatabase()).returns(() => {
return { profile: oeProfile, databaseName: undefined };
});
mockConnectionManagementService.setup(x => x.isProfileConnected(TypeMoq.It.is(profile => profile === oeProfile))).returns(() => true);
mockWorkbenchEditorService.setup(x => x.getActiveEditorInput()).returns(() => undefined);
// If I call getCurrentGlobalConnection, it should return the expected profile from OE
let actualProfile = TaskUtilities.getCurrentGlobalConnection(mockObjectExplorerService.object, mockConnectionManagementService.object, mockWorkbenchEditorService.object);
assert.equal(actualProfile, oeProfile);
});
示例4: test
test('getSelectedProfileAndDatabase returns undefined when there is no selection', () => {
let serverTreeView = TypeMoq.Mock.ofInstance({ getSelection: () => undefined, onSelectionOrFocusChange: Event.None } as ServerTreeView);
serverTreeView.setup(x => x.getSelection()).returns(() => []);
objectExplorerService.registerServerTreeView(serverTreeView.object);
let selectedProfileAndDatabase = objectExplorerService.getSelectedProfileAndDatabase();
assert.equal(selectedProfileAndDatabase, undefined);
});
示例5: getMockLineNumberTransformer
export function getMockLineNumberTransformer(): IMock<LineColTransformer> {
const mock = Mock.ofType(LineColTransformer);
mock.setup(m => m.setBreakpoints(It.isAny()))
.returns(args => args);
return mock;
}
示例6: it
it('logs info messages', () => {
const consoleProxy = TypeMoq.Mock.ofType<ConsoleProxy>();
const consoleSink = new ConsoleSink({ consoleProxy: consoleProxy.object });
consoleSink.emit([
new LogEvent('', LogEventLevel.information, new MessageTemplate('Test'))
]);
consoleProxy.verify(m => m.info(TypeMoq.It.isAny()), TypeMoq.Times.once());
});
示例7: setup
setup(() => {
// Mock ConnectionManagementService but don't set connected state
memento = TypeMoq.Mock.ofType(Memento, TypeMoq.MockBehavior.Loose, '');
memento.setup(x => x.getMemento(TypeMoq.It.isAny())).returns(() => void 0);
queryConnectionService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Loose, memento.object, undefined);
queryConnectionService.callBase = true;
// Mock InstantiationService to give us the actions
queryActionInstantiationService = TypeMoq.Mock.ofType(InstantiationService, TypeMoq.MockBehavior.Loose);
queryActionInstantiationService.setup(x => x.createInstance(TypeMoq.It.isAny())).returns((input) => {
return new TPromise((resolve) => resolve(mockEditor));
});
queryActionInstantiationService.setup(x => x.createInstance(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((input) => {
// Default
return new RunQueryAction(undefined, undefined, undefined);
});
// Setup hook to capture calls to create the listDatabase action
queryActionInstantiationService.setup(x => x.createInstance(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns((definition, editor, action, selectBox) => {
if (definition.ID === 'listDatabaseQueryActionItem') {
let item = new ListDatabasesActionItem(editor, action, queryConnectionService.object, undefined, undefined, undefined,configurationService.object);
return item;
}
// Default
return new RunQueryAction(undefined, undefined, undefined);
});
let fileInput = new UntitledEditorInput(URI.parse('testUri'), false, '', '', '', instantiationService.object, undefined, undefined, undefined);
queryModelService = TypeMoq.Mock.ofType(QueryModelService, TypeMoq.MockBehavior.Loose, undefined, undefined);
queryModelService.callBase = true;
queryInput = new QueryInput(
'',
fileInput,
undefined,
undefined,
undefined,
queryModelService.object,
undefined,
undefined
);
});
示例8: it
it("should stop download on stop command", inject([MainViewComponent], (mainView) => {
var isCalled = false;
listDownloaderMock.setup(c => c.stopDownload()).callback(() => isCalled = true);
mainView.audioList = [];
mainView.onViewStopClick();
expect(isCalled).toBe(true, "stopDownload should be called");
}));
示例9: it
it('logs error messages', () => {
const consoleProxy = TypeMoq.Mock.ofType<ConsoleProxy>();
const consoleSink = new ConsoleSink({ console: consoleProxy.object });
consoleSink.emit([
new LogEvent('', LogEventLevel.fatal, new MessageTemplate('Test')),
new LogEvent('', LogEventLevel.error, new MessageTemplate('Test'))
]);
consoleProxy.verify(m => m.error(TypeMoq.It.isAny()), TypeMoq.Times.exactly(2));
});
示例10: test
test("Logger posts log message to channel", () => {
let mockChannel = TypeMoq.Mock.ofType<OutputChannel>();
mockChannel.setup(c => c.appendLine(TypeMoq.It.isAnyString())).verifiable(TypeMoq.Times.once());
let logger = new Logger(mockChannel.object);
logger.log("Test message");
mockChannel.verifyAll();
});