/// <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 CanConvertValidPSAzureTenants(string domain) { var oldTenant = new PSAzureTenant() { Domain = domain, TenantId = Guid.NewGuid().ToString() }; var tenant = (AzureTenant) oldTenant; Assert.Equal(oldTenant.Domain, tenant.Domain); Assert.Equal(oldTenant.TenantId, tenant.Id.ToString()); }