예제 #1
0
        public void SetAzureSubscriptionDerivesEnvironmentFromEnvironmentParameterOnAdd()
        {
            SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand();
            // Setup
            ProfileClient client = new ProfileClient();

            client.AddOrSetEnvironment(azureEnvironment);
            client.Profile.Save();

            cmdlt.CommandRuntime            = commandRuntimeMock.Object;
            cmdlt.SubscriptionId            = Guid.NewGuid().ToString();
            cmdlt.SubscriptionName          = "NewSubscriptionName";
            cmdlt.CurrentStorageAccountName = "NewCloudStorage";
            cmdlt.Environment = azureEnvironment.Name;
            cmdlt.Certificate = SampleCertificate;

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            client = new ProfileClient();
            var newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)];

            Assert.Equal(cmdlt.SubscriptionName, newSubscription.Name);
            Assert.Equal(cmdlt.Environment, newSubscription.Environment);
            Assert.Equal(cmdlt.CurrentStorageAccountName, newSubscription.GetProperty(AzureSubscription.Property.StorageAccount));
        }
예제 #2
0
        public void SetAzureSubscriptionAddsSubscriptionWithCertificate()
        {
            SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand();

            // Setup
            cmdlt.CommandRuntime            = commandRuntimeMock.Object;
            cmdlt.SubscriptionId            = Guid.NewGuid().ToString();
            cmdlt.SubscriptionName          = "NewSubscriptionName";
            cmdlt.CurrentStorageAccountName = "NewCloudStorage";
            cmdlt.Certificate = SampleCertificate;

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            ProfileClient client          = new ProfileClient();
            var           newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)];
            var           newAccount      = client.Profile.Accounts[SampleCertificate.Thumbprint];

            Assert.Equal(cmdlt.SubscriptionName, newSubscription.Name);
            Assert.Equal(EnvironmentName.AzureCloud, newSubscription.Environment);
            Assert.Equal(cmdlt.CurrentStorageAccountName, newSubscription.GetProperty(AzureSubscription.Property.StorageAccount));

            Assert.Equal(newAccount.Id, newSubscription.Account);
            Assert.Equal(AzureAccount.AccountType.Certificate, newAccount.Type);
            Assert.Equal(SampleCertificate.Thumbprint, newAccount.Id);
            Assert.Equal(cmdlt.SubscriptionId, newAccount.GetProperty(AzureAccount.Property.Subscriptions));
        }
예제 #3
0
        public void SetAzureSubscriptionDerivesEnvironmentFromBothEndpointParameters()
        {
            SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand();
            // Setup
            ProfileClient client = new ProfileClient();

            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.Profile.Save();

            cmdlt.CommandRuntime            = commandRuntimeMock.Object;
            cmdlt.SubscriptionId            = azureSubscription1.Id.ToString();
            cmdlt.CurrentStorageAccountName = "NewCloudStorage";
            cmdlt.ServiceEndpoint           = azureEnvironment.GetEndpoint(AzureEnvironment.Endpoint.ServiceManagement);
            cmdlt.ResourceManagerEndpoint   = azureEnvironment.GetEndpoint(AzureEnvironment.Endpoint.ResourceManager);

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            client = new ProfileClient();
            var newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)];

            Assert.Equal(cmdlt.Environment, newSubscription.Environment);
            Assert.Equal(cmdlt.CurrentStorageAccountName, newSubscription.GetProperty(AzureSubscription.Property.StorageAccount));
        }
예제 #4
0
        public void SetAzureSubscriptionThrowsExceptionWithoutCertificateOnAdd()
        {
            SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand();
            // Setup
            ProfileClient client = new ProfileClient();

            client.AddOrSetEnvironment(azureEnvironment);
            client.Profile.Save();

            cmdlt.CommandRuntime            = commandRuntimeMock.Object;
            cmdlt.SubscriptionId            = Guid.NewGuid().ToString();
            cmdlt.SubscriptionName          = "NewSubscriptionName";
            cmdlt.CurrentStorageAccountName = "NewCloudStorage";
            cmdlt.Environment = azureEnvironment.Name;

            // Verify
            cmdlt.InvokeBeginProcessing();
            Assert.Throws <ArgumentException>(() => cmdlt.ExecuteCmdlet());
        }
예제 #5
0
        public void SetAzureSubscriptionUpdatesSubscriptionWithCertificate()
        {
            SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand();

            // Setup
            ProfileClient client = new ProfileClient();

            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.Profile.Save();

            cmdlt.CommandRuntime            = commandRuntimeMock.Object;
            cmdlt.SubscriptionId            = azureSubscription1.Id.ToString();
            cmdlt.CurrentStorageAccountName = "NewCloudStorage";
            cmdlt.Certificate = SampleCertificate;

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            client = new ProfileClient();
            var newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)];
            var newAccount      = client.Profile.Accounts[SampleCertificate.Thumbprint];
            var existingAccount = client.Profile.Accounts[azureAccount.Id];

            Assert.Equal(azureEnvironment.Name, newSubscription.Environment);
            Assert.Equal(cmdlt.CurrentStorageAccountName, newSubscription.GetProperty(AzureSubscription.Property.StorageAccount));

            Assert.Equal(newAccount.Id, newSubscription.Account);
            Assert.Equal(AzureAccount.AccountType.Certificate, newAccount.Type);
            Assert.Equal(SampleCertificate.Thumbprint, newAccount.Id);
            Assert.Equal(cmdlt.SubscriptionId, newAccount.GetProperty(AzureAccount.Property.Subscriptions));

            Assert.Equal(azureAccount.Id, existingAccount.Id);
            Assert.Equal(AzureAccount.AccountType.User, existingAccount.Type);
            Assert.True(existingAccount.GetPropertyAsArray(AzureAccount.Property.Subscriptions).Contains(cmdlt.SubscriptionId));
        }