Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions test/razor/razorIntegrationTests/definition.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as path from 'path';
import * as vscode from 'vscode';
import { beforeAll, afterAll, test, expect, beforeEach } from '@jest/globals';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers';

integrationHelpers.describeIfWindows(`Razor Definition ${testAssetWorkspace.description}`, function () {
beforeAll(async function () {
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
return;
}

await integrationHelpers.activateCSharpExtension();
});

beforeEach(async function () {
await integrationHelpers.openFileInWorkspaceAsync(path.join('Pages', 'Definition.razor'));
});

afterAll(async () => {
await testAssetWorkspace.cleanupWorkspace();
});

test('Go To Definition', async () => {
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
return;
}

const position = new vscode.Position(6, 41);
const locations = <vscode.Location[]>(
await vscode.commands.executeCommand(
'vscode.executeDefinitionProvider',
vscode.window.activeTextEditor!.document.uri,
position
)
);

expect(locations.length).toBe(1);
const definitionLocation = locations[0];

expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path);
expect(definitionLocation.range.start.line).toBe(11);
expect(definitionLocation.range.start.character).toBe(16);
expect(definitionLocation.range.end.line).toBe(11);
expect(definitionLocation.range.end.character).toBe(28);
});

test('Find All References', async () => {
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
return;
}

const position = new vscode.Position(6, 41);
const locations = <vscode.Location[]>(
await vscode.commands.executeCommand(
'vscode.executeReferenceProvider',
vscode.window.activeTextEditor!.document.uri,
position
)
);

expect(locations.length).toBe(3);

let definitionLocation = locations[0];
expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path);
expect(definitionLocation.range.start.line).toBe(6);
expect(definitionLocation.range.start.character).toBe(33);
expect(definitionLocation.range.end.line).toBe(6);
expect(definitionLocation.range.end.character).toBe(45);

definitionLocation = locations[1];
expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path);
expect(definitionLocation.range.start.line).toBe(11);
expect(definitionLocation.range.start.character).toBe(16);
expect(definitionLocation.range.end.line).toBe(11);
expect(definitionLocation.range.end.character).toBe(28);

definitionLocation = locations[2];
expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path);
expect(definitionLocation.range.start.line).toBe(15);
expect(definitionLocation.range.start.character).toBe(8);
expect(definitionLocation.range.end.line).toBe(15);
expect(definitionLocation.range.end.character).toBe(20);
});

test('Go To Implementation', async () => {
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
return;
}

const position = new vscode.Position(18, 18);
const locations = <vscode.Location[]>(
await vscode.commands.executeCommand(
'vscode.executeImplementationProvider',
vscode.window.activeTextEditor!.document.uri,
position
)
);

expect(locations.length).toBe(1);
const definitionLocation = locations[0];

expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path);
expect(definitionLocation.range.start.line).toBe(23);
expect(definitionLocation.range.start.character).toBe(10);
expect(definitionLocation.range.end.line).toBe(23);
expect(definitionLocation.range.end.character).toBe(19);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@page "/definition"

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
private int currentCount = 0;

private void IncrementCount()
{
currentCount++;
}

interface ITestInterface
{
void TestMethod();
}

class TestClass : ITestInterface
{
public void TestMethod()
{
}
}
}