Azure subscription details.
Exemple #1
0
        /// <summary>
        /// Convert a context from a PSObject
        /// </summary>
        /// <param name="other"></param>
        public PSAzureContext(PSObject other)
        {
            if (other == null || other.Properties == null)
            {
                throw new ArgumentNullException(nameof(other));
            }
            PSObject property;

            if (other.TryGetProperty(nameof(Account), out property))
            {
                Account = new PSAzureRmAccount(property);
            }
            if (other.TryGetProperty(nameof(Environment), out property))
            {
                Environment = new PSAzureEnvironment(property);
            }
            if (other.TryGetProperty(nameof(Subscription), out property))
            {
                Subscription = new PSAzureSubscription(property);
            }
            if (other.TryGetProperty(nameof(Tenant), out property))
            {
                Tenant = new PSAzureTenant(property);
            }
            if (other.TryGetProperty(nameof(TokenCache), out property))
            {
                AzureTokenCache cache = new AzureTokenCache();
                cache.Populate(property);
                TokenCache = new AuthenticationStoreTokenCache(cache);
            }

            VersionProfile = other.GetProperty <string>(nameof(VersionProfile));
            this.PopulateExtensions(other);
        }
 public void CanConvertValidPSAzureSubscriptions(string name, string storageAccount)
  {
      var oldSubscription = new PSAzureSubscription()
      {
          CurrentStorageAccount = storageAccount,
          SubscriptionId = Guid.NewGuid().ToString(),
          SubscriptionName = name,
          TenantId = Guid.NewGuid().ToString()
      };
      var subscription = (AzureSubscription) oldSubscription;
      Assert.Equal(oldSubscription.SubscriptionName, subscription.Name);
      Assert.Equal(oldSubscription.SubscriptionId, subscription.Id.ToString());
      Assert.Equal(oldSubscription.TenantId, subscription.GetProperty(AzureSubscription.Property.Tenants));
      Assert.Equal(storageAccount, subscription.GetProperty(AzureSubscription.Property.StorageAccount));
  }