/// <summary> /// Creates the CDN endpoint. /// </summary> /// <param name="cdn">An authenticated CdnManagementClient</param> private static void CreateCdnEndpoint(CdnManagementClient cdn) { if (endpointAlreadyExists) { Console.WriteLine("Profile {0} already exists.", profileName); } else { Console.WriteLine("Creating endpoint {0} on profile {1}.", endpointName, profileName); EndpointCreateParameters endpointParms = new EndpointCreateParameters() { Origins = new List <DeepCreatedOrigin>() { new DeepCreatedOrigin("Contoso", "www.contoso.com") }, IsHttpAllowed = true, IsHttpsAllowed = true, Location = resourceLocation }; cdn.Endpoints.Create(endpointName, endpointParms, profileName, resourceGroupName); } }
public void CustomDomainCRUDTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); ProfileCreateParameters createParameters = new ProfileCreateParameters { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName); // Create a cdn endpoint with minimum requirements string endpointName = "endpoint-554d5e6b9f56"; var endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); // List custom domains one this endpoint should return none var customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(endpointName, profileName, resourceGroupName); Assert.Equal(0, customDomains.Count()); // NOTE: There is a CName mapping already created for this custom domain and endpoint hostname // "sdk-1-5b4d5e6b9f56.azureedge-test.net" maps to "endpoint-554d5e6b9f56.azureedge-test.net" // "sdk-2-5b4d5e6b9f56.azureedge-test.net" maps to "endpoint-554d5e6b9f56.azureedge-test.net" // Create custom domain on running endpoint should succeed string customDomainName1 = TestUtilities.GenerateName("customDomain"); cdnMgmtClient.CustomDomains.Create(customDomainName1, endpointName, profileName, resourceGroupName, "sdk-1-5b4d5e6b9f56.azureedge-test.net"); // List custom domains one this endpoint should return one customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(endpointName, profileName, resourceGroupName); Assert.Equal(1, customDomains.Count()); // Update custom domain on running endpoint should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.Update(customDomainName1, endpointName, profileName, resourceGroupName, "customdomain11.hello.com"); }); // Stop endpoint cdnMgmtClient.Endpoints.Stop(endpointName, profileName, resourceGroupName); // Create another custom domain on stopped endpoint should succeed string customDomainName2 = TestUtilities.GenerateName("customDomain"); cdnMgmtClient.CustomDomains.Create(customDomainName2, endpointName, profileName, resourceGroupName, "sdk-2-5b4d5e6b9f56.azureedge-test.net"); // List custom domains one this endpoint should return two customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(endpointName, profileName, resourceGroupName); Assert.Equal(2, customDomains.Count()); // Update custom domain on stopped endpoint should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.Update(customDomainName2, endpointName, profileName, resourceGroupName, "customdomain22.hello.com"); }); // Delete second custom domain on stopped endpoint should succeed cdnMgmtClient.CustomDomains.DeleteIfExists(customDomainName2, endpointName, profileName, resourceGroupName); // Get deleted custom domain should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.Get(customDomainName2, endpointName, profileName, resourceGroupName); }); // List custom domains on endpoint should return one customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(endpointName, profileName, resourceGroupName); Assert.Equal(1, customDomains.Count()); // Start endpoint cdnMgmtClient.Endpoints.Start(endpointName, profileName, resourceGroupName); // Delete first custom domain on stopped endpoint should succeed cdnMgmtClient.CustomDomains.DeleteIfExists(customDomainName1, endpointName, profileName, resourceGroupName); // Get deleted custom domain should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.Get(customDomainName1, endpointName, profileName, resourceGroupName); }); // List custom domains on endpoint should return none customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(endpointName, profileName, resourceGroupName); Assert.Equal(0, customDomains.Count()); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void EndpointCheckNameAvailabilityTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Generate new endpoint name string endpointName = TestUtilities.GenerateName("endpoint-unique"); // CheckNameAvailability should return true var output = cdnMgmtClient.NameAvailability.CheckNameAvailability(endpointName, ResourceType.MicrosoftCdnProfilesEndpoints); Assert.Equal(output.NameAvailable, true); // Create endpoint with that name then CheckNameAvailability again // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); ProfileCreateParameters createParameters = new ProfileCreateParameters { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName); // Create endpoint with this name var endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); // CheckNameAvailability after endpoint was created should return false output = cdnMgmtClient.NameAvailability.CheckNameAvailability(endpointName, ResourceType.MicrosoftCdnProfilesEndpoints); Assert.Equal(output.NameAvailable, false); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void OriginCreateTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); ProfileCreateParameters createParameters = new ProfileCreateParameters { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName); // Create a cdn endpoint one origin should succeed string endpointName = TestUtilities.GenerateName("endpoint"); var endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); // Create another origin on this endpoint should fail string originName = TestUtilities.GenerateName("origin1"); var originParameters = new OriginParameters { HostName = "host1.hello.com", HttpPort = 9874, HttpsPort = 9090 }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Origins.Create(originName, originParameters, endpointName, profileName, resourceGroupName); }); // Create a cdn endpoint with invalid ports on origin should fail endpointName = TestUtilities.GenerateName("endpoint"); endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com", HttpPort = 99999, HttpsPort = -1111 } } }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Origins.Create(originName, originParameters, endpointName, profileName, resourceGroupName); }); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void OriginGetListTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); ProfileCreateParameters createParameters = new ProfileCreateParameters { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName); // Create a cdn endpoint with minimum requirements string endpointName = TestUtilities.GenerateName("endpoint"); var endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); // Get origin on endpoint should return the deep created origin var origin = cdnMgmtClient.Origins.Get("origin1", endpointName, profileName, resourceGroupName); Assert.NotNull(origin); // Get origins on endpoint should return one var origins = cdnMgmtClient.Origins.ListByEndpoint(endpointName, profileName, resourceGroupName); Assert.Equal(1, origins.Count()); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void EndpointPurgeLoadTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); ProfileCreateParameters createParameters = new ProfileCreateParameters { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName); // Create a cdn endpoint with minimum requirements should succeed string endpointName = TestUtilities.GenerateName("endpoint"); var endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, IsCompressionEnabled = true, OriginHostHeader = "www.bing.com", OriginPath = "/photos", QueryStringCachingBehavior = QueryStringCachingBehavior.IgnoreQueryString, ContentTypesToCompress = new List <string> { "text/html", "text/css" }, Tags = new Dictionary <string, string> { { "kay1", "value1" } }, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = TestUtilities.GenerateName("origin"), HostName = "custom.hello.com" } } }; cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); // Purge content on endpoint should succeed var purgeContentPaths = new List <string> { "/movies/*", "/pictures/pic1.jpg" }; cdnMgmtClient.Endpoints.PurgeContent(endpointName, profileName, resourceGroupName, purgeContentPaths); // Purge content on non-existing endpoint should fail Assert.Throws <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.PurgeContent("fakeEndpoint", profileName, resourceGroupName, purgeContentPaths); }); // Purge content on endpoint with invalid content paths should fail var invalidPurgeContentPaths = new List <string> { "invalidpath!" }; Assert.Throws <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.PurgeContent(endpointName, profileName, resourceGroupName, invalidPurgeContentPaths); }); // Load content on endpoint should succeed var loadContentPaths = new List <string> { "/movies/amazing.mp4", "/pictures/pic1.jpg" }; cdnMgmtClient.Endpoints.LoadContent(endpointName, profileName, resourceGroupName, loadContentPaths); // Load content on non-existing endpoint should fail Assert.Throws <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.LoadContent("fakeEndpoint", profileName, resourceGroupName, loadContentPaths); }); // Load content on endpoint with invalid content paths should fail var invalidLoadContentPaths = new List <string> { "/movies/*" }; Assert.Throws <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.LoadContent(endpointName, profileName, resourceGroupName, invalidLoadContentPaths); }); // Stop the running endpoint cdnMgmtClient.Endpoints.Stop(endpointName, profileName, resourceGroupName); var endpoint = cdnMgmtClient.Endpoints.Get(endpointName, profileName, resourceGroupName); Assert.Equal(endpoint.ResourceState, EndpointResourceState.Stopped); // Purge content on stopped endpoint should fail Assert.Throws <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.PurgeContent(endpointName, profileName, resourceGroupName, purgeContentPaths); }); // Load content on stopped endpoint should fail Assert.Throws <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.LoadContent(endpointName, profileName, resourceGroupName, loadContentPaths); }); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void ValidateCustomDomainTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); ProfileCreateParameters createParameters = new ProfileCreateParameters { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName); // Create a cdn endpoint with minimum requirements string endpointName = "endpoint-5b4f5e6b9ea6"; var endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); //NOTE: There is a CName mapping already created for this custom domain and endpoint hostname // "customdomain31.azureedge-test.net" maps to "endpoint-5b4f5e6b9ea6.azureedge-test.net" // Validate exisiting custom domain should return true var output = cdnMgmtClient.Endpoints.ValidateCustomDomain(endpointName, profileName, resourceGroupName, "customdomain31.azureedge-test.net"); Assert.Equal(output.CustomDomainValidated, true); // Validate non-exisiting custom domain should return false output = cdnMgmtClient.Endpoints.ValidateCustomDomain(endpointName, profileName, resourceGroupName, "customdomain4.hello.com"); Assert.Equal(output.CustomDomainValidated, false); // Validate invalid custom domain should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.ValidateCustomDomain(endpointName, profileName, resourceGroupName, "invalid\\custom/domain"); }); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void EndpointGetListTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); ProfileCreateParameters createParameters = new ProfileCreateParameters { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName); // List endpoints should return none var endpoints = cdnMgmtClient.Endpoints.ListByProfile(profileName, resourceGroupName); Assert.Equal(0, endpoints.Count()); // Create a cdn endpoint should succeed string endpointName = TestUtilities.GenerateName("endpoint"); var endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); // Get endpoint returns the created endpoint var existingEndpoint = cdnMgmtClient.Endpoints.Get(endpointName, profileName, resourceGroupName); Assert.NotNull(existingEndpoint); Assert.Equal(existingEndpoint.ResourceState, EndpointResourceState.Running); // List endpoints should return one endpoint endpoints = cdnMgmtClient.Endpoints.ListByProfile(profileName, resourceGroupName); Assert.Equal(1, endpoints.Count()); // Create a cdn endpoint and don't wait for creation to finish string endpointName2 = TestUtilities.GenerateName("endpoint"); endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; cdnMgmtClient.Endpoints.BeginCreateAsync(endpointName2, endpointCreateParameters, profileName, resourceGroupName).Wait(5000); // List endpoints should return two endpoints endpoints = cdnMgmtClient.Endpoints.ListByProfile(profileName, resourceGroupName); Assert.Equal(2, endpoints.Count()); // Delete first endpoint should succeed cdnMgmtClient.Endpoints.DeleteIfExists(endpointName, profileName, resourceGroupName); // Get deleted endpoint fails Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.Get(endpointName, profileName, resourceGroupName); }); // List endpoints should return 1 endpoint endpoints = cdnMgmtClient.Endpoints.ListByProfile(profileName, resourceGroupName); Assert.Equal(1, endpoints.Count()); // Wait for second endpoint to complete creation CdnTestUtilities.WaitIfNotInPlaybackMode(); // Delete second endpoint but don't wait for operation to complete cdnMgmtClient.Endpoints.BeginDeleteIfExistsAsync(endpointName2, profileName, resourceGroupName).Wait(2000); // Get second endpoint returns endpoint in Deleting state existingEndpoint = cdnMgmtClient.Endpoints.Get(endpointName2, profileName, resourceGroupName); Assert.Equal(existingEndpoint.ResourceState, EndpointResourceState.Deleting); // Wait for second endpoint deletion to complete CdnTestUtilities.WaitIfNotInPlaybackMode(); // List endpoints should return none endpoints = cdnMgmtClient.Endpoints.ListByProfile(profileName, resourceGroupName); Assert.Equal(0, endpoints.Count()); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void EndpointCreateTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); ProfileCreateParameters createParameters = new ProfileCreateParameters { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName); // Create a cdn endpoint with minimum requirements should succeed string endpointName = TestUtilities.GenerateName("endpoint"); var endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); var existingEndpoint = cdnMgmtClient.Endpoints.Get(endpointName, profileName, resourceGroupName); // Create endpoint with same name should fail endpointCreateParameters = new EndpointCreateParameters { Location = "EastUs", IsHttpAllowed = false, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin2", HostName = "host2.hello.com" } } }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); }); // Create a cdn endpoint with full properties should succeed endpointName = TestUtilities.GenerateName("endpoint"); endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, IsCompressionEnabled = true, OriginHostHeader = "www.bing.com", OriginPath = "/photos", QueryStringCachingBehavior = QueryStringCachingBehavior.BypassCaching, ContentTypesToCompress = new List <string> { "text/html", "application/octet-stream" }, Tags = new Dictionary <string, string> { { "kay1", "value1" } }, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; endpoint = cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); Assert.NotNull(endpoint); // Create a cdn endpoint with no origins should fail endpointName = TestUtilities.GenerateName("endpoint"); endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, IsCompressionEnabled = true, OriginHostHeader = "www.bing.com", OriginPath = "/photos", QueryStringCachingBehavior = QueryStringCachingBehavior.BypassCaching, ContentTypesToCompress = new List <string> { "text/html", "application/octet-stream" }, Tags = new Dictionary <string, string> { { "kay1", "value1" } } }; Assert.ThrowsAny <ValidationException>(() => { cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); }); // Create a cdn endpoint with both http and https disallowed should fail endpointName = TestUtilities.GenerateName("endpoint"); endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = false, IsHttpsAllowed = false, IsCompressionEnabled = true, OriginHostHeader = "www.bing.com", OriginPath = "/photos", QueryStringCachingBehavior = QueryStringCachingBehavior.BypassCaching, ContentTypesToCompress = new List <string> { "text/html", "application/octet-stream" }, Tags = new Dictionary <string, string> { { "kay1", "value1" } } }; Assert.ThrowsAny <ValidationException>(() => { cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); }); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void EndpointUpdateTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); ProfileCreateParameters createParameters = new ProfileCreateParameters { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName); // Create a cdn endpoint with minimum requirements should succeed string endpointName = TestUtilities.GenerateName("endpoint"); var endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); // Update endpoint with invalid origin path should fail var endpointUpdateParameters = new EndpointUpdateParameters { IsHttpAllowed = false, OriginPath = "\\&123invalid_path/.", OriginHostHeader = "www.bing.com" }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.Update(endpointName, endpointUpdateParameters, profileName, resourceGroupName); }); // Update endpoint to enable compression without specifying compression types should fail endpointUpdateParameters = new EndpointUpdateParameters { IsHttpAllowed = false, OriginPath = "/path/valid", OriginHostHeader = "www.bing.com", IsCompressionEnabled = true, QueryStringCachingBehavior = QueryStringCachingBehavior.IgnoreQueryString }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.Update(endpointName, endpointUpdateParameters, profileName, resourceGroupName); }); // Update endpoint with valid properties should succeed endpointUpdateParameters = new EndpointUpdateParameters { IsHttpAllowed = false, OriginPath = "/path/valid", OriginHostHeader = "www.bing.com", IsCompressionEnabled = true, ContentTypesToCompress = new List <string> { "text/html", "application/octet-stream" }, QueryStringCachingBehavior = QueryStringCachingBehavior.IgnoreQueryString }; var endpoint = cdnMgmtClient.Endpoints.Update(endpointName, endpointUpdateParameters, profileName, resourceGroupName); // Create a cdn endpoint but don't wait for creation to complete endpointName = TestUtilities.GenerateName("endpoint"); endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; cdnMgmtClient.Endpoints.BeginCreateAsync(endpointName, endpointCreateParameters, profileName, resourceGroupName).Wait(5000); // Update endpoint in creating state should fail endpointUpdateParameters = new EndpointUpdateParameters { IsHttpAllowed = false, OriginHostHeader = "www.bing.com" }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Endpoints.Update(endpointName, endpointUpdateParameters, profileName, resourceGroupName); }); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
/// <summary> /// Creates a new CDN endpoint with the specified parameters. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='endpointName'> /// Name of the endpoint within the CDN profile. /// </param> /// <param name='endpointProperties'> /// Endpoint properties /// </param> /// <param name='profileName'> /// Name of the CDN profile within the resource group. /// </param> /// <param name='resourceGroupName'> /// Name of the resource group within the Azure subscription. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <Endpoint> BeginCreateAsync(this IEndpointsOperations operations, string endpointName, EndpointCreateParameters endpointProperties, string profileName, string resourceGroupName, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateWithHttpMessagesAsync(endpointName, endpointProperties, profileName, resourceGroupName, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates a new CDN endpoint with the specified parameters. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='endpointName'> /// Name of the endpoint within the CDN profile. /// </param> /// <param name='endpointProperties'> /// Endpoint properties /// </param> /// <param name='profileName'> /// Name of the CDN profile within the resource group. /// </param> /// <param name='resourceGroupName'> /// Name of the resource group within the Azure subscription. /// </param> public static Endpoint BeginCreate(this IEndpointsOperations operations, string endpointName, EndpointCreateParameters endpointProperties, string profileName, string resourceGroupName) { return(Task.Factory.StartNew(s => ((IEndpointsOperations)s).BeginCreateAsync(endpointName, endpointProperties, profileName, resourceGroupName), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }