Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
972b6c9
converted reactWebviewPanelController tests
Benjin Sep 24, 2025
f026f68
converted userSurvey tests
Benjin Sep 26, 2025
bd20997
test: replace TypeMoq with Sinon in azureResourceService tests
Benjin Sep 26, 2025
7697f8b
converted azureResourceService.test.ts
Benjin Sep 29, 2025
7620780
converted queryNotificationHandler.test.ts
Benjin Sep 29, 2025
bf57343
converted confirm.test.ts
Benjin Sep 29, 2025
dbfa8f6
Converted prompts.test.ts
Benjin Sep 29, 2025
db0f6b1
converting mssqlProtocolHandler.test.ts
Benjin Sep 30, 2025
a7a1de1
converted server.test.ts
Benjin Sep 30, 2025
6a13f03
converted scriptingService.test.ts
Benjin Sep 30, 2025
2232901
converted extConfig.test.ts
Benjin Sep 30, 2025
e6e8c25
converted executionPlanWebviewController.test.ts
Benjin Sep 30, 2025
c1f3236
converted metadataService.test.ts
Benjin Sep 30, 2025
ea97400
converted list.test.ts
Benjin Sep 30, 2025
d22bb94
converted adapter.test.ts
Benjin Sep 30, 2025
81d20d3
converted firewallService.test.ts
Benjin Sep 30, 2025
09ee2c4
converted databaseObjectSearchService.test.ts
Benjin Sep 30, 2025
7edbfa6
cleaned up some tests
Benjin Sep 30, 2025
4886de7
cleaned up list.test.ts
Benjin Sep 30, 2025
1be9d3f
fixed up adapter.test.ts
Benjin Sep 30, 2025
ac5488d
cleaned up firewallService.test.ts
Benjin Sep 30, 2025
9b130ae
added test/unit AGENTS.md
Benjin Sep 30, 2025
ae4e969
Adding AGENTS.md for unit test folder
Benjin Oct 2, 2025
45b3d97
Merge branch 'dev/benjin/convertUnitTestsLongRun' into dev/benjin/age…
Benjin Oct 2, 2025
183831d
converted tableDesigner.test.ts
Benjin Oct 2, 2025
ba44ccd
swapping to correct assertions
Benjin Oct 2, 2025
58e80b4
Merge branch 'main' into dev/benjin/convertTypeMoqTests
Benjin Oct 2, 2025
9963e3f
reverting AGENTS and README
Benjin Oct 3, 2025
bf7ee0c
fixing import for test
Benjin Oct 3, 2025
ed7a4c0
Merge branch 'main' into dev/benjin/convertTypeMoqTests
Benjin Oct 3, 2025
e1cef64
PR feedback
Benjin Oct 15, 2025
f71c0ad
Merge branch 'main' into dev/benjin/convertTypeMoqTests
Benjin Oct 15, 2025
bea2ea5
cleanup
Benjin Oct 15, 2025
83c3042
reverting root AGENTS.md
Benjin Oct 15, 2025
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ The following Visual Studio Code settings are available for the mssql extension.
// Status bar
{
"mssql.statusBar.connectionInfoMaxLength": -1,
"mssql.statusBar.enableConnectionColor": true,
"mssql.enableConnectionColor": true,
}
```

Expand Down
61 changes: 36 additions & 25 deletions test/unit/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from "vscode";
import * as TypeMoq from "typemoq";
import { expect } from "chai";
import * as chai from "chai";
import sinonChai from "sinon-chai";
import * as sinon from "sinon";
import CodeAdapter from "../../src/prompts/adapter";
import VscodeWrapper from "../../src/controllers/vscodeWrapper";
import { IQuestion } from "../../src/prompts/question";
import { stubVscodeWrapper } from "./utils";

chai.use(sinonChai);

suite("Code Adapter Tests", () => {
let sandbox: sinon.SinonSandbox;
let adapter: CodeAdapter;
let outputChannel: TypeMoq.IMock<vscode.OutputChannel>;
let vscodeWrapper: TypeMoq.IMock<VscodeWrapper>;
let mockVscodeWrapper: sinon.SinonStubbedInstance<VscodeWrapper>;

const testMessage = {
message: "test_message",
code: 123,
Expand All @@ -27,53 +33,58 @@ suite("Code Adapter Tests", () => {
};

setup(() => {
vscodeWrapper = TypeMoq.Mock.ofType(VscodeWrapper, TypeMoq.MockBehavior.Loose);
outputChannel = TypeMoq.Mock.ofType<vscode.OutputChannel>();
outputChannel.setup((o) => o.appendLine(TypeMoq.It.isAnyString()));
outputChannel.setup((o) => o.clear());
outputChannel.setup((o) => o.show());
vscodeWrapper.setup((v) => v.outputChannel).returns(() => outputChannel.object);
vscodeWrapper.setup((v) => v.showErrorMessage(TypeMoq.It.isAnyString()));
adapter = new CodeAdapter(vscodeWrapper.object);
sandbox = sinon.createSandbox();
mockVscodeWrapper = stubVscodeWrapper(sandbox);

mockVscodeWrapper.showErrorMessage.resolves(undefined);

adapter = new CodeAdapter(mockVscodeWrapper);
});

teardown(() => {
sandbox.restore();
});

test("logError should append message to the channel", () => {
adapter.logError(testMessage);
outputChannel.verify((o) => o.appendLine(TypeMoq.It.isAnyString()), TypeMoq.Times.once());
expect(mockVscodeWrapper.outputChannel.appendLine).to.have.been.calledOnce;
});

test("log should format message and append to the channel", () => {
adapter.log(testMessage);
outputChannel.verify((o) => o.appendLine(TypeMoq.It.isAnyString()), TypeMoq.Times.once());
expect(mockVscodeWrapper.outputChannel.appendLine).to.have.been.calledOnce;
});

test("clearLog should clear from output channel", () => {
adapter.clearLog();
outputChannel.verify((o) => o.clear(), TypeMoq.Times.once());
expect(mockVscodeWrapper.outputChannel.clear).to.have.been.calledOnce;
});

test("showLog should show the output channel", () => {
adapter.showLog();
outputChannel.verify((o) => o.show(), TypeMoq.Times.once());
expect(mockVscodeWrapper.outputChannel.show).to.have.been.calledOnce;
});

test("promptSingle and promptCallback should call prompt", () => {
void adapter.promptSingle(testQuestion);
test("promptSingle and promptCallback should call prompt", async () => {
await adapter.promptSingle(testQuestion);
adapter.promptCallback([testQuestion], () => true);
// Error case
void adapter.prompt([{ type: "test", message: "test", name: "test" }]);
await adapter.prompt([{ type: "test", message: "test", name: "test" }]);
});

test("prompting a checkbox question should call fixQuestion", () => {
let formattedQuestion: IQuestion = {
test("prompting a checkbox question should call fixQuestion", async () => {
const formattedQuestion: IQuestion = {
type: "checkbox",
message: "test",
name: "test_checkbox",
choices: [{ name: "test_choice", value: "test_choice" }],
};
void adapter.promptSingle(formattedQuestion);
let question: any = Object.assign({}, formattedQuestion);
question.choices[0] = "test";
void adapter.promptSingle(question);
await adapter.promptSingle(formattedQuestion);
const question: IQuestion = {
...formattedQuestion,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
choices: ["test" as any], // Intentionally wrong type to trigger fixQuestion
};
await adapter.promptSingle(question);
});
});
Loading