你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

LoadTestAdministrationClient.CreateOrUpdateAppComponentsAsync 方法

定义

将应用组件 (azure 资源集合) 关联到测试。

public virtual System.Threading.Tasks.Task<Azure.Response> CreateOrUpdateAppComponentsAsync (string testId, Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member CreateOrUpdateAppComponentsAsync : string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.CreateOrUpdateAppComponentsAsync : string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function CreateOrUpdateAppComponentsAsync (testId As String, content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Response)

参数

testId
String

负载测试的唯一名称只能包含小写字母、数字、下划线或连字符。

content
RequestContent

要作为请求正文发送的内容。 请求正文架构的详细信息,请参阅下面的“备注”部分。

context
RequestContext

请求上下文,可以基于每个调用替代客户端管道的默认行为。

返回

从服务返回的响应。 响应正文架构的详细信息,请参阅下面的“备注”部分。

例外

testIdcontent 为 null。

testId 是一个空字符串,预期为非空。

服务返回了非成功状态代码。

示例

此示例演示如何使用所需的参数调用 CreateOrUpdateAppComponentsAsync 并请求内容并分析结果。

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new LoadTestAdministrationClient(endpoint, credential);

var data = new {
    components = new {
        key = new {
            resourceName = "<resourceName>",
            resourceType = "<resourceType>",
            displayName = "<displayName>",
            kind = "<kind>",
        },
    },
};

Response response = await client.CreateOrUpdateAppComponentsAsync("<testId>", RequestContent.Create(data));

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("components").GetProperty("<test>").GetProperty("resourceId").ToString());
Console.WriteLine(result.GetProperty("components").GetProperty("<test>").GetProperty("resourceName").ToString());
Console.WriteLine(result.GetProperty("components").GetProperty("<test>").GetProperty("resourceType").ToString());
Console.WriteLine(result.GetProperty("components").GetProperty("<test>").GetProperty("displayName").ToString());
Console.WriteLine(result.GetProperty("components").GetProperty("<test>").GetProperty("resourceGroup").ToString());
Console.WriteLine(result.GetProperty("components").GetProperty("<test>").GetProperty("subscriptionId").ToString());
Console.WriteLine(result.GetProperty("components").GetProperty("<test>").GetProperty("kind").ToString());
Console.WriteLine(result.GetProperty("testId").ToString());
Console.WriteLine(result.GetProperty("createdDateTime").ToString());
Console.WriteLine(result.GetProperty("createdBy").ToString());
Console.WriteLine(result.GetProperty("lastModifiedDateTime").ToString());
Console.WriteLine(result.GetProperty("lastModifiedBy").ToString());

注解

下面是请求和响应有效负载的 JSON 架构。

请求正文:

TestAppComponents架构:

{
  components: Dictionary<string, AppComponent>, # Required. Azure resource collection { resource id (fully qualified resource Id e.g subscriptions/{subId}/resourceGroups/{rg}/providers/Microsoft.LoadTestService/loadtests/{resName}) : resource object } 
  testId: string, # Optional. Test identifier
  createdDateTime: string (ISO 8601 Format), # Optional. The creation datetime(ISO 8601 literal format).
  createdBy: string, # Optional. The user that created.
  lastModifiedDateTime: string (ISO 8601 Format), # Optional. The last Modified datetime(ISO 8601 literal format).
  lastModifiedBy: string, # Optional. The user that last modified.
}

响应正文:

TestAppComponents架构:

{
  components: Dictionary<string, AppComponent>, # Required. Azure resource collection { resource id (fully qualified resource Id e.g subscriptions/{subId}/resourceGroups/{rg}/providers/Microsoft.LoadTestService/loadtests/{resName}) : resource object } 
  testId: string, # Optional. Test identifier
  createdDateTime: string (ISO 8601 Format), # Optional. The creation datetime(ISO 8601 literal format).
  createdBy: string, # Optional. The user that created.
  lastModifiedDateTime: string (ISO 8601 Format), # Optional. The last Modified datetime(ISO 8601 literal format).
  lastModifiedBy: string, # Optional. The user that last modified.
}

适用于