Skip to content

Commit 058240b

Browse files
committed
Cleaning up Profile tests per design guidelines and review feedback
1 parent c4de9ec commit 058240b

File tree

4 files changed

+49
-44
lines changed

4 files changed

+49
-44
lines changed

src/ResourceManager/Profile/Commands.Profile.Test/AzureRMProfileTests.cs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
using Microsoft.Azure.Commands.Common.Authentication.Models;
1919
using Microsoft.Azure.Commands.Profile;
2020
using Microsoft.Azure.Commands.Profile.Models;
21+
using Microsoft.Azure.Commands.Profile.Test;
2122
using Microsoft.Azure.Commands.ScenarioTest;
2223
using Microsoft.Azure.Internal.Subscriptions.Models;
2324
using Microsoft.Azure.ServiceManagemenet.Common.Models;
24-
using Microsoft.IdentityModel.Clients.ActiveDirectory;
2525
using Microsoft.Rest;
2626
using Microsoft.Rest.Azure;
2727
using Microsoft.WindowsAzure.Commands.Common;
@@ -901,12 +901,11 @@ public void LoadingProfileWorks()
901901

902902
[Fact]
903903
[Trait(Category.AcceptanceType, Category.CheckIn)]
904-
public void CanRenwTokenLogin()
904+
public void CanRenewTokenLogin()
905905
{
906906
var tenants = new List<string> { DefaultTenant.ToString() };
907907
var subscriptions = new List<string> { DefaultSubscription.ToString() };
908908
var profile = SetupLogin(tenants, subscriptions, subscriptions);
909-
910909
var cmdlet = new AddAzureRMAccountCommand();
911910
cmdlet.CommandRuntime = new MockCommandRuntime();
912911
cmdlet.DefaultProfile = profile;
@@ -931,7 +930,6 @@ public void CanRenwTokenLogin()
931930
Assert.Equal(graphToken1, account.GetProperty(AzureAccount.Property.GraphAccessToken));
932931
Assert.True(account.IsPropertySet(AzureAccount.Property.KeyVaultAccessToken));
933932
Assert.Equal(keyVaultToken1, account.GetProperty(AzureAccount.Property.KeyVaultAccessToken));
934-
935933
var toss = SetupLogin(tenants, subscriptions, subscriptions);
936934
var cmdlet2 = new AddAzureRMAccountCommand();
937935
cmdlet2.CommandRuntime = new MockCommandRuntime();
@@ -956,7 +954,6 @@ public void CanRenwTokenLogin()
956954
Assert.Equal(graphToken2, account.GetProperty(AzureAccount.Property.GraphAccessToken));
957955
Assert.True(account.IsPropertySet(AzureAccount.Property.KeyVaultAccessToken));
958956
Assert.Equal(keyVaultToken2, account.GetProperty(AzureAccount.Property.KeyVaultAccessToken));
959-
960957
var factory = new ClientFactory();
961958
var rmClient = factory.CreateArmClient<MockServiceClient>(profile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager);
962959
var rmCred = rmClient.Credentials as TokenCredentials;
@@ -966,7 +963,6 @@ public void CanRenwTokenLogin()
966963
Assert.NotNull(message.Headers.Authorization);
967964
Assert.NotNull(message.Headers.Authorization.Parameter);
968965
Assert.Contains(accessToken2, message.Headers.Authorization.Parameter);
969-
970966
var graphClient = factory.CreateArmClient<MockServiceClient>(profile.DefaultContext, AzureEnvironment.Endpoint.Graph);
971967
var graphCred = graphClient.Credentials as TokenCredentials;
972968
Assert.NotNull(graphCred);
@@ -1011,24 +1007,4 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
10111007
}
10121008
}
10131009
}
1014-
public class MockServiceClient : ServiceClient<MockServiceClient>
1015-
{
1016-
public MockServiceClient(Uri uri, ServiceClientCredentials credentials)
1017-
{
1018-
BaseUri = uri;
1019-
Credentials = credentials;
1020-
}
1021-
1022-
public MockServiceClient(Uri uri, ServiceClientCredentials credentials, params DelegatingHandler[] handlers)
1023-
{
1024-
BaseUri = uri;
1025-
Credentials = credentials;
1026-
}
1027-
1028-
public string SubscriptionId { get; set; }
1029-
1030-
public ServiceClientCredentials Credentials { get; set; }
1031-
1032-
public Uri BaseUri { get; set; }
1033-
}
10341010
}

