public void DisableAzureWebsiteApplicationDiagnosticApplication() { // Setup websitesClientMock.Setup(f => f.DisableApplicationDiagnostic( websiteName, WebsiteDiagnosticOutput.FileSystem, null)); disableAzureWebsiteApplicationDiagnosticCommand = new DisableAzureWebsiteApplicationDiagnosticCommand() { CommandRuntime = commandRuntimeMock.Object, Name = websiteName, WebsitesClient = websitesClientMock.Object, File = true, }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription; // Test disableAzureWebsiteApplicationDiagnosticCommand.ExecuteCmdlet(); // Assert websitesClientMock.Verify(f => f.DisableApplicationDiagnostic( websiteName, WebsiteDiagnosticOutput.FileSystem, null), Times.Once()); commandRuntimeMock.Verify(f => f.WriteObject(true), Times.Never()); }
public AzureContext(AzureSubscription subscription, AzureAccount account, AzureEnvironment environment, AzureTenant tenant) { Subscription = subscription; Account = account; Environment = environment; Tenant = tenant; }
public override void ExecuteCmdlet() { switch (ParameterSetName) { case "ByName": IEnumerable<AzureSubscription> subscriptions = new AzureSubscription[0]; if (Profile.Context != null && Profile.Context.Environment != null) { subscriptions = ProfileClient.RefreshSubscriptions(Profile.Context.Environment) .Where( s => SubscriptionName == null || s.Name.Equals(SubscriptionName, StringComparison.InvariantCultureIgnoreCase)); } WriteSubscriptions(subscriptions); break; case "ById": WriteSubscriptions(ProfileClient.GetSubscription(new Guid(SubscriptionId))); break; case "Default": GetDefault(); break; case "Current": GetCurrent(); break; } }
public void ProcessShowWebsiteTest() { // Setup var mockClient = new Mock<IWebsitesClient>(); mockClient.Setup(c => c.GetWebsite("website1", null)) .Returns(new Site { Name = "website1", WebSpace = "webspace1", HostNames = new[] {"website1.cloudapp.com"} }); // Test ShowAzureWebsiteCommand showAzureWebsiteCommand = new ShowAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime(), Name = "website1", WebsitesClient = mockClient.Object }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription; // Show existing website showAzureWebsiteCommand.ExecuteCmdlet(); }
public void SwitchesSlots() { // Setup var mockClient = new Mock<IWebsitesClient>(); string slot1 = WebsiteSlotName.Production.ToString(); string slot2 = "staging"; mockClient.Setup(c => c.GetWebsiteSlots("website1")) .Returns(new List<Site> { new Site { Name = "website1", WebSpace = "webspace1" }, new Site { Name = "website1(staging)", WebSpace = "webspace1" } }); mockClient.Setup(f => f.GetSlotName("website1")).Returns(slot1); mockClient.Setup(f => f.GetSlotName("website1(staging)")).Returns(slot2); mockClient.Setup(f => f.SwitchSlots("webspace1", "website1(staging)", slot1, slot2)).Verifiable(); mockClient.Setup(f => f.GetWebsiteNameFromFullName("website1")).Returns("website1"); // Test SwitchAzureWebsiteSlotCommand switchAzureWebsiteCommand = new SwitchAzureWebsiteSlotCommand { CommandRuntime = new MockCommandRuntime(), WebsitesClient = mockClient.Object, Name = "website1", Force = true }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription { Id = new Guid(base.subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription; // Switch existing website switchAzureWebsiteCommand.ExecuteCmdlet(); mockClient.Verify(c => c.SwitchSlots("webspace1", "website1", slot1, slot2), Times.Once()); }
public void ListWebHostingPlansTest() { // Setup var clientMock = new Mock<IWebsitesClient>(); clientMock.Setup(c => c.ListWebSpaces()) .Returns(new[] {new WebSpace {Name = "webspace1"}, new WebSpace {Name = "webspace2"}}); clientMock.Setup(c => c.ListWebHostingPlans()) .Returns(new List<WebHostingPlan> { new WebHostingPlan {Name = "Plan1", WebSpace = "webspace1"}, new WebHostingPlan { Name = "Plan2", WebSpace = "webspace2" } }); // Test var command = new GetAzureWebHostingPlanCommand { CommandRuntime = new MockCommandRuntime(), WebsitesClient = clientMock.Object }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription{Id = new Guid(subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription; command.ExecuteCmdlet(); var plans = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)command.CommandRuntime).OutputPipeline).Cast<WebHostingPlan>(); Assert.NotNull(plans); Assert.Equal(2, plans.Count()); Assert.True(plans.Any(p => (p).Name.Equals("Plan1") && (p).WebSpace.Equals("webspace1"))); Assert.True(plans.Any(p => (p).Name.Equals("Plan2") && (p).WebSpace.Equals("webspace2"))); }
public bool IsStorageServiceAvailable(AzureSubscription subscription, string name) { EnsureCloudServiceClientInitialized(subscription); bool available = this.CloudServiceClient.CheckStorageServiceAvailability(name); WriteObject(!available); return available; }
/// <summary> /// Creates new WebsitesClient /// </summary> /// <param name="subscription">Subscription containing websites to manipulate</param> /// <param name="logger">The logger action</param> public WebsitesClient(AzureSMProfile profile, AzureSubscription subscription, Action<string> logger) { Logger = logger; cloudServiceClient = new CloudServiceClient(profile, subscription, debugStream: logger); WebsiteManagementClient = AzureSession.ClientFactory.CreateClient<WebSiteManagementClient>(profile, subscription, AzureEnvironment.Endpoint.ServiceManagement); this.subscription = subscription; }
/// <summary> /// Constructs a database adapter /// </summary> /// <param name="profile">The current azure profile</param> /// <param name="subscription">The current azure subscription</param> public AzureSqlDatabaseAdapter(AzureContext context) { Context = context; _subscription = context.Subscription; Communicator = new AzureSqlDatabaseCommunicator(Context); ElasticPoolCommunicator = new AzureSqlElasticPoolCommunicator(Context); }
public static AzureSubscription GetCurrentSubscription() { string certificateThumbprint1 = "jb245f1d1257fw27dfc402e9ecde37e400g0176r"; var newSubscription = new AzureSubscription() { Id = IntegrationTestBase.TestCredentials.SubscriptionId, // Use fake certificate thumbprint Account = certificateThumbprint1, Environment = "AzureCloud" }; newSubscription.Properties[AzureSubscription.Property.Default] = "True"; ProfileClient profileClient = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile))); profileClient.Profile.Accounts[certificateThumbprint1] = new AzureAccount() { Id = certificateThumbprint1, Type = AzureAccount.AccountType.Certificate }; profileClient.Profile.Subscriptions[newSubscription.Id] = newSubscription; profileClient.Profile.Save(); return profileClient.Profile.Subscriptions[newSubscription.Id]; }
/// <summary> /// This overrides the default subscription and default account. This allows the /// test to get the tenant id in the test. /// </summary> public void SetupEnvironment() { base.SetupEnvironment(AzureModule.AzureResourceManager); TestEnvironment csmEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment(); if (csmEnvironment.SubscriptionId != null) { //Overwrite the default subscription and default account //with ones using user ID and tenant ID from auth context var user = GetUser(csmEnvironment); var tenantId = GetTenantId(csmEnvironment); // Existing test will not have a user or tenant id set if (tenantId != null && user != null) { var testSubscription = new AzureSubscription() { Id = new Guid(csmEnvironment.SubscriptionId), Name = AzureRmProfileProvider.Instance.Profile.Context.Subscription.Name, Environment = AzureRmProfileProvider.Instance.Profile.Context.Subscription.Environment, Account = user, Properties = new Dictionary<AzureSubscription.Property, string> { { AzureSubscription.Property.Default, "True" }, { AzureSubscription.Property.StorageAccount, Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT") }, { AzureSubscription.Property.Tenants, tenantId }, } }; var testAccount = new AzureAccount() { Id = user, Type = AzureAccount.AccountType.User, Properties = new Dictionary<AzureAccount.Property, string> { { AzureAccount.Property.Subscriptions, csmEnvironment.SubscriptionId }, } }; AzureRmProfileProvider.Instance.Profile.Context.Subscription.Name = testSubscription.Name; AzureRmProfileProvider.Instance.Profile.Context.Subscription.Id = testSubscription.Id; AzureRmProfileProvider.Instance.Profile.Context.Subscription.Account = testSubscription.Account; var environment = AzureRmProfileProvider.Instance.Profile.Environments[AzureRmProfileProvider.Instance.Profile.Context.Subscription.Environment]; environment.Endpoints[AzureEnvironment.Endpoint.Graph] = csmEnvironment.Endpoints.GraphUri.AbsoluteUri; environment.Endpoints[AzureEnvironment.Endpoint.StorageEndpointSuffix] = "core.windows.net"; AzureRmProfileProvider.Instance.Profile.Save(); } } }
public void StopsWebsiteSlot() { const string slot = "staging"; const string websiteName = "website1"; // Setup Mock<IWebsitesClient> websitesClientMock = new Mock<IWebsitesClient>(); websitesClientMock.Setup(f => f.StopWebsite(websiteName, slot)); // Test StopAzureWebsiteCommand stopAzureWebsiteCommand = new StopAzureWebsiteCommand() { CommandRuntime = new MockCommandRuntime(), Name = websiteName, WebsitesClient = websitesClientMock.Object, Slot = slot }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription; stopAzureWebsiteCommand.ExecuteCmdlet(); websitesClientMock.Verify(f => f.StopWebsite(websiteName, slot), Times.Once()); }
public static AzureSMProfile CreateAzureSMProfile(string storageAccount) { var profile = new AzureSMProfile(); var client = new ProfileClient(profile); var tenantId = Guid.NewGuid(); var subscriptionId = Guid.NewGuid(); var account = new AzureAccount { Id = "*****@*****.**", Type = AzureAccount.AccountType.User }; account.SetProperty(AzureAccount.Property.Tenants, tenantId.ToString()); account.SetProperty(AzureAccount.Property.Subscriptions, subscriptionId.ToString()); var subscription = new AzureSubscription() { Id = subscriptionId, Name = "Test Subscription 1", Environment = EnvironmentName.AzureCloud, Account = account.Id, }; subscription.SetProperty(AzureSubscription.Property.Tenants, tenantId.ToString()); subscription.SetProperty(AzureSubscription.Property.StorageAccount, storageAccount); client.AddOrSetAccount(account); client.AddOrSetSubscription(subscription); client.SetSubscriptionAsDefault(subscriptionId, account.Id); return profile; }
/// <summary> /// Validates that the given subscription is valid. /// </summary> /// <param name="subscription">The <see cref="AzureSubscription"/> to validate.</param> public static void ValidateSubscription(AzureSubscription subscription) { if (subscription == null) { throw new ArgumentException( Common.Properties.Resources.InvalidDefaultSubscription); } }
/// <summary> /// Constructs a database adapter /// </summary> /// <param name="profile">The current azure profile</param> /// <param name="subscription">The current azure subscription</param> public AzureSqlDatabaseReplicationAdapter(AzureContext context) { Context = context; _subscription = context.Subscription; ReplicationCommunicator = new AzureSqlDatabaseReplicationCommunicator(Context); DatabaseCommunicator = new AzureSqlDatabaseCommunicator(Context); ServerCommunicator = new AzureSqlServerCommunicator(Context); }
public AutomationClient(AzureSubscription subscription, AutomationManagement.IAutomationManagementClient automationManagementClient) { Requires.Argument("automationManagementClient", automationManagementClient).NotNull(); this.Subscription = subscription; this.automationManagementClient = automationManagementClient; }
/// <summary> /// Initializes a new instance of the <see cref="ServerDataServiceCertAuth"/> class /// </summary> /// <param name="subscription">The subscription used to connect and authenticate.</param> /// <param name="serverName">The name of the server to connect to.</param> private ServerDataServiceCertAuth( AzureSMProfile profile, AzureSubscription subscription, string serverName) { this.profile = profile; this.serverName = serverName; this.subscription = subscription; }
public AEMHelper(Action<ErrorRecord> errorAction, Action<string> verboseAction, Action<string> warningAction, PSHostUserInterface ui, StorageManagementClient storageClient, AzureSubscription subscription) { this._ErrorAction = errorAction; this._VerboseAction = verboseAction; this._WarningAction = warningAction; this._UI = ui; this._StorageClient = storageClient; this._Subscription = subscription; }
private void EnsureCloudServiceClientInitialized(AzureSubscription subscription) { this.CloudServiceClient = this.CloudServiceClient ?? new CloudServiceClient( Profile, subscription, SessionState.Path.CurrentLocation.Path, WriteDebug, WriteVerbose, WriteWarning); }
public static IHDInsightSubscriptionCredentials GetSubscriptionCertificateCredentials(this IAzureHDInsightCommonCommandBase command, AzureSubscription currentSubscription, AzureAccount azureAccount, AzureEnvironment environment) { return new HDInsightCertificateCredential { SubscriptionId = currentSubscription.Id, Certificate = AzureSession.DataStore.GetCertificate(currentSubscription.Account), Endpoint = environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ServiceManagement), }; }
public void ProfileSerializeDeserializeWorks() { var dataStore = new MockDataStore(); AzureSession.DataStore = dataStore; var profilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AzureSession.ProfileFile); var currentProfile = new AzureRMProfile(profilePath); var tenantId = Guid.NewGuid().ToString(); var environment = new AzureEnvironment { Name = "testCloud", Endpoints = { { AzureEnvironment.Endpoint.ActiveDirectory, "http://contoso.com" } } }; var account = new AzureAccount { Id = "*****@*****.**", Type = AzureAccount.AccountType.User, Properties = { { AzureAccount.Property.Tenants, tenantId } } }; var sub = new AzureSubscription { Account = account.Id, Environment = environment.Name, Id = new Guid(), Name = "Contoso Test Subscription", Properties = { { AzureSubscription.Property.Tenants, tenantId } } }; var tenant = new AzureTenant { Id = new Guid(tenantId), Domain = "contoso.com" }; currentProfile.Context = new AzureContext(sub, account, environment, tenant); currentProfile.Environments[environment.Name] = environment; currentProfile.Context.TokenCache = new byte[] { 1, 2, 3, 4, 5, 6, 8, 9, 0 }; AzureRMProfile deserializedProfile; // Round-trip the exception: Serialize and de-serialize with a BinaryFormatter BinaryFormatter bf = new BinaryFormatter(); using (MemoryStream ms = new MemoryStream()) { // "Save" object state bf.Serialize(ms, currentProfile); // Re-use the same stream for de-serialization ms.Seek(0, 0); // Replace the original exception with de-serialized one deserializedProfile = (AzureRMProfile)bf.Deserialize(ms); } Assert.NotNull(deserializedProfile); var jCurrentProfile = currentProfile.ToString(); var jDeserializedProfile = deserializedProfile.ToString(); Assert.Equal(jCurrentProfile, jDeserializedProfile); }
public StorSimpleClient(AzureSMProfile AzureSMProfile, AzureSubscription currentSubscription) { // Temp code to be able to test internal env. ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };//IgnoreCertificateErrorHandler;//delegate { return true; }; this.Profile = AzureSMProfile; this.cloudServicesClient = AzureSession.ClientFactory.CreateClient<CloudServiceManagementClient>(AzureSMProfile, currentSubscription, AzureEnvironment.Endpoint.ServiceManagement); ResourceCachetimeoutPolicy.AbsoluteExpiration = DateTimeOffset.Now.AddHours(1.0d); }
public void GetAzureWebsiteDeploymentTest() { // Setup var clientMock = new Mock<IWebsitesClient>(); var site1 = new Site { Name = "website1", WebSpace = "webspace1", SiteProperties = new SiteProperties { Properties = new List<NameValuePair> { new NameValuePair {Name = "repositoryuri", Value = "http"}, new NameValuePair {Name = "PublishingUsername", Value = "user1"}, new NameValuePair {Name = "PublishingPassword", Value = "password1"} } } }; clientMock.Setup(c => c.GetWebsite("website1", null)) .Returns(site1); clientMock.Setup(c => c.ListWebSpaces()) .Returns(new[] { new WebSpace { Name = "webspace1" }, new WebSpace { Name = "webspace2" } }); clientMock.Setup(c => c.ListSitesInWebSpace("webspace1")) .Returns(new[] { site1 }); clientMock.Setup(c => c.ListSitesInWebSpace("webspace2")) .Returns(new[] { new Site { Name = "website2", WebSpace = "webspace2" } }); SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement(); deploymentChannel.GetDeploymentsThunk = ar => new List<DeployResult> { new DeployResult(), new DeployResult() }; // Test GetAzureWebsiteDeploymentCommand getAzureWebsiteDeploymentCommand = new GetAzureWebsiteDeploymentCommand(deploymentChannel) { Name = "website1", ShareChannel = true, WebsitesClient = clientMock.Object, CommandRuntime = new MockCommandRuntime(), }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription{Id = new Guid(subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription; getAzureWebsiteDeploymentCommand.ExecuteCmdlet(); var deployments = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline).Cast<DeployResult>(); Assert.NotNull(deployments); Assert.Equal(2, deployments.Count()); }
public PSAzureSubscription(AzureSubscription subscription, AzureSMProfile profile) { SubscriptionId = subscription.Id.ToString(); SubscriptionName = subscription.Name; Environment = subscription.Environment; DefaultAccount = subscription.Account; Accounts = profile.Accounts.Values.Where(a => a.HasSubscription(subscription.Id)).ToArray(); IsDefault = subscription.IsPropertySet(AzureSubscription.Property.Default); IsCurrent = profile.Context != null && profile.Context.Subscription.Id == subscription.Id; CurrentStorageAccountName = subscription.GetProperty(AzureSubscription.Property.StorageAccount); TenantId = subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants).FirstOrDefault(); }
internal static AzureSubscription ToAzureSubscription(this Subscription other, AzureContext context) { var subscription = new AzureSubscription(); subscription.Account = context.Account != null ? context.Account.Id : null; subscription.Environment = context.Environment != null ? context.Environment.Name : EnvironmentName.AzureCloud; subscription.Id = new Guid(other.SubscriptionId); subscription.Name = other.DisplayName; subscription.State = other.State; subscription.SetProperty(AzureSubscription.Property.Tenants, context.Tenant.Id.ToString()); return subscription; }
protected void SetupProfile(string storageName) { currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); AzureSMCmdlet.CurrentProfile = currentProfile; var subscription = new AzureSubscription { Id = new Guid(subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription; if (storageName != null) { currentProfile.Context.Subscription.Properties[AzureSubscription.Property.StorageAccount] = storageName; } currentProfile.Save(); }
public void ProfileSaveDoesNotSerializeContext() { var dataStore = new MockDataStore(); var profilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AzureSession.ProfileFile); var profile = new AzureSMProfile(profilePath); AzureSession.DataStore = dataStore; var tenant = Guid.NewGuid().ToString(); var environment = new AzureEnvironment { Name = "testCloud", Endpoints = { { AzureEnvironment.Endpoint.ActiveDirectory, "http://contoso.com" } } }; var account = new AzureAccount { Id = "*****@*****.**", Type = AzureAccount.AccountType.User, Properties = { { AzureAccount.Property.Tenants, tenant } } }; var sub = new AzureSubscription { Account = account.Id, Environment = environment.Name, Id = new Guid(), Name = "Contoso Test Subscription", Properties = { { AzureSubscription.Property.Tenants, tenant } } }; profile.Environments[environment.Name] = environment; profile.Accounts[account.Id] = account; profile.Subscriptions[sub.Id] = sub; profile.Save(); var profileFile = profile.ProfilePath; string profileContents = dataStore.ReadFileAsText(profileFile); var readProfile = JsonConvert.DeserializeObject<Dictionary<string, object>>(profileContents); Assert.False(readProfile.ContainsKey("DefaultContext")); AzureSMProfile parsedProfile = new AzureSMProfile(); var serializer = new JsonProfileSerializer(); Assert.True(serializer.Deserialize(profileContents, parsedProfile)); Assert.NotNull(parsedProfile); Assert.NotNull(parsedProfile.Environments); Assert.True(parsedProfile.Environments.ContainsKey(environment.Name)); Assert.NotNull(parsedProfile.Accounts); Assert.True(parsedProfile.Accounts.ContainsKey(account.Id)); Assert.NotNull(parsedProfile.Subscriptions); Assert.True(parsedProfile.Subscriptions.ContainsKey(sub.Id)); }
public void GetWebsiteMetricsBasicTest() { // Setup var clientMock = new Mock<IWebsitesClient>(); clientMock.Setup(c => c.ListWebSpaces()) .Returns(new[] {new WebSpace {Name = "webspace1"}, new WebSpace {Name = "webspace2"}}); clientMock.Setup(c => c.ListSitesInWebSpace("webspace1")) .Returns(new[] {new Site {Name = "website1", WebSpace = "webspace1"}}); clientMock.Setup(c => c.GetHistoricalUsageMetrics("website1", null, null, null, null, null, false, false)) .Returns(new[] {new MetricResponse() {Code = "Success", Data = new MetricSet() { Name = "CPU Time", StartTime = DateTime.Parse("7/28/2014 1:00:00 AM", new CultureInfo("en-US")), EndTime = DateTime.Parse("7/28/2014 2:00:00 AM", new CultureInfo("en-US")), Values = new List<MetricSample> { new MetricSample { TimeCreated = DateTime.Parse("7/28/2014 1:00:00 AM", new CultureInfo("en-US")), Total = 201, } } }}}); // Test var command = new GetAzureWebsiteMetricCommand { Name = "website1", CommandRuntime = new MockCommandRuntime(), WebsitesClient = clientMock.Object }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription { Id = new Guid(base.subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription; command.ExecuteCmdlet(); Assert.Equal(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count); var metrics = (MetricResponse)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.NotNull(metrics); Assert.Equal("CPU Time", metrics.Data.Name); Assert.NotNull(metrics.Data.Values); Assert.NotNull(metrics.Data.Values[0]); Assert.Equal(201, metrics.Data.Values[0].Total); }
internal Subscription(AzureSubscription azureSubscription) { if (azureSubscription == null) { throw new ArgumentNullException(); } ProfileClient client = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile))); var environment = client.GetEnvironmentOrDefault(azureSubscription.Environment); this.SubscriptionName = azureSubscription.Name; this.SubscriptionId = azureSubscription.Id.ToString(); this.ServiceEndpoint = new Uri(String.Format("{0}/{1}/services/systemcenter/vmm", environment.GetEndpoint(AzureEnvironment.Endpoint.ServiceManagement).TrimEnd(new[] { '/' }), SubscriptionId)); this.Certificate = FileUtilities.DataStore.GetCertificate(azureSubscription.Account); this.CredentialType = CredentialType.UseCertificate; }
public void ProcessGetMediaServicesTest() { // Setup Mock<IMediaServicesClient> clientMock = new Mock<IMediaServicesClient>(); Guid id1 = Guid.NewGuid(); Guid id2 = Guid.NewGuid(); MediaServicesAccountListResponse response = new MediaServicesAccountListResponse(); response.Accounts.Add(new MediaServicesAccountListResponse.MediaServiceAccount { AccountId = id1.ToString(), Name = "WAMS Account 1" }); response.Accounts.Add(new MediaServicesAccountListResponse.MediaServiceAccount { AccountId = id2.ToString(), Name = "WAMS Account 2" }); clientMock.Setup(f => f.GetMediaServiceAccountsAsync()).Returns(Task.Factory.StartNew(() => response)); // Test GetAzureMediaServiceCommand getAzureMediaServiceCommand = new GetAzureMediaServiceCommand { CommandRuntime = new MockCommandRuntime(), MediaServicesClient = clientMock.Object, }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription { Id = new Guid(SubscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(SubscriptionId)] = subscription; getAzureMediaServiceCommand.ExecuteCmdlet(); IEnumerable<MediaServiceAccount> accounts = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline).Cast<MediaServiceAccount>(); Assert.NotNull(accounts); Assert.Equal(2, accounts.Count()); Assert.True(accounts.Any(mediaservice => (mediaservice).AccountId == id1)); Assert.True(accounts.Any(mediaservice => (mediaservice).AccountId == id2)); Assert.True(accounts.Any(mediaservice => (mediaservice).Name.Equals("WAMS Account 1"))); Assert.True(accounts.Any(mediaservice => (mediaservice).Name.Equals("WAMS Account 2"))); }
/// <summary> /// Creates new instance of AzureContext. /// </summary> /// <param name="subscription">The azure subscription object</param> /// <param name="account">The azure account object</param> /// <param name="environment">The azure environment object</param> public AzureContext(AzureSubscription subscription, AzureAccount account, AzureEnvironment environment) : this(subscription, account, environment, null) { }