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

Fixes regression on passing custom baseurl (beta) #601

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}