Skip to content

Commit cb09920

Browse files
authored
[emitter] Move over Azure branded tests to azure-sdk-for-net emitter (Azure#48638)
1 parent 911c07b commit cb09920

File tree

4 files changed

+455
-6
lines changed

4 files changed

+455
-6
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { TestHost } from "@typespec/compiler/testing";
2+
import { UsageFlags } from "@azure-tools/typespec-client-generator-core";
3+
import { strictEqual } from "assert";
4+
import { beforeEach, describe, it } from "vitest";
5+
import { createModel } from "@typespec/http-client-csharp";
6+
import { createCSharpSdkContext, createEmitterContext, createEmitterTestHost, typeSpecCompile, } from "./test-util.js";
7+
8+
describe("Test GetInputType for enum", () => {
9+
let runner: TestHost;
10+
beforeEach(async () => {
11+
runner = await createEmitterTestHost();
12+
});
13+
it("Fixed string enum", async () => {
14+
const program = await typeSpecCompile(`
15+
#suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "Enums should be defined without the @fixed decorator."
16+
@doc("fixed string enum")
17+
@fixed
18+
enum SimpleEnum {
19+
@doc("Enum value one")
20+
One: "1",
21+
@doc("Enum value two")
22+
Two: "2",
23+
@doc("Enum value four")
24+
Four: "4"
25+
}
26+
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Operation 'test' should be defined using a signature from the Azure.Core namespace."
27+
@doc("test fixed enum.")
28+
op test(@doc("fixed enum as input.")@body input: SimpleEnum): string[];
29+
`, runner, { IsNamespaceNeeded: true});
30+
const context = createEmitterContext(program);
31+
const sdkContext = await createCSharpSdkContext(context);
32+
const root = createModel(sdkContext);
33+
const inputParamArray = root.Clients[0].Operations[0].Parameters.filter((p) => p.Name === "input");
34+
strictEqual(1, inputParamArray.length);
35+
const type = inputParamArray[0].Type;
36+
strictEqual(type.kind, "enum");
37+
strictEqual(type.name, "SimpleEnum");
38+
strictEqual(type.isFixed, true);
39+
strictEqual(type.doc, "fixed string enum");
40+
strictEqual(type.crossLanguageDefinitionId, "Azure.Csharp.Testing.SimpleEnum");
41+
strictEqual(type.access, undefined);
42+
strictEqual(type.valueType.kind, "string");
43+
strictEqual(type.values.length, 3);
44+
strictEqual(type.values[0].name, "One");
45+
strictEqual(type.values[0].value, "1");
46+
strictEqual(type.values[1].name, "Two");
47+
strictEqual(type.values[1].value, "2");
48+
strictEqual(type.values[2].name, "Four");
49+
strictEqual(type.values[2].value, "4");
50+
strictEqual(type.usage, UsageFlags.Input | UsageFlags.Json);
51+
});
52+
it("Fixed int enum", async () => {
53+
const program = await typeSpecCompile(`
54+
#suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "Enums should be defined without the @fixed decorator."
55+
@doc("Fixed int enum")
56+
@fixed
57+
enum FixedIntEnum {
58+
@doc("Enum value one")
59+
One: 1,
60+
@doc("Enum value two")
61+
Two: 2,
62+
@doc("Enum value four")
63+
Four: 4
64+
}
65+
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Operation 'test' should be defined using a signature from the Azure.Core namespace."
66+
@doc("test fixed enum.")
67+
op test(@doc("fixed enum as input.")@body input: FixedIntEnum): string[];
68+
`, runner, { IsNamespaceNeeded: true });
69+
const context = createEmitterContext(program);
70+
const sdkContext = await createCSharpSdkContext(context);
71+
const root = createModel(sdkContext);
72+
const inputParamArray = root.Clients[0].Operations[0].Parameters.filter((p) => p.Name === "input");
73+
strictEqual(1, inputParamArray.length);
74+
const type = inputParamArray[0].Type;
75+
strictEqual(type.kind, "enum");
76+
strictEqual(type.name, "FixedIntEnum");
77+
strictEqual(type.crossLanguageDefinitionId, "Azure.Csharp.Testing.FixedIntEnum");
78+
strictEqual(type.access, undefined);
79+
strictEqual(type.doc, "Fixed int enum");
80+
strictEqual(type.valueType.crossLanguageDefinitionId, "TypeSpec.int32");
81+
strictEqual(type.valueType.kind, "int32");
82+
strictEqual(type.values.length, 3);
83+
strictEqual(type.values[0].name, "One");
84+
strictEqual(type.values[0].value, 1);
85+
strictEqual(type.values[1].name, "Two");
86+
strictEqual(type.values[1].value, 2);
87+
strictEqual(type.values[2].name, "Four");
88+
strictEqual(type.values[2].value, 4);
89+
strictEqual(type.isFixed, true);
90+
strictEqual(type.usage, UsageFlags.Input | UsageFlags.Json);
91+
});
92+
});
93+
//# sourceMappingURL=property-type.test.js.map

eng/packages/http-client-csharp/emitter/test/Unit/scalar.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ describe("Test GetInputType for scalar", () => {
2222
op test(@query location: azureLocation): void;
2323
`,
2424
runner,
25-
{ IsAzureCoreNeeded: true },
2625
);
2726
const context = await createCSharpSdkContext(createEmitterContext(program));
2827
const model = createModel(context);

eng/packages/http-client-csharp/emitter/test/Unit/test-util.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export async function createEmitterTestHost(): Promise<TestHost> {
3131

3232
export interface TypeSpecCompileOptions {
3333
IsNamespaceNeeded?: boolean;
34-
IsAzureCoreNeeded?: boolean;
3534
IsTCGCNeeded?: boolean;
3635
IsXmlNeeded?: boolean;
3736
AuthDecorator?: string;
@@ -43,7 +42,6 @@ export async function typeSpecCompile(
4342
options?: TypeSpecCompileOptions,
4443
) {
4544
const needNamespaces = options?.IsNamespaceNeeded ?? true;
46-
const needAzureCore = options?.IsAzureCoreNeeded ?? false;
4745
const needTCGC = options?.IsTCGCNeeded ?? false;
4846
const needXml = options?.IsXmlNeeded ?? false;
4947
const authDecorator =
@@ -58,7 +56,7 @@ export async function typeSpecCompile(
5856
namespace Azure.Csharp.Testing;
5957
6058
enum Versions {
61-
${needAzureCore ? "@useDependency(Azure.Core.Versions.v1_0_Preview_1)" : ""}
59+
${"@useDependency(Azure.Core.Versions.v1_0_Preview_1)"}
6260
"2023-01-01-preview"
6361
}
6462
@@ -68,13 +66,13 @@ export async function typeSpecCompile(
6866
import "@typespec/http";
6967
import "@typespec/versioning";
7068
${needXml ? 'import "@typespec/xml";' : ""}
71-
${needAzureCore ? 'import "@azure-tools/typespec-azure-core";' : ""}
69+
${'import "@azure-tools/typespec-azure-core";'}
7270
${needTCGC ? 'import "@azure-tools/typespec-client-generator-core";' : ""}
7371
using TypeSpec.Rest;
7472
using TypeSpec.Http;
7573
using TypeSpec.Versioning;
7674
${needXml ? "using TypeSpec.Xml;" : ""}
77-
${needAzureCore ? "using Azure.Core;\nusing Azure.Core.Traits;" : ""}
75+
${"using Azure.Core;\nusing Azure.Core.Traits;"}
7876
${needTCGC ? "using Azure.ClientGenerator.Core;" : ""}
7977
8078
${needNamespaces ? namespace : ""}

0 commit comments

Comments
 (0)