Skip to content

Commit dea56b6

Browse files
authored
Merge branch 'main' into chore/kiota-bundle
2 parents 13b570e + e1fdb11 commit dea56b6

File tree

6 files changed

+43
-13
lines changed

6 files changed

+43
-13
lines changed

.github/workflows/validatePullRequest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ jobs:
6565
- name: Setup .NET
6666
uses: actions/setup-dotnet@v4
6767
with:
68-
dotnet-version: 8.x
68+
dotnet-version: 9.x
6969

7070
- name: Validate Trimming warnings
71-
run: dotnet publish -c Release -r win-x64 /p:TreatWarningsAsErrors=true /warnaserror -f net8.0
71+
run: dotnet publish -c Release -r win-x64 /p:TreatWarningsAsErrors=true /warnaserror -f net9.0
7272
working-directory: ./tests/Microsoft.Graph.DotnetCore.Core.Trimming

src/Microsoft.Graph.Core/Microsoft.Graph.Core.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<PublishRepositoryUrl>true</PublishRepositoryUrl>
3636
<EmbedUntrackedSources>true</EmbedUntrackedSources>
3737
<Deterministic>true</Deterministic>
38+
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
3839
<EnableNETAnalyzers>True</EnableNETAnalyzers>
3940
<PackageReadmeFile>README.md</PackageReadmeFile>
4041
<NoWarn>NU5048;NETSDK1202</NoWarn>
@@ -62,8 +63,8 @@
6263
</None>
6364
</ItemGroup>
6465
<ItemGroup>
65-
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.3.0" />
66-
<PackageReference Include="Microsoft.IdentityModel.Validators" Version="8.3.0" />
66+
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.3.1" />
67+
<PackageReference Include="Microsoft.IdentityModel.Validators" Version="8.3.1" />
6768
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
6869
<PackageReference Include="Microsoft.Kiota.Bundle" Version="1.16.4" />
6970
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.16.4" />

src/Microsoft.Graph.Core/Requests/Content/BatchRequestContent.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.Graph
1717
using System.Threading;
1818
using System.Threading.Tasks;
1919
using Microsoft.Kiota.Abstractions;
20+
using Microsoft.Kiota.Abstractions.Authentication;
2021

2122
/// <summary>
2223
/// A <see cref="HttpContent"/> implementation to handle json batch requests.
@@ -71,7 +72,7 @@ public BatchRequestContent(IRequestAdapter requestAdapter, params BatchRequestSt
7172
if (batchRequestSteps == null)
7273
throw new ArgumentNullException(nameof(batchRequestSteps));
7374

74-
if (batchRequestSteps.Count() > CoreConstants.BatchRequest.MaxNumberOfRequests)
75+
if (batchRequestSteps.Length > CoreConstants.BatchRequest.MaxNumberOfRequests)
7576
throw new ArgumentException(string.Format(ErrorConstants.Messages.MaximumValueExceeded, "Number of batch request steps", CoreConstants.BatchRequest.MaxNumberOfRequests));
7677

7778
this.Headers.ContentType = new MediaTypeHeaderValue(CoreConstants.MimeTypeNames.Application.Json);
@@ -87,7 +88,12 @@ public BatchRequestContent(IRequestAdapter requestAdapter, params BatchRequestSt
8788
AddBatchRequestStep(requestStep);
8889
}
8990

90-
this.RequestAdapter = requestAdapter ?? throw new ArgumentNullException(nameof(requestAdapter));
91+
// as we only use the adapter to serialize request using the `ConvertToNativeRequestAsync` interface,
92+
// we don't want to make extra request to the authentication provider as the request does not need the authentication header.
93+
this.RequestAdapter = new BaseGraphRequestAdapter(new AnonymousAuthenticationProvider())
94+
{
95+
BaseUrl = requestAdapter.BaseUrl
96+
};
9197
}
9298

9399
/// <summary>

tests/Microsoft.Graph.DotnetCore.Core.Test/Requests/Content/BatchRequestContentTests.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void BatchRequestContent_RemoveBatchRequestStepWithIdForNonExistingId()
181181

182182
Assert.False(isSuccess);
183183
Assert.True(batchRequestContent.BatchRequestSteps.Count.Equals(2));
184-
Assert.Same(batchRequestStep2.DependsOn.First(), batchRequestContent.BatchRequestSteps["2"].DependsOn.First());
184+
Assert.Same(batchRequestStep2.DependsOn[0], batchRequestContent.BatchRequestSteps["2"].DependsOn[0]);
185185
}
186186

187187
[Fact]
@@ -311,6 +311,29 @@ public async System.Threading.Tasks.Task BatchRequestContent_GetBatchRequestCont
311311
Assert.Equal(expectedContent, requestContent);
312312
}
313313

