Skip to content

Commit

Permalink
ClientModel: Make message.Apply(options) take nullable options (#43212)
Browse files Browse the repository at this point in the history
* Make message.Apply(options) take nullable options

* add test coverage
  • Loading branch information
annelo-msft authored Apr 4, 2024
1 parent 4b9a46f commit b87f7ad
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions sdk/core/System.ClientModel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Removed `[Serializable]` attribute and serialization constructor from `ClientResultException`.
- Made `value` parameter nullable in `PipelineMessage.SetProperty` method.
- Made `options` parameter to `PipelineMessage.Apply` nullable.

### Bugs Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected internal PipelineMessage(System.ClientModel.Primitives.PipelineRequest
public System.ClientModel.Primitives.PipelineRequest Request { get { throw null; } }
public System.ClientModel.Primitives.PipelineResponse? Response { get { throw null; } protected internal set { } }
public System.ClientModel.Primitives.PipelineMessageClassifier ResponseClassifier { get { throw null; } set { } }
public void Apply(System.ClientModel.Primitives.RequestOptions options) { }
public void Apply(System.ClientModel.Primitives.RequestOptions? options) { }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
public System.ClientModel.Primitives.PipelineResponse? ExtractResponse() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected internal PipelineMessage(System.ClientModel.Primitives.PipelineRequest
public System.ClientModel.Primitives.PipelineRequest Request { get { throw null; } }
public System.ClientModel.Primitives.PipelineResponse? Response { get { throw null; } protected internal set { } }
public System.ClientModel.Primitives.PipelineMessageClassifier ResponseClassifier { get { throw null; } set { } }
public void Apply(System.ClientModel.Primitives.RequestOptions options) { }
public void Apply(System.ClientModel.Primitives.RequestOptions? options) { }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
public System.ClientModel.Primitives.PipelineResponse? ExtractResponse() { throw null; }
Expand Down
12 changes: 6 additions & 6 deletions sdk/core/System.ClientModel/src/Message/PipelineMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ public CancellationToken CancellationToken
/// this <see cref="PipelineMessage"/> instance.
/// </summary>
/// <param name="options">The <see cref="RequestOptions"/> to apply to this
/// <see cref="PipelineMessage"/> instance.</param>
/// <see cref="PipelineMessage"/> instance. If <c>null</c> is passed,
/// no changes will be made to this message instance.</param>
/// <remarks> This method is intended to be called after the creation of
/// the <see cref="PipelineMessage"/> and its <see cref="Request"/> is
/// complete, and prior to the call to
/// <see cref="ClientPipeline.Send(PipelineMessage)"/>.
/// </remarks>
public void Apply(RequestOptions options)
public void Apply(RequestOptions? options)
{
Argument.AssertNotNull(options, nameof(options));

// This design moves the client-author API (options.Apply) off the
// client-user type RequestOptions. Its only purpose is to call through to
// the internal options.Apply method.
options.Apply(this);
// the internal options.Apply method. If null options are passed this
// method is a no-op.
options?.Apply(this);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public void ApplySetsCancellationToken()
Assert.IsTrue(message.CancellationToken.IsCancellationRequested);
}

[Test]
public void NullOptionsIsNoOp()
{
ClientPipeline pipeline = ClientPipeline.Create();
PipelineMessage message = pipeline.CreateMessage();
Assert.DoesNotThrow(() => message.Apply(null));
}

[Test]
public void CanSetAndGetMessageProperties()
{
Expand Down

0 comments on commit b87f7ad

Please sign in to comment.