Skip to content
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
10 changes: 6 additions & 4 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
6.x
8.x
10.x
- uses: actions/checkout@v6
with:
Expand Down Expand Up @@ -72,8 +72,10 @@ jobs:
CoverletOutputFormat: "opencover" # https://github.com/microsoft/vstest/issues/4014#issuecomment-1307913682
shell: pwsh
run: |
./.sonar/scanner/dotnet-sonarscanner begin /k:"microsoftgraph_msgraph-sdk-dotnet-core" /o:"microsoftgraph2" /d:sonar.scanner.scanAll=false /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="tests/Microsoft.Graph.DotnetCore.Core.Test/coverage.opencover.xml"
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
./.sonar/scanner/dotnet-sonarscanner begin /k:"microsoftgraph_msgraph-sdk-dotnet-core" /o:"microsoftgraph2" /d:sonar.scanner.scanAll=false /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="tests/Microsoft.Graph.DotnetCore.Core.Test/coverage.net8.0.opencover.xml"
dotnet workload restore
dotnet build
dotnet test Microsoft.Graph.Core.sln --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --framework net6.0
dotnet build /p:UseSharedCompilation=false
dotnet test Microsoft.Graph.Core.sln --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --framework net8.0
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
12 changes: 6 additions & 6 deletions .github/workflows/validatePullRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ permissions:
jobs:
build:
name: Build and Test
runs-on: windows-2022
runs-on: windows-latest
env:
solutionName: Microsoft.Graph.Core.sln
relativePath: ./src/Microsoft.Graph.Core
steps:
- uses: actions/checkout@v6

- name: Setup .NET 6
- name: Setup .NET 8
uses: actions/setup-dotnet@v5
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x

- name: Setup .NET 10
uses: actions/setup-dotnet@v5
Expand All @@ -45,7 +45,7 @@ jobs:
languages: csharp

- name: Install needed dotnet workloads
run: dotnet workload install android macos ios maccatalyst
run: dotnet workload install android ios maccatalyst

- name: Restore nuget dependencies
run: dotnet restore ${{ env.solutionName }}
Expand All @@ -64,7 +64,7 @@ jobs:

validate-trimming:
name: Validate Project for Trimming
runs-on: windows-2022
runs-on: windows-latest
steps:
- uses: actions/checkout@v6

Expand All @@ -74,5 +74,5 @@ jobs:
dotnet-version: 10.x

