-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[emitter] Move over Azure branded tests to azure-sdk-for-net emitter #48638
Open
nisha-bhatia
wants to merge
1
commit into
Azure:main
Choose a base branch
from
nisha-bhatia:nibhati-movetests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+726
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
161 changes: 161 additions & 0 deletions
161
eng/packages/http-client-csharp/emitter/test/Unit/property-type.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import { TestHost } from "@typespec/compiler/testing"; | ||
import { UsageFlags } from "@azure-tools/typespec-client-generator-core"; | ||
import { strictEqual } from "assert"; | ||
import { beforeEach, describe, it } from "vitest"; | ||
import { createModel } from "@typespec/http-client-csharp"; | ||
import { createCSharpSdkContext, createEmitterContext, createEmitterTestHost, typeSpecCompile, } from "./test-util.js"; | ||
|
||
describe("Test GetInputType for array", () => { | ||
let runner: TestHost; | ||
|
||
beforeEach(async () => { | ||
runner = await createEmitterTestHost(); | ||
}); | ||
it("array as request", async () => { | ||
const program = await typeSpecCompile(` | ||
op test(@body input: string[]): string[]; | ||
`, runner); | ||
const context = createEmitterContext(program); | ||
const sdkContext = await createCSharpSdkContext(context); | ||
const root = createModel(sdkContext); | ||
const inputParamArray = root.Clients[0].Operations[0].Parameters.filter((p) => p.Name === "input"); | ||
strictEqual(1, inputParamArray.length); | ||
const type = inputParamArray[0].Type; | ||
strictEqual(type.kind, "array"); | ||
strictEqual(type.crossLanguageDefinitionId, "TypeSpec.Array"); | ||
strictEqual(type.valueType.kind, "string"); | ||
strictEqual(type.valueType.crossLanguageDefinitionId, "TypeSpec.string"); | ||
}); | ||
it("array as response", async () => { | ||
const program = await typeSpecCompile(` | ||
op test(): string[]; | ||
`, runner); | ||
const context = createEmitterContext(program); | ||
const sdkContext = await createCSharpSdkContext(context); | ||
const root = createModel(sdkContext); | ||
const bodyType = root.Clients[0].Operations[0].Responses[0].BodyType; | ||
strictEqual(bodyType?.kind, "array"); | ||
strictEqual(bodyType.crossLanguageDefinitionId, "TypeSpec.Array"); | ||
strictEqual(bodyType.valueType.kind, "string"); | ||
strictEqual(bodyType.valueType.crossLanguageDefinitionId, "TypeSpec.string"); | ||
}); | ||
}); | ||
describe("Test GetInputType for enum", () => { | ||
let runner; | ||
beforeEach(async () => { | ||
runner = await createEmitterTestHost(); | ||
}); | ||
it("Fixed string enum", async () => { | ||
const program = await typeSpecCompile(` | ||
#suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "Enums should be defined without the @fixed decorator." | ||
@doc("fixed string enum") | ||
@fixed | ||
enum SimpleEnum { | ||
@doc("Enum value one") | ||
One: "1", | ||
@doc("Enum value two") | ||
Two: "2", | ||
@doc("Enum value four") | ||
Four: "4" | ||
} | ||
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Operation 'test' should be defined using a signature from the Azure.Core namespace." | ||
@doc("test fixed enum.") | ||
op test(@doc("fixed enum as input.")@body input: SimpleEnum): string[]; | ||
`, runner, { IsNamespaceNeeded: true, IsAzureCoreNeeded: true }); | ||
const context = createEmitterContext(program); | ||
const sdkContext = await createCSharpSdkContext(context); | ||
const root = createModel(sdkContext); | ||
const inputParamArray = root.Clients[0].Operations[0].Parameters.filter((p) => p.Name === "input"); | ||
strictEqual(1, inputParamArray.length); | ||
const type = inputParamArray[0].Type; | ||
strictEqual(type.kind, "enum"); | ||
strictEqual(type.name, "SimpleEnum"); | ||
strictEqual(type.isFixed, true); | ||
strictEqual(type.doc, "fixed string enum"); | ||
strictEqual(type.crossLanguageDefinitionId, "Azure.Csharp.Testing.SimpleEnum"); | ||
strictEqual(type.access, undefined); | ||
strictEqual(type.valueType.kind, "string"); | ||
strictEqual(type.values.length, 3); | ||
strictEqual(type.values[0].name, "One"); | ||
strictEqual(type.values[0].value, "1"); | ||
strictEqual(type.values[1].name, "Two"); | ||
strictEqual(type.values[1].value, "2"); | ||
strictEqual(type.values[2].name, "Four"); | ||
strictEqual(type.values[2].value, "4"); | ||
strictEqual(type.usage, UsageFlags.Input | UsageFlags.Json); | ||
}); | ||
it("Fixed int enum", async () => { | ||
const program = await typeSpecCompile(` | ||
#suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "Enums should be defined without the @fixed decorator." | ||
@doc("Fixed int enum") | ||
@fixed | ||
enum FixedIntEnum { | ||
@doc("Enum value one") | ||
One: 1, | ||
@doc("Enum value two") | ||
Two: 2, | ||
@doc("Enum value four") | ||
Four: 4 | ||
} | ||
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Operation 'test' should be defined using a signature from the Azure.Core namespace." | ||
@doc("test fixed enum.") | ||
op test(@doc("fixed enum as input.")@body input: FixedIntEnum): string[]; | ||
`, runner, { IsNamespaceNeeded: true, IsAzureCoreNeeded: true }); | ||
const context = createEmitterContext(program); | ||
const sdkContext = await createCSharpSdkContext(context); | ||
const root = createModel(sdkContext); | ||
const inputParamArray = root.Clients[0].Operations[0].Parameters.filter((p) => p.Name === "input"); | ||
strictEqual(1, inputParamArray.length); | ||
const type = inputParamArray[0].Type; | ||
strictEqual(type.kind, "enum"); | ||
strictEqual(type.name, "FixedIntEnum"); | ||
strictEqual(type.crossLanguageDefinitionId, "Azure.Csharp.Testing.FixedIntEnum"); | ||
strictEqual(type.access, undefined); | ||
strictEqual(type.doc, "Fixed int enum"); | ||
strictEqual(type.valueType.crossLanguageDefinitionId, "TypeSpec.int32"); | ||
strictEqual(type.valueType.kind, "int32"); | ||
strictEqual(type.values.length, 3); | ||
strictEqual(type.values[0].name, "One"); | ||
strictEqual(type.values[0].value, 1); | ||
strictEqual(type.values[1].name, "Two"); | ||
strictEqual(type.values[1].value, 2); | ||
strictEqual(type.values[2].name, "Four"); | ||
strictEqual(type.values[2].value, 4); | ||
strictEqual(type.isFixed, true); | ||
strictEqual(type.usage, UsageFlags.Input | UsageFlags.Json); | ||
}); | ||
it("fixed enum", async () => { | ||
const program = await typeSpecCompile(` | ||
@doc("Fixed enum") | ||
enum FixedEnum { | ||
One: "1", | ||
Two: "2", | ||
Four: "4" | ||
} | ||
op test(@body input: FixedEnum): string[]; | ||
`, runner); | ||
const context = createEmitterContext(program); | ||
const sdkContext = await createCSharpSdkContext(context); | ||
const root = createModel(sdkContext); | ||
const inputParamArray = root.Clients[0].Operations[0].Parameters.filter((p) => p.Name === "input"); | ||
strictEqual(1, inputParamArray.length); | ||
const type = inputParamArray[0].Type; | ||
strictEqual(type.kind, "enum"); | ||
strictEqual(type.name, "FixedEnum"); | ||
strictEqual(type.crossLanguageDefinitionId, "Azure.Csharp.Testing.FixedEnum"); | ||
strictEqual(type.access, undefined); | ||
strictEqual(type.doc, "Fixed enum"); | ||
strictEqual(type.valueType.kind, "string"); | ||
strictEqual(type.valueType.crossLanguageDefinitionId, "TypeSpec.string"); | ||
strictEqual(type.values.length, 3); | ||
strictEqual(type.values[0].name, "One"); | ||
strictEqual(type.values[0].value, "1"); | ||
strictEqual(type.values[1].name, "Two"); | ||
strictEqual(type.values[1].value, "2"); | ||
strictEqual(type.values[2].name, "Four"); | ||
strictEqual(type.values[2].value, "4"); | ||
strictEqual(type.usage, UsageFlags.Input | UsageFlags.Json); | ||
strictEqual(type.isFixed, true); | ||
}); | ||
}); | ||
//# sourceMappingURL=property-type.test.js.map |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like it is Azure-specific.