Skip to content

Commit

Permalink
Removed usage of CmdletSubscriptionExtension.GetCurrentSubscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Tavares committed Sep 26, 2013
1 parent 5a757c2 commit e13e6ea
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 1,345 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ protected Collection<DataVirtualHardDisk> GetDataDisks()

protected void ValidateParameters()
{
var currentSubscription = this.GetCurrentSubscription();
if ((currentSubscription == null || currentSubscription.CurrentStorageAccount == null) && this.MediaLocation == null && string.Compare(this.ParameterSetName, "CreateNew", StringComparison.OrdinalIgnoreCase) == 0)
var currentSubscription = WindowsAzureProfile.Instance.CurrentSubscription;
if ((currentSubscription == null || currentSubscription.CurrentStorageAccountName == null) && this.MediaLocation == null && string.Compare(this.ParameterSetName, "CreateNew", StringComparison.OrdinalIgnoreCase) == 0)
{
throw new ArgumentException(Resources.MediaLocationOrDefaultStorageAccountMustBeSpecified);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected Operation WaitForNewGatewayOperation(string opdesc)
{
Operation operation = null;
String operationId = RetrieveOperationId();
SubscriptionData currentSubscription = this.GetCurrentSubscription();
WindowsAzureSubscription currentSubscription = CurrentSubscription;
try
{
IGatewayServiceManagement channel = (IGatewayServiceManagement)Channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ public string MediaLocation

public void NewAzureVMProcess()
{
SubscriptionData currentSubscription = this.GetCurrentSubscription();
WindowsAzureSubscription currentSubscription = CurrentSubscription;
CloudStorageAccount currentStorage = null;
try
{
currentStorage = currentSubscription.GetCurrentStorageAccount();
currentStorage = currentSubscription.GetCloudStorageAccount();
}
catch (ServiceManagementClientException) // couldn't access
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ public SwitchParameter WaitForBoot

public void NewAzureVMProcess()
{
SubscriptionData currentSubscription = this.GetCurrentSubscription();
WindowsAzureSubscription currentSubscription = CurrentSubscription;

CloudStorageAccount currentStorage = null;
try
{
currentStorage = currentSubscription.GetCurrentStorageAccount();
currentStorage = currentSubscription.GetCloudStorageAccount();
}
catch (ServiceManagementClientException) // couldn't access
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ protected override void ProcessRecord()

protected void ValidateParameters()
{
SubscriptionData currentSubscription = this.GetCurrentSubscription();
if ((currentSubscription == null || currentSubscription.CurrentStorageAccount == null) && MediaLocation == null)
WindowsAzureSubscription currentSubscription = WindowsAzureProfile.Instance.CurrentSubscription;
if ((currentSubscription == null || currentSubscription.CurrentStorageAccountName == null) && MediaLocation == null)
{
throw new ArgumentException(Resources.MustSpecifyMediaLocationOrHaveCurrentStorageAccount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal override void ExecuteCommand()
{
base.ExecuteCommand();

SubscriptionData currentSubscription = this.GetCurrentSubscription();
WindowsAzureSubscription currentSubscription = CurrentSubscription;
if (CurrentDeployment == null)
{
return;
Expand All @@ -66,7 +66,7 @@ internal override void ExecuteCommand()
{
if (datadisk.MediaLink == null && string.IsNullOrEmpty(datadisk.DiskName))
{
CloudStorageAccount currentStorage = currentSubscription.GetCurrentStorageAccount();
CloudStorageAccount currentStorage = currentSubscription.GetCloudStorageAccount();
if (currentStorage == null)
{
throw new ArgumentException(Resources.CurrentStorageAccountIsNotAccessible);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ public class NewAzureSqlDatabaseServerContext : PSCmdlet
HelpMessage = "Use certificate authentication")]
public SwitchParameter UseSubscription { get; set; }

/// <summary>
/// Gets or sets the server credentials
/// </summary>
[Parameter(Mandatory = false, Position = 2,
ParameterSetName = ServerNameWithCertAuthParamSet,
HelpMessage = "The subscription data to use, or uses the current subscription if not specified")]
[Parameter(Mandatory = false, Position = 2,
ParameterSetName = FullyQualifiedServerNameWithCertAuthParamSet,
HelpMessage = "The subscription data to use, or uses the current subscription if not specified")]
public SubscriptionData SubscriptionData { get; set; }

#endregion

/// <summary>
Expand Down Expand Up @@ -359,24 +348,6 @@ private SqlAuthenticationCredentials GetSqlAuthCredentials()
}
}

/// <summary>
/// Obtain the SubscriptionData based on the Cmdlet's parameter set.
/// </summary>
/// <returns>The SubscriptionData to use based on the Cmdlet's parameter set.</returns>
private SubscriptionData GetSubscriptionData()
{
if (this.MyInvocation.BoundParameters.ContainsKey("SubscriptionData"))
{
// SubscriptionData is specified as a parameter. Use it as is.
return this.SubscriptionData;
}
else
{
// SubscriptionData is not specified, use the current subscription.
return this.GetCurrentSubscription();
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,8 @@ public class PublishContextTests : TestBase

private static ServiceSettings settings;

private string serviceName;

private string rootPath = "serviceRootPath";

private MockCommandRuntime mockCommandRuntime;

private ImportAzurePublishSettingsOldCommand importCmdlet;

/// <summary>
/// When running this test double check that the certificate used in Azure.PublishSettings has not expired.
/// </summary>
Expand All @@ -56,23 +50,20 @@ public void TestInitialize()
{
CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();

serviceName = Path.GetRandomFileName();
GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir;
service = new AzureServiceWrapper(Directory.GetCurrentDirectory(), Path.GetRandomFileName(), null);
service.CreateVirtualCloudPackage();
packagePath = service.Paths.CloudPackage;
configPath = service.Paths.CloudConfiguration;
settings = ServiceSettingsTestData.Instance.Data[ServiceSettingsState.Default];
mockCommandRuntime = new MockCommandRuntime();
importCmdlet = new ImportAzurePublishSettingsOldCommand();
importCmdlet.CommandRuntime = mockCommandRuntime;
importCmdlet.ImportSubscriptionFile(Data.ValidPublishSettings.First(), null);
importCmdlet.SubscriptionClient = CreateMockSubscriptionClient();
WindowsAzureProfile.Instance = new WindowsAzureProfile(new Mock<IProfileStore>().Object);
WindowsAzureProfile.Instance.ImportPublishSettings(Data.ValidPublishSettings.First());
}

[TestCleanup()]
public void TestCleanup()
{
WindowsAzureProfile.ResetInstance();
if (Directory.Exists(Data.AzureSdkAppDir))
{
new RemoveAzurePublishSettingsCommand().RemovePublishSettingsProcess(Data.AzureSdkAppDir);
Expand Down
3 changes: 0 additions & 3 deletions WindowsAzurePowershell/src/Commands.Test/Commands.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,8 @@
<Compile Include="Subscription\GetSubscriptionTest.cs" />
<Compile Include="Subscription\GetAzurePublishSettingsFileTests.cs" />
<Compile Include="Subscription\ImportAzurePublishSettingsTests.cs" />
<Compile Include="Common\RemoveSubscriptionTest.cs" />
<Compile Include="Common\CmdletSubscriptionExtensionsTest.cs" />
<Compile Include="Common\CmdletExtensionsTest.cs" />
<Compile Include="Common\GeneralTest.cs" />
<Compile Include="Common\GlobalSettingsManagerTests.cs" />
<Compile Include="Common\GlobalPathInfoTest.cs" />
<Compile Include="Common\SubscriptionsManagerTests.cs" />
<Compile Include="Subscription\SubscriptionsClientTest.cs" />
Expand Down

This file was deleted.

Loading

0 comments on commit e13e6ea

Please sign in to comment.