- name: Validate Trimming warnings
run: dotnet publish -c Release -r win-x64 /p:TreatWarningsAsErrors=true /warnaserror -f net9.0
run: dotnet publish -c Release -r win-x64 /p:TreatWarningsAsErrors=true /warnaserror -f net10.0
working-directory: ./tests/Microsoft.Graph.DotnetCore.Core.Trimming
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*.userosscache
*.sln.ide
#*.snk
TestResults/*
**/TestResults/
.vs/*

# UWP project files
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<MauiTargets>net6.0</MauiTargets>
<MauiTargets></MauiTargets>
</PropertyGroup>
<PropertyGroup>
<MauiTargets Condition="'$(IncludeMauiTargets)'=='true'">$(MauiTargets);net6.0-android;net6.0-ios;net6.0-maccatalyst;net6.0-macos;net6.0-windows</MauiTargets>
<MauiTargets Condition="'$(IncludeMauiTargets)'=='true'">$(MauiTargets);net10.0-android;net10.0-ios;net10.0-maccatalyst;net10.0-windows</MauiTargets>
</PropertyGroup>
</Project>
8 changes: 4 additions & 4 deletions pipelines/productionBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ extends:
clean: true
fetchDepth: 1
- task: UseDotNet@2
displayName: 'Use .NET 6'
displayName: 'Use .NET 8'
inputs:
version: 6.x
version: 8.x
- task: UseDotNet@2
displayName: 'Use .NET 10 for trimming validation'
displayName: 'Use .NET 10'
inputs:
version: 10.x
- task: PowerShell@2
Expand All @@ -78,7 +78,7 @@ extends:
pwsh: true
enabled: true
- powershell: |
dotnet workload install android macos ios maccatalyst
dotnet workload install android ios maccatalyst
displayName: 'Install needed dotnet workloads'
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.Graph.Core/Microsoft.Graph.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
- https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/blob/main/CHANGELOG.md
</PackageReleaseNotes>
<!-- By default let the Maui targets be excluded to make contribution for external parties easier and dependabot updates. They can be enabled by adding `-p:IncludeMauiTargets=true` to the target build/restore command which is done in the CI.-->
<TargetFrameworks>netstandard2.0;net462;$(MauiTargets)</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net462;net8.0;net10.0</TargetFrameworks>
<TargetFrameworks Condition="'$(MauiTargets)' != ''">$(TargetFrameworks);$(MauiTargets)</TargetFrameworks>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
Expand Down
2 changes: 0 additions & 2 deletions src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,6 @@
}
#if IOS || MACCATALYST
return new NSUrlSessionHandler { AllowAutoRedirect = false };
#elif MACOS
return new Foundation.NSUrlSessionHandler { AllowAutoRedirect = false };
#elif ANDROID
return new Xamarin.Android.Net.AndroidMessageHandler { Proxy = proxy, AllowAutoRedirect = false, AutomaticDecompression = DecompressionMethods.All };
#elif NETFRAMEWORK
Expand Down Expand Up @@ -302,7 +300,7 @@
string cloud = "";
if (!cloudList.TryGetValue(nationalCloud, out cloud))
{
throw new ArgumentException(String.Format("{0} is an unexpected national cloud.", nationalCloud, "nationalCloud"));

Check warning on line 303 in src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

The format string might be wrong, the following arguments are unused: '"nationalCloud"'.

Check warning on line 303 in src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

The format string might be wrong, the following arguments are unused: '"nationalCloud"'.

Check warning on line 303 in src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

The format string might be wrong, the following arguments are unused: '"nationalCloud"'.

Check warning on line 303 in src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

The format string might be wrong, the following arguments are unused: '"nationalCloud"'.

Check warning on line 303 in src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

The format string might be wrong, the following arguments are unused: '"nationalCloud"'.

Check warning on line 303 in src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

The format string might be wrong, the following arguments are unused: '"nationalCloud"'.

Check warning on line 303 in src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

The format string might be wrong, the following arguments are unused: '"nationalCloud"'.

Check warning on line 303 in src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

The format string might be wrong, the following arguments are unused: '"nationalCloud"'.
}
string cloudAddress = $"{cloud}/{version}/";
return new Uri(cloudAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
public class ReadOnlySubStreamTests
{
private readonly Stream _baseStream;

Check warning on line 13 in tests/Microsoft.Graph.DotnetCore.Core.Test/Helpers/ReadOnlySubStreamTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change type of field '_baseStream' from 'System.IO.Stream' to 'System.IO.MemoryStream' for improved performance

See more on https://sonarcloud.io/project/issues?id=microsoftgraph_msgraph-sdk-dotnet-core&issues=AZ230ty20Yyr--VyeNWL&open=AZ230ty20Yyr--VyeNWL&pullRequest=1031
private readonly List<string> _segments = new List<string>()
{
"1234567890","0987654321","1357924680","2468013579"
Expand Down Expand Up @@ -78,7 +78,7 @@
// reset stream to middle and read again
substream.Seek(5, SeekOrigin.Begin);
readBytes = streamReader.ReadToEnd();
Assert.Equal(segment[5..], readBytes);
Assert.Equal(segment.Substring(5), readBytes);

// reset stream and read again
substream.Position = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net462;net8.0;net10.0</TargetFrameworks>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
Expand All @@ -18,7 +18,7 @@
<PackageReference Include="System.Reflection.Emit" Version="4.7.0">
<ExcludeAssets>all</ExcludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public BatchRequestContentStepsTests()
_steps = new BatchRequestContentSteps();
_steps.Add("1", new BatchRequestStep("1", new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/me")));
_steps["2"] = new BatchRequestStep("2", new HttpRequestMessage(HttpMethod.Post, "https://graph.microsoft.com/v1.0/me"));
_steps["uuid-123"] = new BatchRequestStep("uuid-123", new HttpRequestMessage(HttpMethod.Patch, "https://graph.microsoft.com/v1.0/me"));
_steps["uuid-123"] = new BatchRequestStep("uuid-123", new HttpRequestMessage(new HttpMethod("PATCH"), "https://graph.microsoft.com/v1.0/me"));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
public class BatchRequestContentTests
{
private const string REQUEST_URL = "https://graph.microsoft.com/v1.0/me";
private readonly IBaseClient client = new BaseClient(REQUEST_URL, new MockAuthenticationProvider().Object);

Check warning on line 30 in tests/Microsoft.Graph.DotnetCore.Core.Test/Requests/Content/BatchRequestContentTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change type of field 'client' from 'Microsoft.Graph.IBaseClient' to 'Microsoft.Graph.DotnetCore.Core.Test.Mocks.BaseClient' for improved performance

See more on https://sonarcloud.io/project/issues?id=microsoftgraph_msgraph-sdk-dotnet-core&issues=AZ230tvf0Yyr--VyeNWK&open=AZ230tvf0Yyr--VyeNWK&pullRequest=1031

private readonly Regex whitespacePattern = new Regex("\\s");

Check warning on line 32 in tests/Microsoft.Graph.DotnetCore.Core.Test/Requests/Content/BatchRequestContentTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'GeneratedRegexAttribute' to generate the regular expression implementation at compile-time.

See more on https://sonarcloud.io/project/issues?id=microsoftgraph_msgraph-sdk-dotnet-core&issues=AZ230tvf0Yyr--VyeNWG&open=AZ230tvf0Yyr--VyeNWG&pullRequest=1031

public BatchRequestContentTests()
{
Expand Down Expand Up @@ -356,7 +356,7 @@
using (Stream requestStream = await batchRequestContent.GetBatchRequestContentAsync())
using (JsonDocument jsonDocument = await JsonDocument.ParseAsync(requestStream))
{
requestContent = JsonSerializer.Serialize(jsonDocument.RootElement, new JsonSerializerOptions() { WriteIndented = true });

Check warning on line 359 in tests/Microsoft.Graph.DotnetCore.Core.Test/Requests/Content/BatchRequestContentTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead.

See more on https://sonarcloud.io/project/issues?id=microsoftgraph_msgraph-sdk-dotnet-core&issues=AZ230tvf0Yyr--VyeNWH&open=AZ230tvf0Yyr--VyeNWH&pullRequest=1031
}

string expectedJson = "{\r\n" +
Expand Down Expand Up @@ -434,7 +434,7 @@
using (Stream requestStream = await batchRequestContent.GetBatchRequestContentAsync())
using (JsonDocument jsonDocument = await JsonDocument.ParseAsync(requestStream))
{
requestContent = JsonSerializer.Serialize(jsonDocument.RootElement, new JsonSerializerOptions() { WriteIndented = true });

Check warning on line 437 in tests/Microsoft.Graph.DotnetCore.Core.Test/Requests/Content/BatchRequestContentTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead.

See more on https://sonarcloud.io/project/issues?id=microsoftgraph_msgraph-sdk-dotnet-core&issues=AZ230tvf0Yyr--VyeNWI&open=AZ230tvf0Yyr--VyeNWI&pullRequest=1031
}

string expectedJson = "{\r\n" +
Expand Down Expand Up @@ -601,9 +601,13 @@
Assert.True(batchRequestContent.BatchRequestSteps[batchRequestStepId].Request.Content.Headers.Any());

// we do this to get a version of the json payload that is indented
#if NETFRAMEWORK
using var requestStream = await batchRequestContent.GetBatchRequestContentAsync();
#else
await using var requestStream = await batchRequestContent.GetBatchRequestContentAsync();
#endif
using var jsonDocument = await JsonDocument.ParseAsync(requestStream);
string requestContentString = JsonSerializer.Serialize(jsonDocument.RootElement, new JsonSerializerOptions() { WriteIndented = true });

Check warning on line 610 in tests/Microsoft.Graph.DotnetCore.Core.Test/Requests/Content/BatchRequestContentTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead.

See more on https://sonarcloud.io/project/issues?id=microsoftgraph_msgraph-sdk-dotnet-core&issues=AZ230tvf0Yyr--VyeNWJ&open=AZ230tvf0Yyr--VyeNWJ&pullRequest=1031

// Ensure the headers section is added
string expectedJsonSection = " \"url\": \"/me\",\r\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ public void CreateClient_WithInnerHandlerReference()
// Creation should ignore the InnerHandler on RetryHandler
HttpClient client = GraphClientFactory.Create(handlers: handlers);
Assert.NotNull(client);
#if NETFRAMEWORK
Assert.IsType<WinHttpHandler>(handlers[0].InnerHandler);
#else
Assert.IsType<SocketsHttpHandler>(handlers[0].InnerHandler);
#endif
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
{
// Try to upload 1Mb stream without specifying the slice size(should default to 5Mb)
byte[] mockData = new byte[1000000];
using Stream stream = new MemoryStream(mockData);

Check warning on line 143 in tests/Microsoft.Graph.DotnetCore.Core.Test/Tasks/LargeFileUploadTaskTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change type of variable 'stream' from 'System.IO.Stream' to 'System.IO.MemoryStream' for improved performance

See more on https://sonarcloud.io/project/issues?id=microsoftgraph_msgraph-sdk-dotnet-core&issues=AZ230tzz0Yyr--VyeNWN&open=AZ230tzz0Yyr--VyeNWN&pullRequest=1031
// Arrange
var uploadSession = new UploadSession
{
Expand Down Expand Up @@ -168,7 +168,7 @@
public void BreaksDownStreamIntoRangesCorrectly()
{
byte[] mockData = new byte[1000000];//create a stream of about 1M so we can split it into a few 320K slices
using Stream stream = new MemoryStream(mockData);

Check warning on line 171 in tests/Microsoft.Graph.DotnetCore.Core.Test/Tasks/LargeFileUploadTaskTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change type of variable 'stream' from 'System.IO.Stream' to 'System.IO.MemoryStream' for improved performance

See more on https://sonarcloud.io/project/issues?id=microsoftgraph_msgraph-sdk-dotnet-core&issues=AZ230tzz0Yyr--VyeNWO&open=AZ230tzz0Yyr--VyeNWO&pullRequest=1031
// Arrange
var uploadSession = new UploadSession
{
Expand Down Expand Up @@ -210,7 +210,7 @@
}

//The last slice is a bit smaller than the rest
var lastUploadSlice = uploadSlices[^1];
var lastUploadSlice = uploadSlices[uploadSlices.Length - 1];
Assert.Equal(stream.Length - 1, lastUploadSlice.RangeEnd);
Assert.Equal(stream.Length % maxSliceSize, lastUploadSlice.RangeLength); //verify the last slice is the right size
}
Expand Down Expand Up @@ -250,15 +250,18 @@
// Create cancelled token
var cancellationTokenSource = new CancellationTokenSource();
CancellationToken cancellationToken = cancellationTokenSource.Token;
#if NET8_0_OR_GREATER
await cancellationTokenSource.CancelAsync();
#else
cancellationTokenSource.Cancel();
#endif

// Create task
IBaseClient baseClient = new BaseClient(new BaseGraphRequestAdapter(new AnonymousAuthenticationProvider(), httpClient: GraphClientFactory.Create(finalHandler: testHttpMessageHandler)));

Check warning on line 260 in tests/Microsoft.Graph.DotnetCore.Core.Test/Tasks/LargeFileUploadTaskTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change type of variable 'baseClient' from 'Microsoft.Graph.IBaseClient' to 'Microsoft.Graph.DotnetCore.Core.Test.Mocks.BaseClient' for improved performance

See more on https://sonarcloud.io/project/issues?id=microsoftgraph_msgraph-sdk-dotnet-core&issues=AZ230tzz0Yyr--VyeNWM&open=AZ230tzz0Yyr--VyeNWM&pullRequest=1031
var fileUploadTask = new LargeFileUploadTask<TestDriveItem>(uploadSession, stream, maxSliceSize, baseClient.RequestAdapter);

// Assert that the task is cancellable
var cancellationException = await Assert.ThrowsAsync<TaskCanceledException>(() => fileUploadTask.UploadAsync(cancellationToken: cancellationToken));
Assert.Contains("A task was canceled", cancellationException.Message);
var cancellationException = await Assert.ThrowsAnyAsync<OperationCanceledException>(() => fileUploadTask.UploadAsync(cancellationToken: cancellationToken));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
Expand Down
Loading