Skip to content

Commit

Permalink
Merge pull request #601 from microsoftgraph/fixBaseUrlConstructor
Browse files Browse the repository at this point in the history
Fixes regression on passing custom baseurl (beta)
  • Loading branch information
andrueastman authored Jan 16, 2023
2 parents b5415b9 + e5e2c88 commit 56a022d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project does NOT adhere to [Semantic Versioning](https://semver.org/spe

## [Unreleased]

## [5.16.1-preview] - 2023-01-16

### Changed

- Fixed a regression where passing custom base url would not be reflected in the requests.

## [5.16.0-preview] - 2023-01-11

### Changed
Expand Down
15 changes: 11 additions & 4 deletions src/Microsoft.Graph/GraphServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ public class GraphServiceClient: BaseGraphServiceClient, IBaseClient
/// </summary>
/// <param name="requestAdapter">The custom <see cref="IRequestAdapter"/> to be used for making requests</param>
/// <param name="baseUrl">The base service URL. For example, "https://graph.microsoft.com/beta"</param>
public GraphServiceClient(IRequestAdapter requestAdapter, string baseUrl = null): base(requestAdapter)
public GraphServiceClient(IRequestAdapter requestAdapter, string baseUrl = null): base(InitializeRequestAdapterWithBaseUrl(requestAdapter,baseUrl))
{
this.RequestAdapter = requestAdapter;
if (!string.IsNullOrEmpty(baseUrl)) {
this.RequestAdapter.BaseUrl = baseUrl;
}
}

/// <summary>
Expand Down Expand Up @@ -96,5 +93,15 @@ public BatchRequestBuilder Batch
return new BatchRequestBuilder(this.RequestAdapter);
}
}

private static IRequestAdapter InitializeRequestAdapterWithBaseUrl(IRequestAdapter requestAdapter, string baseUrl)
{
if (!string.IsNullOrEmpty(baseUrl))
{
requestAdapter.BaseUrl = baseUrl;
}

return requestAdapter;
}
}
}
6 changes: 2 additions & 4 deletions src/Microsoft.Graph/Microsoft.Graph.Beta.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
<AssemblyOriginatorKeyFile>35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<PackageReleaseNotes>
- [Breaking] Renames `CreateXXXRequestInformation` methods to `ToXXXRequestInformation
- Adds `IAuthenticationProvider` parameter to GraphServiceClient constructor taking a httpClient instance.
- Latest metadata updates from 12th January 2023 snapshot
- Fixed a regression where passing custom base url would not be reflected in the requests.
</PackageReleaseNotes>
<!-- edit this value to change the current major.minor.patch version -->
<VersionPrefix>5.16.0</VersionPrefix>
<VersionPrefix>5.16.1</VersionPrefix>
<!-- adds a version suffix if the Prerelease environment variable is set. BUILD_BUILDID is an
environment variable set by Azure pipelines from the build. We can use the buildid to correlate
which commit was used to generate the preview build. -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

using Microsoft.Graph.Beta;
using Microsoft.Kiota.Abstractions.Authentication;
using Xunit;

namespace Microsoft.Graph.DotnetCore.Test.Models;

public class GraphServiceClientTests
{
[Fact]
public void InitializesClient()
{
// Arrange
var graphClient = new GraphServiceClient(new AnonymousAuthenticationProvider());

// Act
var userRequestInformation = graphClient.Me.ToGetRequestInformation();

// Assert
Assert.Contains("https://graph.microsoft.com", userRequestInformation.URI.OriginalString);
}

[Fact]
public void InitializesClientWithCustomBaseUrl()
{
// Arrange
var customBaseUrl = "https://graph.microsoft-ppe.com";
var graphClient = new GraphServiceClient(new AnonymousAuthenticationProvider(), customBaseUrl);

// Act
var userRequestInformation = graphClient.Me.ToGetRequestInformation();

// Assert
Assert.Contains(customBaseUrl, userRequestInformation.URI.OriginalString);
}
}

0 comments on commit 56a022d

Please sign in to comment.