Skip to content

Commit 4a16da9

Browse files
authored
update sdk and test framework to net8 (#438)
* update test framework to net8 * clean up test deps
1 parent 0d2d323 commit 4a16da9

28 files changed

+47
-4710
lines changed

.azure-pipelines/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ pool:
66

77
steps:
88
- task: UseDotNet@2
9-
displayName: 'Use .Net Core sdk 2.1.302'
9+
displayName: 'Pin .Net SDK 8.x'
1010
inputs:
11-
version: 2.1.302
11+
version: 8.x
1212

1313
- task: DotNetCoreCLI@2
1414
displayName: 'Build Debug'

.azure-pipelines/daily-build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ pool:
1515

1616
steps:
1717
- task: UseDotNet@2
18-
displayName: 'Use .Net Core sdk 2.1.302'
18+
displayName: 'Pin .Net SDK 8.x'
1919
inputs:
20-
version: 2.1.302
20+
version: 8.x
2121

2222
- task: DotNetCoreCLI@2
2323
displayName: 'Build Debug'

Azure.PowerShell.Common.sln

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31313.79
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.35431.28
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "src\Common\Common.csproj", "{5EE72C53-1720-4309-B54B-5FB79703195F}"
77
EndProject
@@ -127,10 +127,6 @@ Global
127127
{29ECE00D-4FD5-4AFC-BEBF-136002E9CB9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
128128
{29ECE00D-4FD5-4AFC-BEBF-136002E9CB9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
129129
{29ECE00D-4FD5-4AFC-BEBF-136002E9CB9C}.Release|Any CPU.Build.0 = Release|Any CPU
130-
{9E283CCA-7923-4062-A0A7-289C14324E43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
131-
{9E283CCA-7923-4062-A0A7-289C14324E43}.Debug|Any CPU.Build.0 = Debug|Any CPU
132-
{9E283CCA-7923-4062-A0A7-289C14324E43}.Release|Any CPU.ActiveCfg = Release|Any CPU
133-
{9E283CCA-7923-4062-A0A7-289C14324E43}.Release|Any CPU.Build.0 = Release|Any CPU
134130
EndGlobalSection
135131
GlobalSection(SolutionProperties) = preSolution
136132
HideSolutionNode = FALSE

build/pack.proj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Target Name="netstandard20">
1414
<Message Importance="high" Text="Pack: netstandard20 started" />
1515
<ItemGroup>
16-
<NetStandard20Projects Include="$(Src)**\*.csproj" Exclude="$(Src)**\*.Tests.csproj;$(Src)**\*.Test.csproj;$(Src)**\*.UnitTest.Netcore.csproj" />
16+
<NetStandard20Projects Include="$(Src)**\*.csproj" Exclude="$(Src)**\*.Tests.csproj;$(Src)**\*.Test.csproj" />
1717
</ItemGroup>
1818
<Exec Command="dotnet pack %(NetStandard20Projects.FullPath) -c $(Configuration) /p:PackageVersion=$(PackageVersion)-preview --no-build" />
1919
</Target>

src/Authentication.Abstractions.Test/Authentication.Abstractions.Test.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<Import Project="$(ProjectDir)..\Dependencies.Test.targets" />
4-
4+
55
<PropertyGroup>
6-
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
<TargetFramework>net8.0</TargetFramework>
77

88
<IsPackable>false</IsPackable>
99

src/Authentication.Abstractions.Test/AzureEnvironmentTests.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class AzureEnvironmentTests
2525
[Fact]
2626
public void TestArmAndNonArmBasedCloudMetadataInit()
2727
{
28-
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData\GoodArmResponse.json");
28+
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData/GoodArmResponse.json");
2929
var armEnvironments = AzureEnvironment.InitializeBuiltInEnvironments(null, httpOperations: TestOperationsFactory.Create().GetHttpOperations());
3030

3131
// Check all discovered environments are loaded.
@@ -39,7 +39,7 @@ public void TestArmAndNonArmBasedCloudMetadataInit()
3939
[Fact]
4040
public void TestArmCloudMetadata20190501Init()
4141
{
42-
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData\ArmResponse2019-05-01.json");
42+
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData/ArmResponse2019-05-01.json");
4343
var armEnvironments = AzureEnvironment.InitializeBuiltInEnvironments(null, httpOperations: TestOperationsFactory.Create().GetHttpOperations());
4444

4545
// Check all discovered environments are loaded.
@@ -55,7 +55,7 @@ public void TestArmCloudMetadata20190501Init()
5555
[Fact]
5656
public void TestArmCloudMetadata20220901Init()
5757
{
58-
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData\ArmResponse2022-09-01.json");
58+
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData/ArmResponse2022-09-01.json");
5959
var armEnvironments = AzureEnvironment.InitializeBuiltInEnvironments(null, httpOperations: TestOperationsFactory.Create().GetHttpOperations());
6060

6161
// Check all discovered environments are loaded.
@@ -80,7 +80,7 @@ public void TestArmCloudMetadata20220901Init()
8080
[Fact]
8181
public void TestArmResponseNoAzureCloud()
8282
{
83-
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData\ArmResponseNoAzureCloud.json");
83+
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData/ArmResponseNoAzureCloud.json");
8484
var armEnvironments = AzureEnvironment.InitializeBuiltInEnvironments(null, httpOperations: TestOperationsFactory.Create().GetHttpOperations());
8585

8686
// Check AzureCloud is added to public environment list even discovery endpoint doesn't return AzureCloud.
@@ -93,7 +93,7 @@ public void TestArmResponseNoAzureCloud()
9393
[Fact]
9494
public void TestArmResponseOneEntry()
9595
{
96-
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData\ArmResponseOneEntry.json");
96+
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData/ArmResponseOneEntry.json");
9797
var armEnvironments = AzureEnvironment.InitializeBuiltInEnvironments(null, httpOperations: TestOperationsFactory.Create().GetHttpOperations());
9898

9999
Assert.Equal(4, armEnvironments.Count);
@@ -133,7 +133,7 @@ public void TestDisableArmCloudMetadataInit()
133133
[Fact]
134134
public void TestArmResponseWithEmptyGalleryEndpoint()
135135
{
136-
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData\ArmResponseWithEmptyGallery.json");
136+
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData/ArmResponseWithEmptyGallery.json");
137137
var armEnvironments = AzureEnvironment.InitializeBuiltInEnvironments(null, httpOperations: TestOperationsFactory.Create().GetHttpOperations());
138138

139139
Assert.Equal(3, armEnvironments.Count);

src/Dependencies.Test.targets

+7-14
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@
55
</PropertyGroup>
66
<Import Project="$(MSBuildThisFileDirectory)\Dependencies.Client.targets" />
77
<ItemGroup>
8-
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.9.0-preview" />
9-
<PackageReference Include="Microsoft.Azure.Test.HttpRecorder" Version="1.13.3" />
10-
<PackageReference Include="Microsoft.Identity.Client" Version="3.0.8" />
11-
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.TestFramework" Version="1.7.6" />
12-
<PackageReference Include="xunit" Version="2.4.0" />
13-
</ItemGroup>
14-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
16-
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
17-
</ItemGroup>
18-
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
19-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
20-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
21-
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.2.4" IncludeAssets="All" />
8+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
9+
<PackageReference Include="xunit" Version="2.9.2" />
10+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
11+
<PrivateAssets>all</PrivateAssets>
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
</PackageReference>
14+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.24" IncludeAssets="All" />
2215
</ItemGroup>
2316
</Project>

src/Probe.Test/Probe.Test.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="$(ProjectDir)..\Dependencies.Test.targets" />
44

55
<PropertyGroup>
6-
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
<TargetFramework>net8.0</TargetFramework>
77
<AssemblyName>Microsoft.Azure.PowerShell.Probe.Test</AssemblyName>
88
<OutputPath>$(ProjectDir)..\..\artifacts\$(Configuration)</OutputPath>
99
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

src/ResourceManager.Test/AzureRMCmdletAuthenticationUnitTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void TestGetAuxHeaderByTenantIds()
101101

102102
var header = cmdlet.GetAuxilaryAuthHeaderByTenatIds(tenants);
103103

104-
Assert.Equal(1, header.Count);
104+
Assert.Single(header);
105105
var h = header.First();
106106
Assert.Equal("x-ms-authorization-auxiliary", h.Key);
107107
Assert.Single(h.Value);

src/ResourceManager.Test/CredentialManager.cs

+3-20
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
16+
using System.Collections.Generic;
17+
1518
namespace Microsoft.Azure.Commands.Common.Compute.Tests
1619
{
17-
using System;
18-
using System.Collections.Generic;
19-
using System.IO;
20-
using Microsoft.IdentityModel.Clients.ActiveDirectory;
21-
using Microsoft.Rest;
22-
2320
class CredentialManager
2421
{
2522
protected CredentialManager() { }
@@ -38,20 +35,6 @@ protected CredentialManager() { }
3835
public string TenantId { get; private set; }
3936
public string SubscriptionId { get; private set; }
4037

41-
public TokenCredentials TokenCredentials
42-
{
43-
get
44-
{
45-
var clientCredential = new ClientCredential(ApplicationId, ApplicationSecret);
46-
var context = new AuthenticationContext(Path.Combine(AuthUrl, TenantId));
47-
var result = context.AcquireTokenAsync(BaseUrl, clientCredential);
48-
49-
if (result == null) throw new InvalidOperationException("Failed to obtain the token");
50-
51-
return new TokenCredentials(result.Result.AccessToken);
52-
}
53-
}
54-
5538
public static CredentialManager FromServicePrincipalEnvVariable(string envVariableName = ServicePrincipalEnvVariableName)
5639
{
5740
//AZURE_SERVICE_PRINCIPAL = UserId =< UserGuid >; Password =< Password >; AADTenant =< TenantGuid >; SubscriptionId =< SubscriptionId >

src/ResourceManager.Test/RPRegistrationDelegatingHandlerTests.cs

+18-18
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public RPRegistrationDelegatingHandlerTests(ITestOutputHelper output)
3939
}
4040

4141
[Fact]
42-
public void InvokeRegistrationForUnregisteredResourceProviders()
42+
public async Task InvokeRegistrationForUnregisteredResourceProviders()
4343
{
4444
// Setup
4545
Mock<ResourceManagementClient> mockClient = new Mock<ResourceManagementClient>() { CallBase = true };
@@ -75,16 +75,16 @@ public void InvokeRegistrationForUnregisteredResourceProviders()
7575
HttpClient httpClient = new HttpClient(rpHandler);
7676

7777
// Test
78-
HttpResponseMessage response = httpClient.SendAsync(request).Result;
78+
HttpResponseMessage response = await httpClient.SendAsync(request);
7979

8080
// Assert
8181
Assert.Contains(msgs, s => s.Equals("Succeeded to register resource provider 'microsoft.compute'"));
8282
Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
83-
Assert.Equal("Azure works!", response.Content.ReadAsStringAsync().Result);
83+
Assert.Equal("Azure works!", await response.Content.ReadAsStringAsync());
8484
}
8585

8686
[Fact]
87-
public void DoesNotInvokeRegistrationForRegisteredResourceProviders()
87+
public async Task DoesNotInvokeRegistrationForRegisteredResourceProviders()
8888
{
8989
// Setup
9090
Mock<ResourceManagementClient> mockClient = new Mock<ResourceManagementClient>() { CallBase = true };
@@ -108,16 +108,16 @@ public void DoesNotInvokeRegistrationForRegisteredResourceProviders()
108108
HttpClient httpClient = new HttpClient(rpHandler);
109109

110110
// Test
111-
HttpResponseMessage response = httpClient.SendAsync(request).Result;
111+
HttpResponseMessage response = await httpClient.SendAsync(request);
112112

113113
// Assert
114114
Assert.Empty(msgs);
115115
Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
116-
Assert.Equal("Azure works!", response.Content.ReadAsStringAsync().Result);
116+
Assert.Equal("Azure works!", await response.Content.ReadAsStringAsync());
117117
}
118118

119119
[Fact]
120-
public void DoesNotInvokeRegistrationForUnrelatedStatusCode()
120+
public async Task DoesNotInvokeRegistrationForUnrelatedStatusCode()
121121
{
122122
// Setup
123123
Mock<ResourceManagementClient> mockClient = new Mock<ResourceManagementClient>() { CallBase = true };
@@ -141,16 +141,16 @@ public void DoesNotInvokeRegistrationForUnrelatedStatusCode()
141141
HttpClient httpClient = new HttpClient(rpHandler);
142142

143143
// Test
144-
HttpResponseMessage response = httpClient.SendAsync(request).Result;
144+
HttpResponseMessage response = await httpClient.SendAsync(request);
145145

146146
// Assert
147147
Assert.Empty(msgs);
148148
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
149-
Assert.Equal("auth error!", response.Content.ReadAsStringAsync().Result);
149+
Assert.Equal("auth error!", await response.Content.ReadAsStringAsync());
150150
}
151151

152152
[Fact]
153-
public void DoesNotInvokeRegistrationForIncompatibleUri()
153+
public async Task DoesNotInvokeRegistrationForIncompatibleUri()
154154
{
155155
// Setup
156156
Mock<ResourceManagementClient> mockClient = new Mock<ResourceManagementClient>() { CallBase = true };
@@ -174,16 +174,16 @@ public void DoesNotInvokeRegistrationForIncompatibleUri()
174174
HttpClient httpClient = new HttpClient(rpHandler);
175175

176176
// Test
177-
HttpResponseMessage response = httpClient.SendAsync(request).Result;
177+
HttpResponseMessage response = await httpClient.SendAsync(request);
178178

179179
// Assert
180180
Assert.Empty(msgs);
181181
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
182-
Assert.Equal("registered to use namespace", response.Content.ReadAsStringAsync().Result);
182+
Assert.Equal("registered to use namespace", await response.Content.ReadAsStringAsync());
183183
}
184184

185185
[Fact]
186-
public void DoesNotHangForLongRegistrationCalls()
186+
public async Task DoesNotHangForLongRegistrationCalls()
187187
{
188188
// Setup
189189
Mock<ResourceManagementClient> mockClient = new Mock<ResourceManagementClient>() { CallBase = true };
@@ -219,17 +219,17 @@ public void DoesNotHangForLongRegistrationCalls()
219219
HttpClient httpClient = new HttpClient(rpHandler);
220220

221221
// Test
222-
HttpResponseMessage response = httpClient.SendAsync(request).Result;
222+
HttpResponseMessage response = await httpClient.SendAsync(request);
223223

224224
// Assert
225225
Assert.Contains(msgs, s => s.Equals("Failed to register resource provider 'microsoft.compute'.Details: 'The operation has timed out.'"));
226226
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
227-
Assert.Equal("registered to use namespace", response.Content.ReadAsStringAsync().Result);
227+
Assert.Equal("registered to use namespace", await response.Content.ReadAsStringAsync());
228228
mockProvidersOperations.Verify(f => f.RegisterWithHttpMessagesAsync("microsoft.compute", null, It.IsAny<CancellationToken>()), Times.AtMost(5));
229229
}
230230

231231
[Fact]
232-
public void DoesNotThrowForFailedRegistrationCall()
232+
public async Task DoesNotThrowForFailedRegistrationCall()
233233
{
234234
// Setup
235235
Mock<ResourceManagementClient> mockClient = new Mock<ResourceManagementClient>() { CallBase = true };
@@ -256,12 +256,12 @@ public void DoesNotThrowForFailedRegistrationCall()
256256
HttpClient httpClient = new HttpClient(rpHandler);
257257

258258
// Test
259-
HttpResponseMessage response = httpClient.SendAsync(request).Result;
259+
HttpResponseMessage response = await httpClient.SendAsync(request);
260260

261261
// Assert
262262
Assert.Contains(msgs, s => s.Equals("Failed to register resource provider 'microsoft.compute'.Details: 'PR reg failed'"));
263263
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
264-
Assert.Equal("registered to use namespace", response.Content.ReadAsStringAsync().Result);
264+
Assert.Equal("registered to use namespace", await response.Content.ReadAsStringAsync());
265265
mockProvidersOperations.Verify(f => f.RegisterWithHttpMessagesAsync("microsoft.compute", null, It.IsAny<CancellationToken>()), Times.AtMost(4));
266266
}
267267
}

src/ResourceManager.Test/ResourceManager.Test.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="$(ProjectDir)..\Dependencies.Test.targets" />
44

55
<PropertyGroup>
6-
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
<TargetFramework>net8.0</TargetFramework>
77
<AssemblyName>Microsoft.Azure.PowerShell.ResourceManager.Test</AssemblyName>
88
<RootNamespace>Microsoft.Azure.Commands.Common.ResourceManager.Tests</RootNamespace>
99
<OutputPath>$(ProjectDir)..\..\artifacts\$(Configuration)</OutputPath>

src/Strategies.Test/Strategies.Test.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="$(ProjectDir)..\Dependencies.Test.targets" />
44

55
<PropertyGroup>
6-
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
<TargetFramework>net8.0</TargetFramework>
77
<AssemblyName>Microsoft.Azure.PowerShell.Strategies.Test</AssemblyName>
88
<RootNamespace>Microsoft.Azure.Commands.Common.Strategies.UnitTest</RootNamespace>
99
<OutputPath>$(ProjectDir)..\..\artifacts\$(Configuration)</OutputPath>
Binary file not shown.
Binary file not shown.

tools/xunit.runner.console.2.3.1/net452/xunit.console.exe.config

-6
This file was deleted.
Binary file not shown.

tools/xunit.runner.console.2.3.1/net452/xunit.console.x86.exe.config

-6
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)