Skip to content

Commit 4a9548d

Browse files
author
Hovsep Mkrtchyan
committed
Added rest of Environment cmdlets and tests.
1 parent 3d054b7 commit 4a9548d

File tree

10 files changed

+775
-5
lines changed

10 files changed

+775
-5
lines changed

src/Common/Commands.ResourceManager.Common/RMProfileClient.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Microsoft.IdentityModel.Clients.ActiveDirectory;
2222
using System;
2323
using System.Collections.Generic;
24+
using System.Diagnostics;
2425
using System.Linq;
2526
using System.Management.Automation;
2627
using System.Security;
@@ -166,6 +167,45 @@ public AzureEnvironment AddOrSetEnvironment(AzureEnvironment environment)
166167
return _profile.Environments[environment.Name];
167168
}
168169

170+
public List<AzureEnvironment> ListEnvironments(string name)
171+
{
172+
var result = new List<AzureEnvironment>();
173+
174+
if (string.IsNullOrWhiteSpace(name))
175+
{
176+
result.AddRange(_profile.Environments.Values);
177+
}
178+
else if (_profile.Environments.ContainsKey(name))
179+
{
180+
result.Add(_profile.Environments[name]);
181+
}
182+
183+
return result;
184+
}
185+
186+
public AzureEnvironment RemoveEnvironment(string name)
187+
{
188+
if (string.IsNullOrEmpty(name))
189+
{
190+
throw new ArgumentNullException("name", Resources.EnvironmentNameNeedsToBeSpecified);
191+
}
192+
if (AzureEnvironment.PublicEnvironments.ContainsKey(name))
193+
{
194+
throw new ArgumentException(Resources.RemovingDefaultEnvironmentsNotSupported, "name");
195+
}
196+
197+
if (_profile.Environments.ContainsKey(name))
198+
{
199+
var environment = _profile.Environments[name];
200+
_profile.Environments.Remove(name);
201+
return environment;
202+
}
203+
else
204+
{
205+
throw new ArgumentException(string.Format(Resources.EnvironmentNotFound, name), "name");
206+
}
207+
}
208+
169209
private AzureEnvironment MergeEnvironmentProperties(AzureEnvironment environment1, AzureEnvironment environment2)
170210
{
171211
if (environment1 == null || environment2 == null)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
</ItemGroup>
184184
<ItemGroup>
185185
<Compile Include="AzureRMProfileTests.cs" />
186+
<Compile Include="EnvironmentCmdletTests.cs" />
186187
<Compile Include="MockSubscriptionClientFactory.cs" />
187188
<Compile Include="ProfileController.cs" />
188189
<Compile Include="SubscriptionCmdletTests.cs" />

0 commit comments

Comments
 (0)