本文整理汇总了C#中Microsoft.Azure.Commands.Common.Authentication.Models.AzureSubscription类的典型用法代码示例。如果您正苦于以下问题:C# AzureSubscription类的具体用法?C# AzureSubscription怎么用?C# AzureSubscription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AzureSubscription类属于Microsoft.Azure.Commands.Common.Authentication.Models命名空间,在下文中一共展示了AzureSubscription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisableAzureWebsiteApplicationDiagnosticApplication
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());
}
示例2: AzureContext
public AzureContext(AzureSubscription subscription, AzureAccount account, AzureEnvironment environment, AzureTenant tenant)
{
Subscription = subscription;
Account = account;
Environment = environment;
Tenant = tenant;
}
示例3: ExecuteCmdlet
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;
}
}
示例4: IsStorageServiceAvailable
public bool IsStorageServiceAvailable(AzureSubscription subscription, string name)
{
EnsureCloudServiceClientInitialized(subscription);
bool available = this.CloudServiceClient.CheckStorageServiceAvailability(name);
WriteObject(!available);
return available;
}
示例5: ListWebHostingPlansTest
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")));
}
示例6: WebsitesClient
/// <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;
}
示例7: SwitchesSlots
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());
}
示例8: GetCurrentSubscription
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];
}
示例9: SetupEnvironment
/// <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();
}
}
}
示例10: CreateAzureSMProfile
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 = "[email protected]",
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;
}
示例11: StopsWebsiteSlot
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());
}
示例12: ProcessShowWebsiteTest
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();
}
示例13: ValidateSubscription
/// <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);
}
}
示例14: AutomationClient
public AutomationClient(AzureSubscription subscription,
AutomationManagement.IAutomationManagementClient automationManagementClient)
{
Requires.Argument("automationManagementClient", automationManagementClient).NotNull();
this.Subscription = subscription;
this.automationManagementClient = automationManagementClient;
}
示例15: ServerDataServiceCertAuth
/// <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;
}