Skip to content
Browse files

Change Get-AzureStoreAddOn -ListAvailable to use ManagementClient

  • Loading branch information...
1 parent 9fa804c commit d38ce0288550d7f34da2a72ed4845e49e3027f60 ogail committed Oct 16, 2013
View
12 WindowsAzurePowershell/src/Commands.Test/Store/GetAzureStoreAddOnTest.cs
@@ -22,10 +22,10 @@ namespace Microsoft.WindowsAzure.Commands.Test.Store
using Utilities.Common;
using Microsoft.WindowsAzure.Commands.Utilities.MarketplaceServiceReference;
using Commands.Utilities.Store;
- using Microsoft.WindowsAzure.ServiceManagement;
using Moq;
using VisualStudio.TestTools.UnitTesting;
using Resource = Microsoft.WindowsAzure.Management.Store.Models.CloudServiceListResponse.CloudService.AddOnResource;
+ using Location = Microsoft.WindowsAzure.Management.Models.LocationsListResponse.Location;
[TestClass]
public class GetAzureStoreAddOnTests : TestBase
@@ -34,8 +34,6 @@ public class GetAzureStoreAddOnTests : TestBase
Mock<StoreClient> mockStoreClient;
- Mock<IServiceManagement> mockServiceManagementChannel;
-
Mock<MarketplaceClient> mockMarketplaceClient;
GetAzureStoreAddOnCommand cmdlet;
@@ -47,12 +45,10 @@ public void SetupTest()
mockCommandRuntime = new Mock<ICommandRuntime>();
mockStoreClient = new Mock<StoreClient>();
mockMarketplaceClient = new Mock<MarketplaceClient>();
- mockServiceManagementChannel = new Mock<IServiceManagement>();
cmdlet = new GetAzureStoreAddOnCommand()
{
StoreClient = mockStoreClient.Object,
CommandRuntime = mockCommandRuntime.Object,
- Channel = mockServiceManagementChannel.Object,
MarketplaceClient = mockMarketplaceClient.Object
};
}
@@ -90,10 +86,8 @@ public void GetAzureStoreAddOnAvailableAddOnsSuccessfull()
.Returns(expectedWindowsAzureOffers);
mockMarketplaceClient.Setup(f => f.IsKnownProvider(It.IsAny<Guid>())).Returns(true);
- mockServiceManagementChannel.Setup(
- f => f.BeginListLocations(It.IsAny<string>(), It.IsAny<AsyncCallback>(), It.IsAny<object>()));
- mockServiceManagementChannel.Setup(f => f.EndListLocations(It.IsAny<IAsyncResult>()))
- .Returns(new LocationList()
+ mockStoreClient.Setup(f => f.GetLocations())
+ .Returns(new List<Location>()
{
new Location() { Name = "West US" },
new Location() { Name = "East US" }
View
17 WindowsAzurePowershell/src/Commands.Utilities/Store/StoreClient.cs
@@ -32,6 +32,9 @@ namespace Microsoft.WindowsAzure.Commands.Utilities.Store
using ServiceManagementConstants = Microsoft.WindowsAzure.ServiceManagement.Constants;
using CloudService = Microsoft.WindowsAzure.Management.Store.Models.CloudServiceListResponse.CloudService;
using Resource = Microsoft.WindowsAzure.Management.Store.Models.CloudServiceListResponse.CloudService.AddOnResource;
+ using Microsoft.WindowsAzure.Management;
+ using System.Linq;
+ using Microsoft.WindowsAzure.Management.Models;
public class StoreClient
{
@@ -45,6 +48,8 @@ public class StoreClient
private ComputeManagementClient computeClient { get; set; }
+ private ManagementClient managementClient { get; set; }
+
private string subscriptionId;
private List<CloudService> GetStoreCloudServices()
@@ -144,20 +149,23 @@ public StoreClient(WindowsAzureSubscription subscription)
subscription,
subscription.CreateClient<ComputeManagementClient>(),
subscription.CreateClient<StoreManagementClient>(),
- new MarketplaceClient()) { }
+ new MarketplaceClient(),
+ subscription.CreateClient<ManagementClient>()) { }
public StoreClient(
WindowsAzureSubscription subscription,
ComputeManagementClient compute,
StoreManagementClient store,
- MarketplaceClient marketplace)
+ MarketplaceClient marketplace,
+ ManagementClient management)
{
Validate.ValidateStringIsNullOrEmpty(subscription.SubscriptionId, null, true);
this.subscriptionId = subscription.SubscriptionId;
computeClient = compute;
storeClient = store;
MarketplaceClient = marketplace;
+ managementClient = management;
}
/// <summary>
@@ -375,6 +383,11 @@ public virtual void UpdateAddOn(string name, string plan, string promotionCode)
}
}
}
+
+ public virtual List<LocationsListResponse.Location> GetLocations()
+ {
+ return managementClient.Locations.List().Locations.ToList();
+ }
}
public enum OperationType
View
6 WindowsAzurePowershell/src/Commands/Store/GetAzureStoreAddOn.cs
@@ -72,9 +72,9 @@ private void GetAddOn()
private void ListAvailableAddOns()
{
- LocationList locations = Channel.ListLocations(CurrentSubscription.SubscriptionId);
- MarketplaceClient = MarketplaceClient ??
- new MarketplaceClient(locations.Select<Location, string>(l => l.Name));
+ StoreClient = StoreClient ?? new StoreClient(CurrentSubscription);
+ MarketplaceClient = MarketplaceClient ??
+ new MarketplaceClient(StoreClient.GetLocations().Select(l => l.Name));
WriteVerbose(Resources.GetAllAddOnsWaitMessage);
List<WindowsAzureOffer> result = MarketplaceClient.GetAvailableWindowsAzureOffers(Country);

0 comments on commit d38ce02

Please sign in to comment.
Something went wrong with that request. Please try again.