diff --git a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Middleware/UriReplacementHandlerTests.cs b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Middleware/UriReplacementHandlerTests.cs index 02df8ce..293edf4 100644 --- a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Middleware/UriReplacementHandlerTests.cs +++ b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Middleware/UriReplacementHandlerTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; +using Microsoft.Kiota.Abstractions; using Microsoft.Kiota.Http.HttpClientLibrary.Middleware; using Microsoft.Kiota.Http.HttpClientLibrary.Middleware.Options; using Moq; @@ -65,4 +66,38 @@ public async Task Calls_Uri_ReplacementAsync() mockReplacement.Verify(static x=> x.Replace(It.IsAny()), Times.Once()); } + + [Fact] + public async Task Calls_Uri_Replacement_From_Request_OptionsAsync() + { + var mockReplacement = new Mock(); + mockReplacement.Setup(static x => x.IsEnabled()).Returns(true); + mockReplacement.Setup(static x => x.Replace(It.IsAny())).Returns(new Uri("http://changed")); + + var handler = new UriReplacementHandler() + { + InnerHandler = new FakeSuccessHandler() + }; + var msg = new HttpRequestMessage(HttpMethod.Get, "http://localhost"); + SetRequestOption(msg, mockReplacement.Object); + var client = new HttpClient(handler); + await client.SendAsync(msg); + + mockReplacement.Verify(static x=> x.Replace(It.IsAny()), Times.Once()); + } + + /// + /// Sets a in . + /// + /// + /// The representation of the request. + /// The request option. + private static void SetRequestOption(HttpRequestMessage httpRequestMessage, T option) where T : IRequestOption + { +#if NET5_0_OR_GREATER + httpRequestMessage.Options.Set(new HttpRequestOptionsKey(typeof(T).FullName!), option); +#else + httpRequestMessage.Properties.Add(typeof(T).FullName!, option); +#endif + } }