本文整理汇总了TypeScript中typemoq.Mock.ofType方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Mock.ofType方法的具体用法?TypeScript Mock.ofType怎么用?TypeScript Mock.ofType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typemoq.Mock
的用法示例。
在下文中一共展示了Mock.ofType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: buildApp
export const testAppForInitiateLogin = () => {
const verifyMock = TypeMoq.Mock.ofType(VerificationClient);
const authMock = TypeMoq.Mock.ofType(AuthClient);
const initiateResult: InitiateResult = {
status: 200,
verificationId: '123',
attempts: 0,
expiredOn: 124545,
method: 'email'
};
const loginResult: AccessTokenResponse = {
accessToken: 'token'
};
verifyMock.setup(x => x.initiateVerification(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(async(): Promise<InitiateResult> => initiateResult);
authMock.setup(x => x.loginUser(TypeMoq.It.isAny()))
.returns(async(): Promise<AccessTokenResponse> => loginResult);
container.rebind<VerificationClientInterface>(VerificationClientType).toConstantValue(verifyMock.object);
container.rebind<AuthClientInterface>(AuthClientType).toConstantValue(authMock.object);
return buildApp();
};
示例2: test
test('ManageConnectionAction - test if connect is called for manage action if not already connected', (done) => {
let isConnectedReturnValue: boolean = false;
let connection: ConnectionProfile = new ConnectionProfile(capabilitiesService, {
connectionName: 'Test',
savePassword: false,
groupFullName: 'testGroup',
serverName: 'testServerName',
databaseName: 'testDatabaseName',
authenticationType: 'integrated',
password: 'test',
userName: 'testUsername',
groupId: undefined,
providerName: 'MSSQL',
options: {},
saveProfile: true,
id: 'testId'
});
let connectionManagementService = createConnectionManagementService(isConnectedReturnValue, connection);
let objectExplorerService = createObjectExplorerService(connectionManagementService.object, undefined);
let treeSelectionMock = TypeMoq.Mock.ofType(TreeSelectionHandler);
let instantiationService = TypeMoq.Mock.ofType(InstantiationService, TypeMoq.MockBehavior.Loose);
instantiationService.setup(x => x.createInstance(TypeMoq.It.isAny())).returns((input) => {
return treeSelectionMock.object;
});
let manageConnectionAction: ManageConnectionAction = new ManageConnectionAction(ManageConnectionAction.ID,
ManageConnectionAction.LABEL, undefined, connectionManagementService.object, capabilitiesService, instantiationService.object, objectExplorerService.object);
var actionContext = new ObjectExplorerActionsContext();
actionContext.connectionProfile = connection.toIConnectionProfile();
actionContext.isConnectionNode = true;
manageConnectionAction.run(actionContext).then((value) => {
connectionManagementService.verify(x => x.connect(TypeMoq.It.isAny(), undefined, TypeMoq.It.isAny(), undefined), TypeMoq.Times.once());
}).then(() => done(), (err) => done(err));
});
示例3: beforeEach
beforeEach(() => {
holder = {};
projectionRunner = Mock.ofType(MockProjectionRunner);
holder["Mock"] = projectionRunner.object;
request = new MockRequest();
response = Mock.ofType<IResponse>();
});
示例4: test
test('getCurrentGlobalConnection returns the connection from the active tab, if there is one and 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);
let connectionProfile2 = Object.assign({}, connectionProfile);
connectionProfile2.serverName = 'test_server_2';
connectionProfile2.id = 'test_id_2';
let tabProfile = new ConnectionProfile(undefined, connectionProfile2);
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 || profile === tabProfile))).returns(() => true);
// Mock the workbench service to return the active tab connection
let tabConnectionUri = 'test_uri';
let editorInput = new UntitledEditorInput(URI.parse(tabConnectionUri), false, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined);
let queryInput = new QueryInput(undefined, undefined, editorInput, undefined, undefined, undefined, undefined, undefined);
mockWorkbenchEditorService.setup(x => x.getActiveEditorInput()).returns(() => queryInput);
mockConnectionManagementService.setup(x => x.getConnectionProfile(tabConnectionUri)).returns(() => tabProfile);
// If I call getCurrentGlobalConnection, it should return the expected profile from the active tab
let actualProfile = TaskUtilities.getCurrentGlobalConnection(mockObjectExplorerService.object, mockConnectionManagementService.object, mockWorkbenchEditorService.object);
assert.equal(actualProfile.databaseName, tabProfile.databaseName);
assert.equal(actualProfile.authenticationType, tabProfile.authenticationType);
assert.equal(actualProfile.password, tabProfile.password);
assert.equal(actualProfile.serverName, tabProfile.serverName);
assert.equal(actualProfile.userName, tabProfile.userName);
});
示例5: it
it('queues events if a flush is in progress', () => {
let emittedEvents = [];
const pipeline = new Pipeline();
const pipelineStage1 = TypeMoq.Mock.ofType<PipelineStage>();
const pipelineStage2 = TypeMoq.Mock.ofType<PipelineStage>();
pipelineStage1.setup(m => m.emit(TypeMoq.It.isAny())).returns(events => events);
pipelineStage1.setup(m => m.flush()).returns(() => new Promise(resolve => setTimeout(resolve, 1)));
pipelineStage2.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));
pipelineStage2.setup(m => m.flush()).returns(() => Promise.resolve());
pipeline.addStage(pipelineStage1.object);
pipeline.addStage(pipelineStage2.object);
const events = [
new LogEvent('', LogEventLevel.information, new MessageTemplate('Message 1'), {}),
new LogEvent('', LogEventLevel.information, new MessageTemplate('Message 2'), {}),
new LogEvent('', LogEventLevel.information, new MessageTemplate('Message 3'), {}),
new LogEvent('', LogEventLevel.information, new MessageTemplate('Message 4'), {})
];
return pipeline.emit(events.slice(0, 2))
.then(() => {
expect(emittedEvents).to.have.length(2);
expect(emittedEvents[0]).to.have.deep.property('messageTemplate.raw', 'Message 1');
expect(emittedEvents[1]).to.have.deep.property('messageTemplate.raw', 'Message 2');
})
.then(() => Promise.all([pipeline.flush(), pipeline.emit(events.slice(2))]))
.then(() => {
expect(emittedEvents).to.have.length(4);
expect(emittedEvents[2]).to.have.deep.property('messageTemplate.raw', 'Message 3');
expect(emittedEvents[3]).to.have.deep.property('messageTemplate.raw', 'Message 4');
});
});
示例6: beforeEach
beforeEach(() => {
factory = Mock.ofType<IViewModelFactory>();
uriResolver = Mock.ofType<IUriResolver>();
viewResolver = Mock.ofType<IViewResolver>();
serializer = Mock.ofType<ISerializer<Dictionary<string>,string>>();
subject = new ContextFactory(uriResolver.object, viewResolver.object, factory.object, serializer.object);
});
示例7: mockEmailQueue
export const testAppForVerifyLogin = () => {
mockEmailQueue();
const authMock = TypeMoq.Mock.ofType(AuthClient);
const verifyTokenResultNotVerified = {
login: 'activated@test.com'
};
authMock.setup(x => x.verifyUserToken(TypeMoq.It.isValue('not_verified_token')))
.returns(async(): Promise<any> => verifyTokenResultNotVerified);
const verifyMock = TypeMoq.Mock.ofType(VerificationClient);
const initiateResult: InitiateResult = {
status: 200,
verificationId: '123',
attempts: 0,
expiredOn: 124545,
method: 'email'
};
verifyMock.setup(x => x.initiateVerification(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(async(): Promise<InitiateResult> => initiateResult);
container.rebind<VerificationClientInterface>(VerificationClientType).toConstantValue(verifyMock.object);
container.rebind<AuthClientInterface>(AuthClientType).toConstantValue(authMock.object);
return buildApp();
};
示例8: beforeEach
beforeEach(() => {
registry = Mock.ofType<IViewModelRegistry>();
componentFactory = Mock.ofType<IPageComponentFactory>();
componentFactory.setup(c => c.componentForUri(It.isAny())).returns(() => null);
componentFactory.setup(c => c.componentForMaster()).returns(() => null);
componentFactory.setup(c => c.componentForNotFound()).returns(() => null);
subject = new RoutingAdapter(registry.object, componentFactory.object, null);
});
示例9: beforeEach
beforeEach(() => {
client = Mock.ofType<ISocketClient>();
registry = Mock.ofType<IProjectionRegistry>();
subject = new ClientRegistry(registry.object);
let projection = new ClientRegistryDefinition().define();
registry.setup(r => r.projectionFor("Foo", "Admin")).returns(() => ["Admin", projection]);
registry.setup(r => r.projectionFor("Bar", "Admin")).returns(() => ["Admin", projection]);
registry.setup(r => r.projectionFor("KeyUndefined", "Admin")).returns(() => ["Admin", projection]);
});
示例10: beforeEach
beforeEach(() => {
let filter = Mock.ofType<IIdempotenceFilter>();
filter.setup(f => f.serialize()).returns(() => [
{id: "test", timestamp: new Date(2)}
]);
mementoProducer = Mock.ofType<IMementoProducer<any>>();
subject = new SnapshotProducer({
"Mock": filter.object
}, mementoProducer.object);
});
示例11: beforeEach
beforeEach(() => {
requestHandler = Mock.ofType<IRequestHandler>();
routeResolver = Mock.ofType<IRouteResolver>();
request = new MockRequest();
request.method = "GET";
request.originalRequest = undefined;
response = Mock.ofType<IResponse>();
response.setup(r => r.status(anyValue)).returns(() => response.object);
subject = new RequestAdapter(routeResolver.object);
});
示例12: beforeEach
beforeEach(() => {
registry = Mock.ofType<IProjectionRegistry>();
request = new MockRequest();
response = Mock.ofType<IResponse>();
subject = new ProjectionsListHandler(registry.object);
registry.setup(r => r.projections()).returns(() => [
["Admin", {name: "Test", definition: {}, publish: {}}],
["Admin", {name: "Test2", definition: {}, publish: {}}]
]);
});
示例13: it
it('catches errors when suppressed', () => {
let loggedEvents = [];
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const logger = new Logger(TypeMoq.Mock.ofType<Pipeline>().object);
expect(() => logger.fatal(undefined)).to.not.throw();
expect(() => logger.error(undefined)).to.not.throw();
expect(() => logger.warn(undefined)).to.not.throw();
expect(() => logger.info(undefined)).to.not.throw();
expect(() => logger.debug(undefined)).to.not.throw();
expect(() => logger.verbose(undefined)).to.not.throw();
});
示例14: beforeEach
beforeEach(() => {
projectionRunner = Mock.ofType(MockProjectionRunner);
dateRetriever = Mock.ofType<IDateRetriever>();
holder = {};
holder["projection"] = projectionRunner.object;
request = new MockRequest();
response = Mock.ofType<IResponse>();
response.setup(s => s.status(It.isAny())).returns(a => response.object);
snapshotRepository = Mock.ofType<ISnapshotRepository>();
snapshotRepository.setup(s => s.saveSnapshot(It.isAny(), It.isAny())).returns(() => Promise.resolve());
snapshotRepository.setup(s => s.deleteSnapshot(It.isAny())).returns(() => Promise.resolve());
});
示例15: beforeEach
beforeEach(() => {
locationNavigator = TypeMoq.Mock.ofType(MockLocationNavigator);
settingsManager = TypeMoq.Mock.ofType(MockSettingsManager);
subject = new Auth0Provider({
clientNamespace: "test.auth0.com",
logoutCallbackUrl: "http://localhost",
loginCallbackUrl: "http://localhost",
renewCallbackUrl: "http://localhost",
clientId: "test",
audience: "test-audience"
}, settingsManager.object, locationNavigator.object);
});