public void CleansDefaultSubscriptionTwice() { // Setup Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>(); SelectAzureSubscriptionCommand cmdlet = new SelectAzureSubscriptionCommand() { CommandRuntime = commandRuntimeMock.Object, PassThru = true, NoDefault = true }; // Test cmdlet.ExecuteCmdlet(); cmdlet.ExecuteCmdlet(); // Assert that no exception is thrown Assert.True(true); }
public void SelectAzureSubscriptionByInvalidGuidThrowsException() { SelectAzureSubscriptionCommand cmdlt = new SelectAzureSubscriptionCommand(); SetupDefaultProfile(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("SelectSubscriptionByIdParameterSet"); string invalidGuid = "foo"; cmdlt.SubscriptionId = invalidGuid; // Act cmdlt.InvokeBeginProcessing(); try { cmdlt.ExecuteCmdlet(); Assert.True(false); } catch (ArgumentException ex) { Assert.Contains(string.Format(Microsoft.WindowsAzure.Commands.Common.Properties.Resources.InvalidGuid, invalidGuid), ex.Message); } }
public void SelectAzureSubscriptionByInvalidIdThrowsException() { SetupDefaultProfile(); SelectAzureSubscriptionCommand cmdlt = new SelectAzureSubscriptionCommand(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("SelectSubscriptionByIdParameterSet"); string invalidGuid = Guid.NewGuid().ToString(); cmdlt.SubscriptionId = invalidGuid; // Act cmdlt.InvokeBeginProcessing(); try { cmdlt.ExecuteCmdlet(); Assert.True(false); } catch (ArgumentException ex) { Assert.Contains(string.Format("The subscription id {0} doesn't exist.\r\nParameter name: id", invalidGuid), ex.Message); } }
public void SelectDefaultAzureSubscriptionByIdAndNoDefaultUpdatesProfile() { var client = SetupDefaultProfile(); SelectAzureSubscriptionCommand cmdlt = new SelectAzureSubscriptionCommand(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("SelectDefaultSubscriptionByIdParameterSet"); cmdlt.SubscriptionId = azureSubscription2.Id.ToString(); cmdlt.Default = new SwitchParameter(true); Assert.NotEqual(azureSubscription2.Id, client.Profile.DefaultSubscription.Id); // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify client = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile))); Assert.NotNull(client.Profile.DefaultSubscription); Assert.Equal(azureSubscription2.Id, client.Profile.DefaultSubscription.Id); cmdlt = new SelectAzureSubscriptionCommand(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("NoDefaultSubscriptionParameterSet"); cmdlt.NoDefault = new SwitchParameter(true); // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify client = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile))); Assert.Null(client.Profile.DefaultSubscription); }
public void SelectAzureSubscriptionWithPassthroughPrintsSubscription() { SetupDefaultProfile(); SelectAzureSubscriptionCommand cmdlt = new SelectAzureSubscriptionCommand(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("SelectSubscriptionByNameParameterSet"); cmdlt.SubscriptionName = azureSubscription2.Name; cmdlt.PassThru = new SwitchParameter(true); // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.Equal(1, commandRuntimeMock.OutputPipeline.Count); Assert.True(commandRuntimeMock.OutputPipeline[0] is AzureSubscription); }
public void SelectAzureSubscriptionWithoutPassthroughDoesNotPrint() { SetupDefaultProfile(); SelectAzureSubscriptionCommand cmdlt = new SelectAzureSubscriptionCommand(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("SelectSubscriptionByNameParameterSet"); cmdlt.SubscriptionName = azureSubscription2.Name; // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.Equal(0, commandRuntimeMock.OutputPipeline.Count); }
public void SelectAzureSubscriptionByIdWithoutAccountPreservesTheAccount() { SetupDefaultProfile(); SelectAzureSubscriptionCommand cmdlt = new SelectAzureSubscriptionCommand(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("SelectSubscriptionByIdParameterSet"); cmdlt.SubscriptionId = azureSubscription2.Id.ToString(); // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.NotNull(cmdlt.Profile.Context.Subscription); Assert.Equal(azureSubscription2.Account, cmdlt.Profile.Context.Subscription.Account); Assert.Equal(azureSubscription2.Id, cmdlt.Profile.Context.Subscription.Id); }
public void SelectAzureSubscriptionByNameUpdatesCustomProfile() { var client = SetupDefaultProfile(); var profile = SetupCustomProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); SelectAzureSubscriptionCommand cmdlt = new SelectAzureSubscriptionCommand(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("SelectSubscriptionByNameParameterSet"); cmdlt.SubscriptionName = azureSubscription2.Name; cmdlt.Profile = profile; // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.NotNull(cmdlt.Profile.Context.Subscription); Assert.Equal(azureSubscription2.Id, cmdlt.Profile.Context.Subscription.Id); // current profile unchanged Assert.Equal(azureSubscription1.Id, client.Profile.Context.Subscription.Id); }
public void SelectAzureSubscriptionByNameUpdatesProfile() { SetupDefaultProfile(); SelectAzureSubscriptionCommand cmdlt = new SelectAzureSubscriptionCommand(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("SelectSubscriptionByNameParameterSet"); cmdlt.SubscriptionName = azureSubscription2.Name; // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.NotNull(cmdlt.Profile.Context.Subscription); Assert.Equal(azureSubscription2.Id, cmdlt.Profile.Context.Subscription.Id); }
public void SelectAzureSubscriptionByIdAndNoCurrentUpdatesProfile() { SelectAzureSubscriptionCommand cmdlt = new SelectAzureSubscriptionCommand(); SetupDefaultProfile(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("SelectSubscriptionByIdParameterSet"); cmdlt.SubscriptionId = azureSubscription2.Id.ToString(); Assert.Null(AzureSession.CurrentContext.Subscription); // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.NotNull(AzureSession.CurrentContext.Subscription); Assert.Equal(azureSubscription2.Id, AzureSession.CurrentContext.Subscription.Id); cmdlt = new SelectAzureSubscriptionCommand(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("NoCurrentSubscriptionParameterSet"); cmdlt.NoCurrent = new SwitchParameter(true); // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.Null(AzureSession.CurrentContext.Subscription); }
public void SelectDefaultAzureSubscriptionByNameUpdatesProfile() { SelectAzureSubscriptionCommand cmdlt = new SelectAzureSubscriptionCommand(); var client = SetupDefaultProfile(); // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SetParameterSet("SelectDefaultSubscriptionByNameParameterSet"); cmdlt.SubscriptionName = azureSubscription2.Name; cmdlt.Default = new SwitchParameter(true); Assert.NotEqual(azureSubscription2.Id, client.Profile.DefaultSubscription.Id); // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify client = new ProfileClient(); Assert.NotNull(client.Profile.DefaultSubscription); Assert.Equal(azureSubscription2.Id, client.Profile.DefaultSubscription.Id); }
public void SelectAzureSubscriptionByIdWorks() { MockDataStore dataStore = new MockDataStore(); ProfileClient.DataStore = dataStore; ProfileClient client = new ProfileClient(); var tempSubscriptions = new List<AzureSubscription> { new AzureSubscription { Id = new Guid("11111111-1383-4740-8A69-748C5B63ADBA"), Name = "Same Name Subscription", Environment = azureEnvironment.Name, Account = azureAccount.Id, Properties = new Dictionary<AzureSubscription.Property, string> { { AzureSubscription.Property.Default, "True" } } }, new AzureSubscription { Id = new Guid("22222222-1383-4740-8A69-748C5B63ADBA"), Name = "Same Name Subscription", Environment = azureEnvironment.Name, Account = azureAccount.Id, Properties = new Dictionary<AzureSubscription.Property, string>() }, new AzureSubscription { Id = new Guid("33333333-1383-4740-8A69-748C5B63ADBA"), Name = "Same Name Subscription", Environment = azureEnvironment.Name, Account = azureAccount.Id, Properties = new Dictionary<AzureSubscription.Property, string>() } }; client.Profile.Accounts[azureAccount.Id] = azureAccount; client.AddOrSetEnvironment(azureEnvironment); foreach (var s in tempSubscriptions) { client.AddOrSetSubscription(s); } client.SetSubscriptionAsCurrent(tempSubscriptions[0].Name, tempSubscriptions[0].Account); client.Profile.Save(); Assert.Equal(tempSubscriptions[0].Id, AzureSession.CurrentContext.Subscription.Id); var cmdlt = new SelectAzureSubscriptionCommand(); cmdlt.CommandRuntime = new MockCommandRuntime(); cmdlt.SubscriptionId = tempSubscriptions[2].Id.ToString(); cmdlt.SetParameterSet("SelectSubscriptionByIdParameterSet"); // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); Assert.Equal(tempSubscriptions[2].Id, AzureSession.CurrentContext.Subscription.Id); }