Skip to content

Commit ad7c5c4

Browse files
committed
fix comments
1 parent eda2e76 commit ad7c5c4

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

src/ResourceManager/Common/Commands.ResourceManager.Common/ArgumentCompleters/ResourceGroupCompleter.cs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters
1919
using Management.Internal.Resources;
2020
using Management.Internal.Resources.Models;
2121
using Properties;
22+
using Rest.Azure;
2223
using System;
2324
using System.Collections.Concurrent;
2425
using System.Collections.Generic;
@@ -43,7 +44,7 @@ protected static IList<String> ResourceGroupNames
4344
var contextHash = HashContext(context);
4445
if (!_resourceGroupNamesDictionary.ContainsKey(contextHash))
4546
{
46-
_resourceGroupNamesDictionary[contextHash] = new List<string>();
47+
var tempResourceGroupList = new List<string>();
4748
try
4849
{
4950
var instance = AzureSession.Instance;
@@ -56,20 +57,11 @@ protected static IList<String> ResourceGroupNames
5657
var resourceGroups = client.ResourceGroups.ListAsync();
5758
if (resourceGroups.Wait(TimeSpan.FromSeconds(5)))
5859
{
60+
tempResourceGroupList = CreateResourceGroupList(resourceGroups.Result);
5961
if (resourceGroups.Result != null)
6062
{
61-
var resourceGroupList = resourceGroups.Result;
62-
foreach (ResourceGroup resourceGroup in resourceGroupList)
63-
{
64-
_resourceGroupNamesDictionary[contextHash].Add(resourceGroup.Name);
65-
}
63+
_resourceGroupNamesDictionary[contextHash] = tempResourceGroupList;
6664
}
67-
#if DEBUG
68-
else
69-
{
70-
throw new Exception("Result from client.ResourceGroups is null");
71-
}
72-
#endif
7365
}
7466
#if DEBUG
7567
else
@@ -85,9 +77,14 @@ protected static IList<String> ResourceGroupNames
8577
throw ex;
8678
#endif
8779
}
80+
81+
return tempResourceGroupList;
8882
}
8983

90-
return _resourceGroupNamesDictionary[contextHash];
84+
else
85+
{
86+
return _resourceGroupNamesDictionary[contextHash];
87+
}
9188
}
9289
}
9390
}
@@ -138,5 +135,24 @@ private static int HashContext(IAzureContext context)
138135
{
139136
return (context.Account.Id + context.Environment.Name + context.Subscription.Id + context.Tenant.Id).GetHashCode();
140137
}
138+
139+
public static List<string> CreateResourceGroupList(IPage<ResourceGroup> result)
140+
{
141+
var tempResourceGroupList = new List<string>();
142+
if (result != null)
143+
{
144+
foreach (ResourceGroup resourceGroup in result)
145+
{
146+
tempResourceGroupList.Add(resourceGroup.Name);
147+
}
148+
}
149+
#if DEBUG
150+
else
151+
{
152+
throw new Exception("Result from client.ResourceGroups is null");
153+
}
154+
#endif
155+
return tempResourceGroupList;
156+
}
141157
}
142158
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
<Compile Include="ProfileController.cs" />
204204
<Compile Include="ProtectedFileProviderTests.cs" />
205205
<Compile Include="PSSerializationTests.cs" />
206-
<Compile Include="ResourcGroupCompleterUnitTests.cs" />
206+
<Compile Include="ResourceGroupCompleterUnitTests.cs" />
207207
<Compile Include="RPRegistrationDelegatingHandlerTests.cs" />
208208
<Compile Include="SessionInitializationTests.cs" />
209209
<Compile Include="SubscriptionCmdletTests.cs" />
@@ -287,4 +287,4 @@
287287
<ItemGroup />
288288
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
289289
<Import Project="..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
290-
</Project>
290+
</Project>

src/ResourceManager/Profile/Commands.Profile.Test/ResourcGroupCompleterUnitTests.cs renamed to src/ResourceManager/Profile/Commands.Profile.Test/ResourceGroupCompleterUnitTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
16+
using Microsoft.Azure.Management.Internal.Resources;
17+
using Microsoft.Azure.Management.Internal.Resources.Models;
18+
using Microsoft.Rest.Azure.OData;
1619
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Moq;
21+
using System;
1722
using System.Collections.Generic;
23+
using System.Threading;
1824
using Xunit;
1925

2026
namespace Microsoft.Azure.Commands.Profile.Test
@@ -82,5 +88,13 @@ public void MultipleResourceGroupsWithDefault()
8288
Assert.Collection(ResourceGroupCompleterAttribute.GetResourceGroups(resourceGroupsReturned, "test3"), e1 => Assert.Equal("test3", e1),
8389
e2 => Assert.Equal("test1", e2), e3 => Assert.Equal("test2", e3), e4 => Assert.Equal("test4", e4));
8490
}
91+
92+
[Fact]
93+
[Trait(Category.AcceptanceType, Category.CheckIn)]
94+
public void ThrowsErrorWhenResultNull()
95+
{
96+
var ex = Assert.Throws<Exception>(() => ResourceGroupCompleterAttribute.CreateResourceGroupList(null));
97+
Assert.Equal(ex.Message, "Result from client.ResourceGroups is null");
98+
}
8599
}
86100
}

0 commit comments

Comments
 (0)