Skip to content
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

Adding Support to override the ClientRequestID guid format for test recording sessions. #39133

Merged
merged 13 commits into from
Oct 9, 2023
12 changes: 10 additions & 2 deletions sdk/core/Azure.Core.TestFramework/src/ProxyTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,16 @@ public override Request CreateRequest()
_recording.HasRequests = true;
lock (_recording.Random)
{
// Make sure ClientRequestId are the same across request and response
request.ClientRequestId = _recording.Random.NewGuid().ToString("N");
if (_recording.UseDefaultGuidFormatForClientRequestId)
{
// User want the client format to use the default format
request.ClientRequestId = _recording.Random.NewGuid().ToString();
}
else
{
// Make sure ClientRequestId are the same across request and response
request.ClientRequestId = _recording.Random.NewGuid().ToString("N");
}
}
return request;
}
Expand Down
7 changes: 7 additions & 0 deletions sdk/core/Azure.Core.TestFramework/src/RecordedTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ public string ReplacementHost
/// </summary>
public bool CompareBodies { get; set; } = true;

/// <summary>
/// Determines if the ClientRequestId that is sent as part of a request while in Record mode
/// should use the default Guid format. The default Guid format contains hyphens.
/// The default value is <value>false</value>.
/// </summary>
public bool UseDefaultGuidFormatForClientRequestId { get; set; } = false;

/// <summary>
/// Request headers whose values can change between recording and playback without causing request matching
/// to fail. The presence or absence of the header itself is still respected in matching.
Expand Down
12 changes: 12 additions & 0 deletions sdk/core/Azure.Core.TestFramework/src/TestRecording.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ public TestRandom Random

public string RecordingId { get; private set; }

/// <summary>
/// Determines if the ClientRequestId that is sent as part of a request while in Record mode
/// should use the default Guid format. The default Guid format contains hyphens.
/// </summary>
public bool UseDefaultGuidFormatForClientRequestId
{
get
{
return _recordedTestBase.UseDefaultGuidFormatForClientRequestId;
}
}

/// <summary>
/// Gets the moment in time that this test is being run. This is useful
/// for any test recordings that capture the current time.
Expand Down