diff --git a/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs b/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs index 5878a958ac022..11d7723bfa5fd 100644 --- a/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs +++ b/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs @@ -185,8 +185,8 @@ protected PipelineRequest() { } protected abstract System.ClientModel.Primitives.PipelineRequestHeaders HeadersCore { get; } public string Method { get { throw null; } set { } } protected abstract string MethodCore { get; set; } - public System.Uri Uri { get { throw null; } set { } } - protected abstract System.Uri UriCore { get; set; } + public System.Uri? Uri { get { throw null; } set { } } + protected abstract System.Uri? UriCore { get; set; } public abstract void Dispose(); } public abstract partial class PipelineRequestHeaders : System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable diff --git a/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs b/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs index 8bf5ae04454f2..631faf6d45835 100644 --- a/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs +++ b/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs @@ -184,8 +184,8 @@ protected PipelineRequest() { } protected abstract System.ClientModel.Primitives.PipelineRequestHeaders HeadersCore { get; } public string Method { get { throw null; } set { } } protected abstract string MethodCore { get; set; } - public System.Uri Uri { get { throw null; } set { } } - protected abstract System.Uri UriCore { get; set; } + public System.Uri? Uri { get { throw null; } set { } } + protected abstract System.Uri? UriCore { get; set; } public abstract void Dispose(); } public abstract partial class PipelineRequestHeaders : System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable diff --git a/sdk/core/System.ClientModel/src/Message/PipelineRequest.cs b/sdk/core/System.ClientModel/src/Message/PipelineRequest.cs index c10731bb058eb..cf05b6d832494 100644 --- a/sdk/core/System.ClientModel/src/Message/PipelineRequest.cs +++ b/sdk/core/System.ClientModel/src/Message/PipelineRequest.cs @@ -16,13 +16,13 @@ public string Method protected abstract string MethodCore { get; set; } - public Uri Uri + public Uri? Uri { get => UriCore; set => UriCore = value; } - protected abstract Uri UriCore { get; set; } + protected abstract Uri? UriCore { get; set; } public PipelineRequestHeaders Headers => HeadersCore; diff --git a/sdk/core/System.ClientModel/src/Pipeline/HttpClientPipelineTransport.Request.cs b/sdk/core/System.ClientModel/src/Pipeline/HttpClientPipelineTransport.Request.cs index d26fdabaffa66..e0b5a8ea8997b 100644 --- a/sdk/core/System.ClientModel/src/Pipeline/HttpClientPipelineTransport.Request.cs +++ b/sdk/core/System.ClientModel/src/Pipeline/HttpClientPipelineTransport.Request.cs @@ -43,17 +43,9 @@ protected override string MethodCore } } - protected override Uri UriCore + protected override Uri? UriCore { - get - { - if (_uri is null) - { - throw new InvalidOperationException("Uri has not been set on this instance."); - } - - return _uri; - } + get => _uri; set { Argument.AssertNotNull(value, nameof(value)); @@ -89,6 +81,11 @@ private static HttpMethod ToHttpMethod(string method) internal static HttpRequestMessage BuildHttpRequestMessage(PipelineRequest request, CancellationToken cancellationToken) { + if (request.Uri is null) + { + throw new InvalidOperationException("Uri must be set on message request prior to sending message."); + } + HttpMethod method = ToHttpMethod(request.Method); Uri uri = request.Uri; HttpRequestMessage httpRequest = new HttpRequestMessage(method, uri); diff --git a/sdk/core/System.ClientModel/tests/TestFramework/Mocks/MockPipelineRequest.cs b/sdk/core/System.ClientModel/tests/TestFramework/Mocks/MockPipelineRequest.cs index 4fdb8f66ec191..bfafc9750091e 100644 --- a/sdk/core/System.ClientModel/tests/TestFramework/Mocks/MockPipelineRequest.cs +++ b/sdk/core/System.ClientModel/tests/TestFramework/Mocks/MockPipelineRequest.cs @@ -37,18 +37,9 @@ protected override string MethodCore set => _method = value; } - protected override Uri UriCore + protected override Uri? UriCore { - get - { - if (_uri is null) - { - throw new InvalidOperationException("Uri has not be set on HttpMessageRequest instance."); - } - - return _uri; - } - + get => _uri; set => _uri = value; } diff --git a/sdk/core/System.ClientModel/tests/TestFramework/Mocks/MockPipelineTransport.cs b/sdk/core/System.ClientModel/tests/TestFramework/Mocks/MockPipelineTransport.cs index 03ee11154fbfb..cfa28349067b5 100644 --- a/sdk/core/System.ClientModel/tests/TestFramework/Mocks/MockPipelineTransport.cs +++ b/sdk/core/System.ClientModel/tests/TestFramework/Mocks/MockPipelineTransport.cs @@ -119,7 +119,7 @@ public void SetResponse(int status) private class TransportRequest : PipelineRequest { - private Uri _uri; + private Uri? _uri; private readonly PipelineRequestHeaders _headers; public TransportRequest() @@ -145,7 +145,7 @@ protected override string MethodCore set => throw new NotImplementedException(); } - protected override Uri UriCore + protected override Uri? UriCore { get => _uri; set => _uri = value; diff --git a/sdk/core/System.ClientModel/tests/TestFramework/Mocks/ObservableTransport.cs b/sdk/core/System.ClientModel/tests/TestFramework/Mocks/ObservableTransport.cs index 6fe2cb00b781d..be6496cea9467 100644 --- a/sdk/core/System.ClientModel/tests/TestFramework/Mocks/ObservableTransport.cs +++ b/sdk/core/System.ClientModel/tests/TestFramework/Mocks/ObservableTransport.cs @@ -105,7 +105,7 @@ protected override string MethodCore set => throw new NotImplementedException(); } - protected override Uri UriCore + protected override Uri? UriCore { get => throw new NotImplementedException(); set => throw new NotImplementedException();