Skip to content

Commit

Permalink
Add Lro\Rpc Test (#5108)
Browse files Browse the repository at this point in the history
* update

* Update rpc.cs

* regenrate

* Update rpc.cs
  • Loading branch information
mcgallan authored Oct 17, 2024
1 parent 6835b74 commit fb25b1b
Show file tree
Hide file tree
Showing 23 changed files with 2,451 additions and 0 deletions.
1 change: 1 addition & 0 deletions eng/testProjects.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"azure/resource-manager/models/resources",
"azure/core/basic",
"azure/core/lro/standard",
"azure/core/lro/rpc",
"azure/core/scalar",
"azure/core/traits",
"azure/core/model",
Expand Down
4 changes: 4 additions & 0 deletions src/AutoRest.CSharp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,10 @@
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\azure\\core\\basic\\src\\Generated -n"
},
"typespec-azure/core/lro/rpc": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\azure\\core\\lro\\rpc\\src\\Generated -n"
},
"typespec-azure/core/lro/standard": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\azure\\core\\lro\\standard\\src\\Generated -n"
Expand Down
36 changes: 36 additions & 0 deletions test/CadlRanchProjects.Tests/lro/rpc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Threading.Tasks;
using _Azure.Lro.Rpc;
using _Azure.Lro.Rpc.Models;
using AutoRest.TestServer.Tests.Infrastructure;
using Azure;
using NUnit.Framework;

namespace CadlRanchProjects.Tests.lro
{
public class LongRunningOperation : CadlRanchTestBase
{
[Test]
public Task LongRunningRpc_Completed() => Test(async (host) =>
{
var option = new GenerationOptions("text");
var response = await new RpcClient(host, null).LongRunningRpcAsync(WaitUntil.Completed, option);
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual("text data", response.Value.Data);
});

[Test]
public Task LongRunningRpc_Started() => Test(async (host) =>
{
var option = new GenerationOptions("text");
var response = await new RpcClient(host, null).LongRunningRpcAsync(WaitUntil.Started, option);
Assert.AreEqual(202, response.GetRawResponse().Status);
Assert.AreEqual(true, response.GetRawResponse().Headers.TryGetValue("operation-location", out string operationLocation));
Assert.AreEqual(true, operationLocation.Contains("/azure/core/lro/rpc/generations/operations/operation1"));
});


}
}
11 changes: 11 additions & 0 deletions test/CadlRanchProjects/azure/core/lro/rpc/Configuration.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions test/CadlRanchProjects/azure/core/lro/rpc/_Azure.Lro.Rpc.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_Azure.Lro.Rpc", "src\_Azure.Lro.Rpc.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_Azure.Lro.Rpc.Tests", "tests\_Azure.Lro.Rpc.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
EndGlobalSection
EndGlobal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<doc>
<members>
<member name="LongRunningRpcAsync(WaitUntil,GenerationOptions,CancellationToken)">
<example>
This sample shows how to call LongRunningRpcAsync.
<code><![CDATA[
RpcClient client = new RpcClient();
GenerationOptions body = new GenerationOptions("<prompt>");
Operation<GenerationResult> operation = await client.LongRunningRpcAsync(WaitUntil.Completed, body);
GenerationResult responseData = operation.Value;
]]></code>
This sample shows how to call LongRunningRpcAsync with all parameters.
<code><![CDATA[
RpcClient client = new RpcClient();
GenerationOptions body = new GenerationOptions("<prompt>");
Operation<GenerationResult> operation = await client.LongRunningRpcAsync(WaitUntil.Completed, body);
GenerationResult responseData = operation.Value;
]]></code></example>
</member>
<member name="LongRunningRpc(WaitUntil,GenerationOptions,CancellationToken)">
<example>
This sample shows how to call LongRunningRpc.
<code><![CDATA[
RpcClient client = new RpcClient();
GenerationOptions body = new GenerationOptions("<prompt>");
Operation<GenerationResult> operation = client.LongRunningRpc(WaitUntil.Completed, body);
GenerationResult responseData = operation.Value;
]]></code>
This sample shows how to call LongRunningRpc with all parameters.
<code><![CDATA[
RpcClient client = new RpcClient();
GenerationOptions body = new GenerationOptions("<prompt>");
Operation<GenerationResult> operation = client.LongRunningRpc(WaitUntil.Completed, body);
GenerationResult responseData = operation.Value;
]]></code></example>
</member>
<member name="LongRunningRpcAsync(WaitUntil,RequestContent,RequestContext)">
<example>
This sample shows how to call LongRunningRpcAsync and parse the result.
<code><![CDATA[
RpcClient client = new RpcClient();
using RequestContent content = RequestContent.Create(new
{
prompt = "<prompt>",
});
Operation<BinaryData> operation = await client.LongRunningRpcAsync(WaitUntil.Completed, content);
BinaryData responseData = operation.Value;
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("data").ToString());
]]></code>
This sample shows how to call LongRunningRpcAsync with all parameters and request content and parse the result.
<code><![CDATA[
RpcClient client = new RpcClient();
using RequestContent content = RequestContent.Create(new
{
prompt = "<prompt>",
});
Operation<BinaryData> operation = await client.LongRunningRpcAsync(WaitUntil.Completed, content);
BinaryData responseData = operation.Value;
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("data").ToString());
]]></code></example>
</member>
<member name="LongRunningRpc(WaitUntil,RequestContent,RequestContext)">
<example>
This sample shows how to call LongRunningRpc and parse the result.
<code><![CDATA[
RpcClient client = new RpcClient();
using RequestContent content = RequestContent.Create(new
{
prompt = "<prompt>",
});
Operation<BinaryData> operation = client.LongRunningRpc(WaitUntil.Completed, content);
BinaryData responseData = operation.Value;
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("data").ToString());
]]></code>
This sample shows how to call LongRunningRpc with all parameters and request content and parse the result.
<code><![CDATA[
RpcClient client = new RpcClient();
using RequestContent content = RequestContent.Create(new
{
prompt = "<prompt>",
});
Operation<BinaryData> operation = client.LongRunningRpc(WaitUntil.Completed, content);
BinaryData responseData = operation.Value;
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("data").ToString());
]]></code></example>
</member>
</members>
</doc>
Loading

0 comments on commit fb25b1b

Please sign in to comment.