314+
[Fact]
315+
public async System.Threading.Tasks.Task BatchRequestContent_GetBatchRequestContentFromRequestInformationDoesNotAddAuthHeaderAsync()
316+
{
317+
BatchRequestContent batchRequestContent = new BatchRequestContent(client);
318+
RequestInformation requestInformation = new RequestInformation() { HttpMethod = Method.GET, UrlTemplate = REQUEST_URL };
319+
await batchRequestContent.AddBatchRequestStepAsync(requestInformation, "2");
320+
321+
string requestContent;
322+
// We get the contents of the stream as string for comparison.
323+
using (Stream requestStream = await batchRequestContent.GetBatchRequestContentAsync())
324+
using (StreamReader reader = new StreamReader(requestStream))
325+
{
326+
requestContent = await reader.ReadToEndAsync();
327+
}
328+
329+
string expectedContent = "{\"requests\":[{\"id\":\"2\",\"url\":\"/me\",\"method\":\"GET\"}]}"; //Auth Header Absent.
330+
331+
Assert.NotNull(requestContent);
332+
Assert.IsType<BaseGraphRequestAdapter>(batchRequestContent.RequestAdapter);
333+
Assert.True(batchRequestContent.BatchRequestSteps.Count.Equals(1));
334+
Assert.Equal(expectedContent, requestContent);
335+
}
336+
314337
[Fact]
315338
public async System.Threading.Tasks.Task BatchRequestContent_GetBatchRequestContentSupportsNonJsonPayloadAsync()
316339
{
@@ -331,7 +354,7 @@ public async System.Threading.Tasks.Task BatchRequestContent_GetBatchRequestCont
331354
string requestContent;
332355
// we do this to get a version of the json that is indented
333356
using (Stream requestStream = await batchRequestContent.GetBatchRequestContentAsync())
334-
using (JsonDocument jsonDocument = JsonDocument.Parse(requestStream))
357+
using (JsonDocument jsonDocument = await JsonDocument.ParseAsync(requestStream))
335358
{
336359
requestContent = JsonSerializer.Serialize(jsonDocument.RootElement, new JsonSerializerOptions() { WriteIndented = true });
337360
}
@@ -409,7 +432,7 @@ public async System.Threading.Tasks.Task BatchRequestContent_GetBatchRequestCont
409432
string requestContent;
410433
// we do this to get a version of the json that is indented
411434
using (Stream requestStream = await batchRequestContent.GetBatchRequestContentAsync())
412-
using (JsonDocument jsonDocument = JsonDocument.Parse(requestStream))
435+
using (JsonDocument jsonDocument = await JsonDocument.ParseAsync(requestStream))
413436
{
414437
requestContent = JsonSerializer.Serialize(jsonDocument.RootElement, new JsonSerializerOptions() { WriteIndented = true });
415438
}
@@ -532,7 +555,7 @@ public void BatchRequestContent_AddBatchRequestStepWithHttpRequestMessageToBatch
532555

533556
// Assert
534557
var exception = Assert.Throws<ArgumentException>(() => batchRequestContent.AddBatchRequestStep(extraHttpRequestMessage));//Assert we throw exception on excess add
535-
//Assert.Equal(ErrorConstants.Codes.MaximumValueExceeded, exception.Error.Code);
558+
Assert.Equal(string.Format(ErrorConstants.Messages.MaximumValueExceeded, "Number of batch request steps", CoreConstants.BatchRequest.MaxNumberOfRequests), exception.Message);
536559
Assert.NotNull(batchRequestContent.BatchRequestSteps);
537560
Assert.True(batchRequestContent.BatchRequestSteps.Count.Equals(CoreConstants.BatchRequest.MaxNumberOfRequests));
538561
}
@@ -612,7 +635,7 @@ public async Task BatchRequestContent_AddBatchRequestStepWithBaseRequestToBatchR
612635
var exception = await Assert.ThrowsAsync<ArgumentException>(() => batchRequestContent.AddBatchRequestStepAsync(extraRequestInformation));
613636

614637
// Assert
615-
//Assert.Equal(ErrorConstants.Codes.MaximumValueExceeded, exception.Error.Code);
638+
Assert.Equal(string.Format(ErrorConstants.Messages.MaximumValueExceeded, "Number of batch request steps", CoreConstants.BatchRequest.MaxNumberOfRequests), exception.Message);
616639
Assert.NotNull(batchRequestContent.BatchRequestSteps);
617640
Assert.True(batchRequestContent.BatchRequestSteps.Count.Equals(CoreConstants.BatchRequest.MaxNumberOfRequests));
618641
}

tests/Microsoft.Graph.DotnetCore.Core.Trimming/Microsoft.Graph.DotnetCore.Core.Trimming.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<InvariantGlobalization>true</InvariantGlobalization>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.101", /* https://github.com/dotnet/maui/wiki/.NET-7-and-.NET-MAUI */
3+
"version": "9.0.102", /* https://github.com/dotnet/maui/wiki/.NET-7-and-.NET-MAUI */
44
"rollForward": "major"
55
}
66
}

0 commit comments

Comments
 (0)