示例#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 CanConvertValidPSAzureAccounts(string id, AzureAccount.AccountType type)
  {
      var oldAccount = new PSAzureRmAccount
      {
          Id = id,
          AccountType = type.ToString()
      };
      var account = (AzureAccount) oldAccount;
      Assert.Equal(oldAccount.AccountType, account.Type.ToString());
      Assert.Equal(oldAccount.Id, account.Id);
  }