Skip to content

Commit 1994740

Browse files
committed
Add test for getting context without logging in
1 parent 9b05cbe commit 1994740

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,42 @@ public void GetAzureContext()
7171
Assert.Equal("test", context.Subscription.SubscriptionName);
7272
}
7373

74+
[Fact]
75+
[Trait(Category.AcceptanceType, Category.CheckIn)]
76+
public void GetAzureContextNoLogin()
77+
{
78+
var cmdlt = new GetAzureRMContextCommand();
79+
80+
// Setup
81+
cmdlt.CommandRuntime = commandRuntimeMock;
82+
var profile = AzureRmProfileProvider.Instance.Profile;
83+
AzureRmProfileProvider.Instance.Profile = new AzureRMProfile();
84+
85+
try
86+
{
87+
// Act
88+
cmdlt.InvokeBeginProcessing();
89+
cmdlt.ExecuteCmdlet();
90+
cmdlt.InvokeEndProcessing();
91+
}
92+
catch
93+
{
94+
95+
}
96+
finally
97+
{
98+
AzureRmProfileProvider.Instance.Profile = profile;
99+
}
100+
101+
// Verify
102+
Assert.True(commandRuntimeMock.OutputPipeline.Count == 1);
103+
var context = (PSAzureContext)commandRuntimeMock.OutputPipeline[0];
104+
Assert.Null(context);
105+
Assert.True(commandRuntimeMock.ErrorStream.Count == 1);
106+
var error = commandRuntimeMock.ErrorStream[0];
107+
Assert.Equal("Run Login-AzureRmAccount to login.", error.Exception.Message);
108+
}
109+
74110
[Fact]
75111
[Trait(Category.AcceptanceType, Category.CheckIn)]
76112
public void SelectAzureContextWithNoSubscriptionAndTenant()

0 commit comments

Comments
 (0)