public static async Task UploadTestApplicationPackageIfNotAlreadyUploadedAsync( string appPackageName, string applicationVersion, string accountName, string resourceGroupName) { using BatchManagementClient mgmtClient = IntegrationTestCommon.OpenBatchManagementClient(); IPage <Application> applicationSummaries = await mgmtClient.Application.ListAsync(resourceGroupName, accountName).ConfigureAwait(false); bool testPackageAlreadyUploaded = applicationSummaries.Any(a => string.Equals(appPackageName, a.Id, StringComparison.OrdinalIgnoreCase)); if (!testPackageAlreadyUploaded) { const string format = "zip"; var addResponse = await mgmtClient.ApplicationPackage.CreateAsync(resourceGroupName, accountName, appPackageName, applicationVersion) .ConfigureAwait(false); var storageUrl = addResponse.StorageUrl; await IntegrationTestCommon.UploadTestApplicationAsync(storageUrl).ConfigureAwait(false); await mgmtClient.ApplicationPackage.ActivateAsync( resourceGroupName, accountName, appPackageName, applicationVersion, format).ConfigureAwait(false); } }
public static async Task DeleteApplicationAsync(string applicationPackage, string resourceGroupName, string accountName) { using BatchManagementClient mgmtClient = IntegrationTestCommon.OpenBatchManagementClient(); await mgmtClient.ApplicationPackage.DeleteAsync(resourceGroupName, accountName, applicationPackage, Version).ConfigureAwait(false); await mgmtClient.Application.DeleteAsync(resourceGroupName, accountName, applicationPackage).ConfigureAwait(false); }
public void TestCreateSha256Pfx() { string filePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.pfx", CertificateFilePrefix)); CertificateBuilder.CreateSelfSignedInFile("Foo", filePath, CertificateBuilder.Sha256Algorithm, password: CommonResources.CertificatePassword); TestCertificateFromRawData(filePath, CertificateBuilder.Sha256Algorithm, CommonResources.CertificatePassword); }
public void TestCreateCerFileFromRawData() { string filePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.cer", CertificateFilePrefix)); CertificateBuilder.CreateSelfSignedInFile("Foo", filePath, CertificateBuilder.Sha1Algorithm); TestCertificateFromRawData(filePath, CertificateBuilder.Sha1Algorithm); }
public ApplicationManagementIntegrationTests() { IntegrationTestCommon.EnableAutoStorageAsync().Wait(); ApplicationIntegrationCommon.UploadTestApplicationPackageIfNotAlreadyUploadedAsync(ApplicationId, ApplicationIntegrationCommon.Version, TestCommon.Configuration.BatchAccountName, TestCommon.Configuration.BatchAccountResourceGroup).Wait(); }
public IntegrationJobApplicationPackageReferencesTests(ITestOutputHelper output) { this.output = output; IntegrationTestCommon.EnableAutoStorageAsync().Wait(); ApplicationPackageCommon.UploadTestApplicationPackageIfNotAlreadyUploadedAsync(AppPackageName, Version).Wait(); ApplicationPackageCommon.UpdateApplicationPackageAsync(AppPackageName, Version, "My First App", false).Wait(); }
public async Task CanAuthenticateToServiceWithAADToken() { Func <Task <string> > tokenProvider = () => IntegrationTestCommon.GetAuthenticationTokenAsync("https://batch.core.windows.net/"); using (var client = BatchClient.Open(new BatchTokenCredentials(TestCommon.Configuration.BatchAccountUrl, tokenProvider))) { await client.JobOperations.ListJobs().ToListAsync(); } }
public async Task End2EndApplicationPackageScenario() { string accountName = TestCommon.Configuration.BatchAccountName; Func <Task> test = async() => { var poolId = "app-ref-test" + Guid.NewGuid(); using (BatchClient client = await TestUtilities.OpenBatchClientFromEnvironmentAsync()) { using (var mgmtClient = IntegrationTestCommon.OpenBatchManagementClient()) { // Give the application a display name await mgmtClient.Application.UpdateAsync(TestCommon.Configuration.BatchAccountResourceGroup, accountName, ApplicationId, new UpdateApplicationParameters { AllowUpdates = true, DefaultVersion = ApplicationIntegrationCommon.Version, DisplayName = DisplayName }).ConfigureAwait(false); List <ApplicationSummary> applicationSummaries = await client.ApplicationOperations.ListApplicationSummaries().ToListAsync().ConfigureAwait(false); ApplicationSummary applicationSummary = applicationSummaries.First(); Assert.Equal(ApplicationIntegrationCommon.Version, applicationSummary.Versions.First()); Assert.Equal(ApplicationId, applicationSummary.Id); Assert.Equal(DisplayName, applicationSummary.DisplayName); ApplicationSummary getApplicationSummary = await client.ApplicationOperations.GetApplicationSummaryAsync(applicationSummary.Id).ConfigureAwait(false); Assert.Equal(getApplicationSummary.Id, applicationSummary.Id); Assert.Equal(getApplicationSummary.Versions.Count(), applicationSummary.Versions.Count()); Assert.Equal(getApplicationSummary.DisplayName, applicationSummary.DisplayName); var appPackage = await mgmtClient.ApplicationPackage.GetAsync( TestCommon.Configuration.BatchAccountResourceGroup, accountName, ApplicationId, ApplicationIntegrationCommon.Version).ConfigureAwait(false); Assert.Equal(PackageState.Active, appPackage.State); Assert.Equal(ApplicationIntegrationCommon.Version, appPackage.Version); Assert.Equal(ApplicationId, appPackage.Id); var application = await mgmtClient.Application.GetAsync(TestCommon.Configuration.BatchAccountResourceGroup, accountName, ApplicationId).ConfigureAwait(false); Assert.Equal(ApplicationIntegrationCommon.Version, application.DefaultVersion); Assert.Equal(ApplicationId, application.Id); await AssertPoolWasCreatedWithApplicationReferences(client, poolId, ApplicationId).ConfigureAwait(false); } } }; await SynchronizationContextHelper.RunTestAsync(test, LongRunningTestTimeout); }
public async Task TestPoolCertificateReferencesWithUpdate() { Func <Task> test = async() => { using (BatchClient batchCli = await TestUtilities.OpenBatchClientAsync(TestUtilities.GetCredentialsFromEnvironment())) { //Generate the certificates const string certificatePrefix = "poolwithcertificatereferences"; string cerFilePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.cer", certificatePrefix)); string pfxFilePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.pfx", certificatePrefix)); IEnumerable <Certificate> certificates = GenerateCertificates(batchCli, cerFilePath, pfxFilePath); try { foreach (Certificate certificate in certificates) { this.testOutputHelper.WriteLine("Adding certificate with thumbprint: {0}", certificate.Thumbprint); await certificate.CommitAsync().ConfigureAwait(false); } List <CertificateReference> certificateReferences = certificates.Select(cer => new CertificateReference(cer) { StoreLocation = CertStoreLocation.LocalMachine, StoreName = "My", Visibility = CertificateVisibility.RemoteUser }).ToList(); await TestPoolCreateAndUpdateWithCertificateReferencesAsync(batchCli, certificateReferences).ConfigureAwait(false); await TestAutoPoolCreateAndUpdateWithCertificateReferencesAsync(batchCli, certificateReferences).ConfigureAwait(false); } finally { File.Delete(pfxFilePath); File.Delete(cerFilePath); foreach (Certificate certificate in certificates) { TestUtilities.DeleteCertificateIfExistsAsync(batchCli, certificate.ThumbprintAlgorithm, certificate.Thumbprint).Wait(); } foreach (Certificate certificate in certificates) { TestUtilities.DeleteCertMonitor(batchCli.CertificateOperations, this.testOutputHelper, certificate.ThumbprintAlgorithm, certificate.Thumbprint); } } } }; await SynchronizationContextHelper.RunTestAsync(test, TestTimeout); }
public void Dispose() { BatchManagementClient mgmtClient = IntegrationTestCommon.OpenBatchManagementClient(); string accountName = TestCommon.Configuration.BatchAccountName; string resourceGroupName = TestCommon.Configuration.BatchAccountResourceGroup; Func <Task> cleanupTask = async() => { await mgmtClient.ApplicationPackage.DeleteAsync(resourceGroupName, accountName, AppPackageName, Version); await mgmtClient.Application.DeleteAsync(resourceGroupName, accountName, AppPackageName); }; Task.Run(cleanupTask).GetAwaiter().GetResult(); }
private static async Task UploadTestApplicationAndActivateAsync(string appPackageName, string applicationVersion, string resourceGroupName, string accountName) { const string format = "zip"; using (BatchManagementClient mgmtClient = IntegrationTestCommon.OpenBatchManagementClient()) { var addResponse = await mgmtClient.ApplicationPackage.CreateAsync(resourceGroupName, accountName, appPackageName, applicationVersion).ConfigureAwait(false); var storageUrl = addResponse.StorageUrl; await IntegrationTestCommon.UploadTestApplicationAsync(storageUrl).ConfigureAwait(false); await mgmtClient.ApplicationPackage.ActivateAsync(resourceGroupName, accountName, appPackageName, applicationVersion, format).ConfigureAwait(false); } }
public static async Task UploadTestApplicationPackageIfNotAlreadyUploadedAsync(string appPackageName, string applicationVersion) { string accountName = TestCommon.Configuration.BatchAccountName; string resourceGroupName = TestCommon.Configuration.BatchAccountResourceGroup; using (BatchManagementClient mgmtClient = IntegrationTestCommon.OpenBatchManagementClient()) { var applicationSummaries = await mgmtClient.Application.ListAsync(resourceGroupName, accountName); bool testPackageAlreadyUploaded = applicationSummaries.Any(a => string.Equals(appPackageName, a.Id, StringComparison.OrdinalIgnoreCase) && string.Equals(applicationVersion, a.DefaultVersion, StringComparison.OrdinalIgnoreCase)); if (!testPackageAlreadyUploaded) { await UploadTestApplicationAndActivateAsync(appPackageName, applicationVersion, resourceGroupName, accountName).ConfigureAwait(false); } } }
public static async Task UpdateApplicationPackageAsync(string applicationId, string defaultVersion, string displayName, bool hasDefaultVersion) { string accountName = TestCommon.Configuration.BatchAccountName; string resourceGroupName = TestCommon.Configuration.BatchAccountResourceGroup; BatchManagementClient mgmtClient = IntegrationTestCommon.OpenBatchManagementClient(); if (hasDefaultVersion) { await mgmtClient.Application.UpdateAsync( resourceGroupName, accountName, applicationId, new UpdateApplicationParameters { AllowUpdates = true, DefaultVersion = defaultVersion, DisplayName = displayName }); } else { await mgmtClient.Application.UpdateAsync( resourceGroupName, accountName, applicationId, new UpdateApplicationParameters { AllowUpdates = true, DisplayName = displayName }); } }
public async Task TestCertificateVerbs() { Func <Task> test = async() => { using (BatchClient batchCli = await TestUtilities.OpenBatchClientAsync(TestUtilities.GetCredentialsFromEnvironment())) { //Generate the certificates const string certificatePrefix = "testcertificatecrud"; string cerFilePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.cer", certificatePrefix)); string pfxFilePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.pfx", certificatePrefix)); IEnumerable <Certificate> certificates = GenerateCertificates(batchCli, cerFilePath, pfxFilePath); try { foreach (Certificate certificate in certificates) { this.testOutputHelper.WriteLine("Adding certificate with thumbprint: {0}", certificate.Thumbprint); await certificate.CommitAsync().ConfigureAwait(false); Certificate boundCert = await batchCli.CertificateOperations.GetCertificateAsync( certificate.ThumbprintAlgorithm, certificate.Thumbprint).ConfigureAwait(false); Assert.Equal(certificate.Thumbprint, boundCert.Thumbprint); Assert.Equal(certificate.ThumbprintAlgorithm, boundCert.ThumbprintAlgorithm); Assert.NotNull(boundCert.Url); Certificate certLowerDetail = await batchCli.CertificateOperations.GetCertificateAsync( certificate.ThumbprintAlgorithm, certificate.Thumbprint, new ODATADetailLevel() { SelectClause = "thumbprint, thumbprintAlgorithm" }).ConfigureAwait(false); // confirm lower detail level Assert.Null(certLowerDetail.Url); //test refresh to higher detail level await certLowerDetail.RefreshAsync(); // confirm higher detail level Assert.NotNull(certLowerDetail.Url); // test refresh can lower detail level await certLowerDetail.RefreshAsync(new ODATADetailLevel() { SelectClause = "thumbprint, thumbprintAlgorithm" }); // confirm lower detail level via refresh Assert.Null(certLowerDetail.Url); } List <CertificateReference> certificateReferences = certificates.Select(cer => new CertificateReference(cer) { StoreLocation = CertStoreLocation.LocalMachine, StoreName = "My", Visibility = CertificateVisibility.RemoteUser }).ToList(); await TestCancelDeleteCertificateAsync(batchCli, certificateReferences, certificates.First()).ConfigureAwait(false); } finally { File.Delete(pfxFilePath); File.Delete(cerFilePath); foreach (Certificate certificate in certificates) { TestUtilities.DeleteCertificateIfExistsAsync(batchCli, certificate.ThumbprintAlgorithm, certificate.Thumbprint).Wait(); } foreach (Certificate certificate in certificates) { TestUtilities.DeleteCertMonitor(batchCli.CertificateOperations, this.testOutputHelper, certificate.ThumbprintAlgorithm, certificate.Thumbprint); } } } }; await SynchronizationContextHelper.RunTestAsync(test, TestTimeout); }
static Task <string> tokenProvider() => IntegrationTestCommon.GetAuthenticationTokenAsync("https://batch.core.windows.net/");