Skip to content

Commit b1471bd

Browse files
kashish2508guptakashish
andauthored
feat(loadtestservice): added create test run logic for activity log (Azure#51577)
* Generated Client * updated client * client generate * Test run client name updated * Revert "Test run client name updated" This reverts commit 6e27760. * clientName update * update * added patch test run call * updated test --------- Co-authored-by: guptakashish <[email protected]>
1 parent 101878f commit b1471bd

File tree

15 files changed

+755
-140
lines changed

15 files changed

+755
-140
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// <auto-generated/>
5+
6+
#nullable disable
7+
8+
using System;
9+
using System.Diagnostics.CodeAnalysis;
10+
using Azure.Core.Extensions;
11+
using Azure.Developer.Playwright;
12+
13+
namespace Microsoft.Extensions.Azure
14+
{
15+
/// <summary> Extension methods to add <see cref="TestRunUpdateClient"/> to client builder. </summary>
16+
internal static partial class DeveloperPlaywrightClientBuilderExtensions
17+
{
18+
/// <summary> Registers a <see cref="TestRunUpdateClient"/> instance. </summary>
19+
/// <param name="builder"> The builder to register with. </param>
20+
/// <param name="endpoint"> server parameter. </param>
21+
public static IAzureClientBuilder<TestRunUpdateClient, TestRunUpdateClientOptions> AddTestRunUpdateClient<TBuilder>(this TBuilder builder, Uri endpoint)
22+
where TBuilder : IAzureClientFactoryBuilder
23+
{
24+
return builder.RegisterClientFactory<TestRunUpdateClient, TestRunUpdateClientOptions>((options) => new TestRunUpdateClient(endpoint, options));
25+
}
26+
27+
/// <summary> Registers a <see cref="TestRunUpdateClient"/> instance. </summary>
28+
/// <param name="builder"> The builder to register with. </param>
29+
/// <param name="configuration"> The configuration values. </param>
30+
[RequiresUnreferencedCode("Requires unreferenced code until we opt into EnableConfigurationBindingGenerator.")]
31+
[RequiresDynamicCode("Requires unreferenced code until we opt into EnableConfigurationBindingGenerator.")]
32+
public static IAzureClientBuilder<TestRunUpdateClient, TestRunUpdateClientOptions> AddTestRunUpdateClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration)
33+
where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration>
34+
{
35+
return builder.RegisterClientFactory<TestRunUpdateClient, TestRunUpdateClientOptions>(configuration);
36+
}
37+
}
38+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// <auto-generated/>
5+
6+
#nullable disable
7+
8+
using System;
9+
using System.Collections;
10+
using System.Collections.Generic;
11+
12+
namespace Azure.Developer.Playwright
13+
{
14+
internal static class Argument
15+
{
16+
public static void AssertNotNull<T>(T value, string name)
17+
{
18+
if (value is null)
19+
{
20+
throw new ArgumentNullException(name);
21+
}
22+
}
23+
24+
public static void AssertNotNull<T>(T? value, string name)
25+
where T : struct
26+
{
27+
if (!value.HasValue)
28+
{
29+
throw new ArgumentNullException(name);
30+
}
31+
}
32+
33+
public static void AssertNotNullOrEmpty<T>(IEnumerable<T> value, string name)
34+
{
35+
if (value is null)
36+
{
37+
throw new ArgumentNullException(name);
38+
}
39+
if (value is ICollection<T> collectionOfT && collectionOfT.Count == 0)
40+
{
41+
throw new ArgumentException("Value cannot be an empty collection.", name);
42+
}
43+
if (value is ICollection collection && collection.Count == 0)
44+
{
45+
throw new ArgumentException("Value cannot be an empty collection.", name);
46+
}
47+
using IEnumerator<T> e = value.GetEnumerator();
48+
if (!e.MoveNext())
49+
{
50+
throw new ArgumentException("Value cannot be an empty collection.", name);
51+
}
52+
}
53+
54+
public static void AssertNotNullOrEmpty(string value, string name)
55+
{
56+
if (value is null)
57+
{
58+
throw new ArgumentNullException(name);
59+
}
60+
if (value.Length == 0)
61+
{
62+
throw new ArgumentException("Value cannot be an empty string.", name);
63+
}
64+
}
65+
66+
public static void AssertNotNullOrWhiteSpace(string value, string name)
67+
{
68+
if (value is null)
69+
{
70+
throw new ArgumentNullException(name);
71+
}
72+
if (string.IsNullOrWhiteSpace(value))
73+
{
74+
throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name);
75+
}
76+
}
77+
78+
public static void AssertNotDefault<T>(ref T value, string name)
79+
where T : struct, IEquatable<T>
80+
{
81+
if (value.Equals(default))
82+
{
83+
throw new ArgumentException("Value cannot be empty.", name);
84+
}
85+
}
86+
87+
public static void AssertInRange<T>(T value, T minimum, T maximum, string name)
88+
where T : notnull, IComparable<T>
89+
{
90+
if (minimum.CompareTo(value) > 0)
91+
{
92+
throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed.");
93+
}
94+
if (maximum.CompareTo(value) < 0)
95+
{
96+
throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed.");
97+
}
98+
}
99+
100+
public static void AssertEnumDefined(Type enumType, object value, string name)
101+
{
102+
if (!Enum.IsDefined(enumType, value))
103+
{
104+
throw new ArgumentException($"Value not defined for {enumType.FullName}.", name);
105+
}
106+
}
107+
108+
public static T CheckNotNull<T>(T value, string name)
109+
where T : class
110+
{
111+
AssertNotNull(value, name);
112+
return value;
113+
}
114+
115+
public static string CheckNotNullOrEmpty(string value, string name)
116+
{
117+
AssertNotNullOrEmpty(value, name);
118+
return value;
119+
}
120+
121+
public static void AssertNull<T>(T value, string name, string message = null)
122+
{
123+
if (value != null)
124+
{
125+
throw new ArgumentException(message ?? "Value must be null.", name);
126+
}
127+
}
128+
}
129+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// <auto-generated/>
5+
6+
#nullable disable
7+
8+
using System;
9+
using System.Threading.Tasks;
10+
using Azure.Core;
11+
using Azure.Core.Pipeline;
12+
13+
namespace Azure.Developer.Playwright
14+
{
15+
// Data plane generated client.
16+
/// <summary> The TestRunUpdate service client. </summary>
17+
internal partial class TestRunUpdateClient
18+
{
19+
private readonly HttpPipeline _pipeline;
20+
private readonly Uri _endpoint;
21+
private readonly string _apiVersion;
22+
23+
/// <summary> The ClientDiagnostics is used to provide tracing support for the client library. </summary>
24+
internal ClientDiagnostics ClientDiagnostics { get; }
25+
26+
/// <summary> The HTTP pipeline for sending and receiving REST requests and responses. </summary>
27+
public virtual HttpPipeline Pipeline => _pipeline;
28+
29+
/// <summary> Initializes a new instance of TestRunUpdateClient for mocking. </summary>
30+
protected TestRunUpdateClient()
31+
{
32+
}
33+
34+
/// <summary> Initializes a new instance of TestRunUpdateClient. </summary>
35+
/// <param name="endpoint"> server parameter. </param>
36+
/// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> is null. </exception>
37+
public TestRunUpdateClient(Uri endpoint) : this(endpoint, new TestRunUpdateClientOptions())
38+
{
39+
}
40+
41+
/// <summary> Initializes a new instance of TestRunUpdateClient. </summary>
42+
/// <param name="endpoint"> server parameter. </param>
43+
/// <param name="options"> The options for configuring the client. </param>
44+
/// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> is null. </exception>
45+
public TestRunUpdateClient(Uri endpoint, TestRunUpdateClientOptions options)
46+
{
47+
Argument.AssertNotNull(endpoint, nameof(endpoint));
48+
options ??= new TestRunUpdateClientOptions();
49+
50+
ClientDiagnostics = new ClientDiagnostics(options, true);
51+
_pipeline = HttpPipelineBuilder.Build(options, Array.Empty<HttpPipelinePolicy>(), Array.Empty<HttpPipelinePolicy>(), new ResponseClassifier());
52+
_endpoint = endpoint;
53+
_apiVersion = options.Version;
54+
}
55+
56+
/// <summary>
57+
/// [Protocol Method]
58+
/// <list type="bullet">
59+
/// <item>
60+
/// <description>
61+
/// This <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/ProtocolMethods.md">protocol method</see> allows explicit creation of the request and processing of the response for advanced scenarios.
62+
/// </description>
63+
/// </item>
64+
/// </list>
65+
/// </summary>
66+
/// <param name="workspaceId"> The <see cref="string"/> to use. </param>
67+
/// <param name="testRunId"> The <see cref="string"/> to use. </param>
68+
/// <param name="content"> The content to send as the body of the request. </param>
69+
/// <param name="authorization"> access token. </param>
70+
/// <param name="xCorrelationId"> Correlation-id used for tracing and debugging. </param>
71+
/// <param name="context"> The request context, which can override default behaviors of the client pipeline on a per-call basis. </param>
72+
/// <exception cref="ArgumentNullException"> <paramref name="workspaceId"/> or <paramref name="testRunId"/> is null. </exception>
73+
/// <exception cref="ArgumentException"> <paramref name="workspaceId"/> or <paramref name="testRunId"/> is an empty string, and was expected to be non-empty. </exception>
74+
/// <exception cref="RequestFailedException"> Service returned a non-success status code. </exception>
75+
/// <returns> The response returned from the service. </returns>
76+
public virtual async Task<Response> TestRunsAsync(string workspaceId, string testRunId, RequestContent content, string authorization = null, string xCorrelationId = null, RequestContext context = null)
77+
{
78+
Argument.AssertNotNullOrEmpty(workspaceId, nameof(workspaceId));
79+
Argument.AssertNotNullOrEmpty(testRunId, nameof(testRunId));
80+
81+
using var scope = ClientDiagnostics.CreateScope("TestRunUpdateClient.TestRuns");
82+
scope.Start();
83+
try
84+
{
85+
using HttpMessage message = CreateTestRunsRequest(workspaceId, testRunId, content, authorization, xCorrelationId, context);
86+
return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
87+
}
88+
catch (Exception e)
89+
{
90+
scope.Failed(e);
91+
throw;
92+
}
93+
}
94+
95+
/// <summary>
96+
/// [Protocol Method]
97+
/// <list type="bullet">
98+
/// <item>
99+
/// <description>
100+
/// This <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/ProtocolMethods.md">protocol method</see> allows explicit creation of the request and processing of the response for advanced scenarios.
101+
/// </description>
102+
/// </item>
103+
/// </list>
104+
/// </summary>
105+
/// <param name="workspaceId"> The <see cref="string"/> to use. </param>
106+
/// <param name="testRunId"> The <see cref="string"/> to use. </param>
107+
/// <param name="content"> The content to send as the body of the request. </param>
108+
/// <param name="authorization"> access token. </param>
109+
/// <param name="xCorrelationId"> Correlation-id used for tracing and debugging. </param>
110+
/// <param name="context"> The request context, which can override default behaviors of the client pipeline on a per-call basis. </param>
111+
/// <exception cref="ArgumentNullException"> <paramref name="workspaceId"/> or <paramref name="testRunId"/> is null. </exception>
112+
/// <exception cref="ArgumentException"> <paramref name="workspaceId"/> or <paramref name="testRunId"/> is an empty string, and was expected to be non-empty. </exception>
113+
/// <exception cref="RequestFailedException"> Service returned a non-success status code. </exception>
114+
/// <returns> The response returned from the service. </returns>
115+
public virtual Response TestRuns(string workspaceId, string testRunId, RequestContent content, string authorization = null, string xCorrelationId = null, RequestContext context = null)
116+
{
117+
Argument.AssertNotNullOrEmpty(workspaceId, nameof(workspaceId));
118+
Argument.AssertNotNullOrEmpty(testRunId, nameof(testRunId));
119+
120+
using var scope = ClientDiagnostics.CreateScope("TestRunUpdateClient.TestRuns");
121+
scope.Start();
122+
try
123+
{
124+
using HttpMessage message = CreateTestRunsRequest(workspaceId, testRunId, content, authorization, xCorrelationId, context);
125+
return _pipeline.ProcessMessage(message, context);
126+
}
127+
catch (Exception e)
128+
{
129+
scope.Failed(e);
130+
throw;
131+
}
132+
}
133+
134+
internal HttpMessage CreateTestRunsRequest(string workspaceId, string testRunId, RequestContent content, string authorization, string xCorrelationId, RequestContext context)
135+
{
136+
var message = _pipeline.CreateMessage(context, ResponseClassifier200);
137+
var request = message.Request;
138+
request.Method = RequestMethod.Patch;
139+
var uri = new RawRequestUriBuilder();
140+
uri.Reset(_endpoint);
141+
uri.AppendPath("/playwrightworkspaces/", false);
142+
uri.AppendPath(workspaceId, true);
143+
uri.AppendPath("/test-runs/", false);
144+
uri.AppendPath(testRunId, true);
145+
uri.AppendQuery("api-version", _apiVersion, true);
146+
request.Uri = uri;
147+
request.Headers.Add("Accept", "application/json");
148+
if (authorization != null)
149+
{
150+
request.Headers.Add("Authorization", authorization);
151+
}
152+
if (xCorrelationId != null)
153+
{
154+
request.Headers.Add("x-correlation-id", xCorrelationId);
155+
}
156+
request.Headers.Add("Content-Type", "application/merge-patch+json");
157+
request.Content = content;
158+
return message;
159+
}
160+
161+
private static ResponseClassifier _responseClassifier200;
162+
private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 });
163+
}
164+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// <auto-generated/>
5+
6+
#nullable disable
7+
8+
using System;
9+
using Azure.Core;
10+
11+
namespace Azure.Developer.Playwright
12+
{
13+
/// <summary> Client options for TestRunUpdateClient. </summary>
14+
internal partial class TestRunUpdateClientOptions : ClientOptions
15+
{
16+
private const ServiceVersion LatestVersion = ServiceVersion.V2025_07_01_Preview;
17+
18+
/// <summary> The version of the service to use. </summary>
19+
public enum ServiceVersion
20+
{
21+
/// <summary> Service version "2025-07-01-preview". </summary>
22+
V2025_07_01_Preview = 1,
23+
}
24+
25+
internal string Version { get; }
26+
27+
/// <summary> Initializes new instance of TestRunUpdateClientOptions. </summary>
28+
public TestRunUpdateClientOptions(ServiceVersion version = LatestVersion)
29+
{
30+
Version = version switch
31+
{
32+
ServiceVersion.V2025_07_01_Preview => "2025-07-01-preview",
33+
_ => throw new NotSupportedException()
34+
};
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)