src/ResourceManager/Profile/Commands.Profile.Test/Commands.Profile.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
<Compile Include="ErrorResolutionTests.cs" />
193193
<Compile Include="LocationCompleterUnitTests.cs" />
194194
<Compile Include="MockDataStore.cs" />
195+
<Compile Include="MockServiceClient.cs" />
195196
<Compile Include="MockSubscriptionClientFactory.cs" />
196197
<Compile Include="NullClient.cs" />
197198
<Compile Include="ProfileController.cs" />

src/ResourceManager/Profile/Commands.Profile.Test/ContextModelTests.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,13 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.Common.Authentication;
16-
using Microsoft.Azure.Commands.Common.Authentication.Models;
17-
using Microsoft.Azure.Commands.Profile;
18-
using Microsoft.Azure.Commands.Profile.Models;
19-
using Microsoft.Azure.ServiceManagemenet.Common.Models;
20-
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
21-
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
23-
using Microsoft.WindowsAzure.Commands.Utilities.Common;
24-
using Xunit;
25-
using Xunit.Abstractions;
2615
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
27-
using System;
28-
using Microsoft.Azure.Commands.ScenarioTest.Extensions;
29-
using Microsoft.Azure.Commands.Profile.Context;
30-
using System.Linq;
16+
using Microsoft.Azure.Commands.Common.Authentication.Models;
3117
using Microsoft.Azure.Commands.Common.Authentication.ResourceManager;
32-
using Microsoft.Azure.Commands.Profile.Common;
3318
using Microsoft.Azure.Commands.ScenarioTest;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using System;
21+
using Xunit;
3422

3523
namespace Microsoft.Azure.Commands.Profile.Test
3624
{
@@ -48,7 +36,6 @@ public class ContextModelTests
4836
[Trait(Category.AcceptanceType, Category.CheckIn)]
4937
public void SetContextCopiesAccountProperties()
5038
{
51-
5239
TestExecutionHelpers.SetUpSessionAndProfile();
5340
var context = new AzureContext();
5441
var newContext = new AzureContext();
@@ -87,7 +74,6 @@ public void SetDefaultContextCopiesAccountProperties()
8774
[Trait(Category.AcceptanceType, Category.CheckIn)]
8875
public void SetContextWithNameCopiesAccountProperties()
8976
{
90-
9177
TestExecutionHelpers.SetUpSessionAndProfile();
9278
var context = new AzureContext();
9379
var newContext = new AzureContext();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Rest;
16+
using System;
17+
using System.Net.Http;
18+
19+
namespace Microsoft.Azure.Commands.Profile.Test
20+
{
21+
22+
public class MockServiceClient : ServiceClient<MockServiceClient>
23+
{
24+
public MockServiceClient(Uri uri, ServiceClientCredentials credentials)
25+
{
26+
BaseUri = uri;
27+
Credentials = credentials;
28+
}
29+
30+
public MockServiceClient(Uri uri, ServiceClientCredentials credentials, params DelegatingHandler[] handlers)
31+
{
32+
BaseUri = uri;
33+
Credentials = credentials;
34+
}
35+
36+
public string SubscriptionId { get; set; }
37+
38+
public ServiceClientCredentials Credentials { get; set; }
39+
40+
public Uri BaseUri { get; set; }
41+
}
42+
}

0 commit comments

Comments
 (0)