Skip to content

Commit 990e918

Browse files
author
msJinLei
committed
Fix the pipeline issue
1 parent e8a8b44 commit 990e918

File tree

3 files changed

+27
-56
lines changed

3 files changed

+27
-56
lines changed

src/Accounts/Accounts.Test/AutosaveTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,25 @@ public class AutosaveTests
3535
{
3636
private MemoryDataStore dataStore;
3737
private MockCommandRuntime commandRuntimeMock;
38+
private AzKeyStore keyStore;
3839
public AutosaveTests(ITestOutputHelper output)
3940
{
4041
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
4142
commandRuntimeMock = new MockCommandRuntime();
4243
dataStore = new MemoryDataStore();
43-
ResetState();
44+
keyStore = SetMockedAzKeyStore();
4445
}
4546

46-
private void SetMockedAzKeyStore()
47+
private AzKeyStore SetMockedAzKeyStore()
4748
{
4849
var storageMocker = new Mock<IStorage>();
4950
storageMocker.Setup(f => f.Create()).Returns(storageMocker.Object);
5051
storageMocker.Setup(f => f.ReadData()).Returns(new byte[0]);
52+
storageMocker.Setup(f => f.WriteData(It.IsAny<byte[]>())).Callback((byte[] s) => {});
5153
var keyStore = new AzKeyStore(AzureSession.Instance.ARMProfileDirectory, "keystore.cache", false, false, storageMocker.Object);
5254
AzKeyStore.RegisterJsonConverter(typeof(ServicePrincipalKey), typeof(ServicePrincipalKey).Name);
5355
AzKeyStore.RegisterJsonConverter(typeof(SecureString), typeof(SecureString).Name, new SecureStringConverter());
54-
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore);
55-
keyStore.LoadStorage();
56+
return keyStore;
5657
}
5758

5859
void ResetState()
@@ -68,7 +69,7 @@ void ResetState()
6869
Environment.SetEnvironmentVariable("Azure_PS_Data_Collection", "false");
6970
PowerShellTokenCacheProvider tokenProvider = new InMemoryTokenCacheProvider();
7071
AzureSession.Instance.RegisterComponent(PowerShellTokenCacheProvider.PowerShellTokenCacheProviderKey, () => tokenProvider, true);
71-
SetMockedAzKeyStore();
72+
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore, true);
7273
}
7374

7475
[Fact]

src/Accounts/Accounts.Test/ProfileCmdletTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
1717
using Microsoft.Azure.Commands.Common.Authentication.Models;
18+
using Microsoft.Azure.Commands.ResourceManager.Common;
1819
using Microsoft.Azure.Commands.ScenarioTest;
1920
using Microsoft.Azure.Commands.TestFx.Mocks;
2021
using Microsoft.Azure.ServiceManagement.Common.Models;
2122
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
2223
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2324
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
2425
using Microsoft.WindowsAzure.Commands.Utilities.Common;
26+
using Moq;
2527
using System;
2628
using System.Linq;
2729
using System.Management.Automation;
@@ -34,6 +36,7 @@ public class ProfileCmdletTests : RMTestBase
3436
{
3537
private MemoryDataStore dataStore;
3638
private MockCommandRuntime commandRuntimeMock;
39+
private AzKeyStore keyStore;
3740

3841
public ProfileCmdletTests(ITestOutputHelper output)
3942
{
@@ -43,12 +46,25 @@ public ProfileCmdletTests(ITestOutputHelper output)
4346
AzureSession.Instance.DataStore = dataStore;
4447
commandRuntimeMock = new MockCommandRuntime();
4548
AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory();
49+
keyStore = SetMockedAzKeyStore();
50+
}
51+
52+
private AzKeyStore SetMockedAzKeyStore()
53+
{
54+
var storageMocker = new Mock<IStorage>();
55+
storageMocker.Setup(f => f.Create()).Returns(storageMocker.Object);
56+
storageMocker.Setup(f => f.ReadData()).Returns(new byte[0]);
57+
storageMocker.Setup(f => f.WriteData(It.IsAny<byte[]>())).Callback((byte[] s) => { });
58+
var keyStore = new AzKeyStore(AzureSession.Instance.ARMProfileDirectory, "keystore.cache", false, false, storageMocker.Object);
59+
return keyStore;
4660
}
4761

4862
[Fact]
4963
[Trait(Category.AcceptanceType, Category.CheckIn)]
5064
public void SelectAzureProfileInMemory()
5165
{
66+
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore, true);
67+
5268
var profile = new AzureRmProfile { DefaultContext = new AzureContext() };
5369
var env = new AzureEnvironment(AzureEnvironment.PublicEnvironments.Values.FirstOrDefault());
5470
env.Name = "foo";
@@ -71,6 +87,7 @@ public void SelectAzureProfileInMemory()
7187
[Trait(Category.AcceptanceType, Category.CheckIn)]
7288
public void SelectAzureProfileBadPath()
7389
{
90+
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore, true);
7491
#pragma warning disable CS0618 // Suppress obsolescence warning: cmdlet name is changing
7592
ImportAzureRMContextCommand cmdlt = new ImportAzureRMContextCommand();
7693
#pragma warning restore CS0618 // Suppress obsolescence warning: cmdlet name is changing
@@ -88,6 +105,7 @@ public void SelectAzureProfileBadPath()
88105
[Trait(Category.AcceptanceType, Category.CheckIn)]
89106
public void SelectAzureProfileFromDisk()
90107
{
108+
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore, true);
91109
var profile = new AzureRmProfile();
92110
profile.EnvironmentTable.Add("foo", new AzureEnvironment(new AzureEnvironment( AzureEnvironment.PublicEnvironments.Values.FirstOrDefault())));
93111
profile.EnvironmentTable["foo"].Name = "foo";
@@ -110,6 +128,7 @@ public void SelectAzureProfileFromDisk()
110128
[Trait(Category.AcceptanceType, Category.CheckIn)]
111129
public void SaveAzureProfileInMemory()
112130
{
131+
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore, true);
113132
var profile = new AzureRmProfile();
114133
profile.EnvironmentTable.Add("foo", new AzureEnvironment(AzureEnvironment.PublicEnvironments.Values.FirstOrDefault()));
115134
profile.EnvironmentTable["foo"].Name = "foo";
@@ -134,6 +153,7 @@ public void SaveAzureProfileInMemory()
134153
[Trait(Category.AcceptanceType, Category.CheckIn)]
135154
public void SaveAzureProfileNull()
136155
{
156+
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore, true);
137157
#pragma warning disable CS0618 // Suppress obsolescence warning: cmdlet name is changing
138158
SaveAzureRMContextCommand cmdlt = new SaveAzureRMContextCommand();
139159
#pragma warning restore CS0618 // Suppress obsolescence warning: cmdlet name is changing
@@ -150,6 +170,7 @@ public void SaveAzureProfileNull()
150170
[Trait(Category.AcceptanceType, Category.CheckIn)]
151171
public void SaveAzureProfileFromDefault()
152172
{
173+
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore, true);
153174
var profile = new AzureRmProfile();
154175
profile.EnvironmentTable.Add("foo", new AzureEnvironment(AzureEnvironment.PublicEnvironments.Values.FirstOrDefault()));
155176
profile.DefaultContext = new AzureContext(new AzureSubscription(), new AzureAccount(), profile.EnvironmentTable["foo"]);

src/Accounts/Authentication.Test/Mocks/MockServicePrincipalCredential.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)