Skip to content

Commit e429c1d

Browse files
committed
Fix failing tests and resolve feedback
1 parent c26f24c commit e429c1d

File tree

4 files changed

+11
-28
lines changed

4 files changed

+11
-28
lines changed

src/Common/Commands.Common.Authentication/AzureSessionInitializer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static ContextAutosaveSettings InitializeSessionSettings(IDataStore store, strin
7878
{
7979
CacheDirectory = profileDirectory,
8080
ContextDirectory = profileDirectory,
81-
Mode = ContextSaveMode.CurrentUser,
81+
Mode = ContextSaveMode.Process,
8282
CacheFile = "TokenCache.dat",
8383
ContextFile = "AzureRmContext.json"
8484
};
@@ -102,6 +102,7 @@ static ContextAutosaveSettings InitializeSessionSettings(IDataStore store, strin
102102
FileUtilities.EnsureDirectoryExists(profileDirectory);
103103
string autoSavePath = Path.Combine(profileDirectory, settingsFile);
104104
store.WriteFile(autoSavePath, JsonConvert.SerializeObject(result));
105+
result.Mode = ContextSaveMode.CurrentUser;
105106
}
106107
}
107108
catch

src/ResourceManager/Common/Commands.Common.Authentication.ResourceManager/AzureRmProfile.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class AzureRmProfile : IAzureContextContainer, IProfileOperations
4040
public IDictionary<string, IAzureContext> Contexts { get; set; } = new ConcurrentDictionary<string, IAzureContext>(StringComparer.CurrentCultureIgnoreCase);
4141

4242
/// <summary>
43-
/// Gets the path of the profile file.
43+
/// Gets the path of the profile file.
4444
/// </summary>
4545
[JsonIgnore]
4646
[XmlIgnore]
@@ -271,7 +271,7 @@ public void Save(IFileProvider provider, bool serializeCache = true)
271271
writer.Write(contents);
272272
writer.Flush();
273273

274-
// When writing to a stream, ensure that the file is truncated
274+
// When writing to a stream, ensure that the file is truncated
275275
// so that previous data is overwritten
276276
provider.Stream.SetLength(provider.Stream.Position);
277277
}
@@ -386,20 +386,9 @@ public bool TryGetContextName(IAzureContext context, out string name)
386386
if (context != null)
387387
{
388388

389-
if ((context.Account != null && !string.IsNullOrWhiteSpace(context.Account.Id)) || context.Subscription != null)
389+
if (context.Subscription != null)
390390
{
391-
List<string> components = new List<string>();
392-
if (context.Account != null && !string.IsNullOrWhiteSpace(context.Account.Id))
393-
{
394-
components.Add(context.Account.Id);
395-
}
396-
397-
if (context.Subscription != null)
398-
{
399-
components.Add(context.Subscription.GetId().ToString());
400-
}
401-
402-
name = string.Format("[{0}]", string.Join(", ", components));
391+
name = string.Format("{0} - {1}", context.Subscription.Name, context.Subscription.Id);
403392
result = true;
404393
}
405394
else

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ public void GetAzureContextNoLogin()
9696
}
9797

9898
// Verify
99-
Assert.True(commandRuntimeMock.OutputPipeline.Count == 1);
100-
var context = (PSAzureContext)commandRuntimeMock.OutputPipeline[0];
101-
Assert.True(context == null || context.Account == null || context.Account.Id == null);
102-
Assert.True(commandRuntimeMock.ErrorStream.Count == 1);
103-
var error = commandRuntimeMock.ErrorStream[0];
104-
Assert.Equal("Run Connect-AzureRmAccount to login.", error.Exception.Message);
99+
Assert.True(commandRuntimeMock.OutputPipeline.Count == 0);
105100
}
106101

107102
[Fact]
@@ -131,9 +126,7 @@ public void ListAzureContextNoLogin()
131126

132127
// Verify
133128
Assert.Equal(0, commandRuntimeMock.OutputPipeline.Count);
134-
Assert.True(commandRuntimeMock.ErrorStream.Count == 1);
135-
var error = commandRuntimeMock.ErrorStream[0];
136-
Assert.Equal("Run Connect-AzureRmAccount to login.", error.Exception.Message);
129+
Assert.True(commandRuntimeMock.ErrorStream.Count == 0);
137130
}
138131

139132

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void DataCollectionSettingPreventsFileWrite()
8383
Assert.Equal(typeof(AuthenticationStoreTokenCache), session.TokenCache.GetType());
8484
Assert.NotNull(AzureRmProfileProvider.Instance);
8585
Assert.Equal(typeof(ResourceManagerProfileProvider), AzureRmProfileProvider.Instance.GetType());
86-
store.Verify(f => f.WriteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
86+
store.Verify(f => f.WriteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
8787
}
8888
finally
8989
{
@@ -103,7 +103,7 @@ public void TestInitializationCannotCheckDirectoryExistence()
103103
AzureSessionInitializer.CreateOrReplaceSession(store.Object);
104104
var session = AzureSession.Instance;
105105
Assert.NotNull(session);
106-
Assert.Equal(ContextSaveMode.Process, session.ARMContextSaveMode);
106+
Assert.Equal(ContextSaveMode.CurrentUser, session.ARMContextSaveMode);
107107
Assert.NotNull(session.TokenCache);
108108
Assert.Equal(typeof(AuthenticationStoreTokenCache), session.TokenCache.GetType());
109109
Assert.NotNull(AzureRmProfileProvider.Instance);
@@ -178,7 +178,7 @@ public void TestInitializationCannotCreateDirectory()
178178
AzureSessionInitializer.CreateOrReplaceSession(store.Object);
179179
var session = AzureSession.Instance;
180180
Assert.NotNull(session);
181-
Assert.Equal(ContextSaveMode.Process, session.ARMContextSaveMode);
181+
Assert.Equal(ContextSaveMode.CurrentUser, session.ARMContextSaveMode);
182182
Assert.NotNull(session.TokenCache);
183183
Assert.Equal(typeof(AuthenticationStoreTokenCache), session.TokenCache.GetType());
184184
Assert.NotNull(AzureRmProfileProvider.Instance);

0 commit comments

Comments
 (0)