Beispiel #1
0
 private static void VerifyProfileCreated(Profile profile, ProfileCreateParameters parameters)
 {
     Assert.Equal(profile.Location, parameters.Location);
     Assert.Equal(profile.Sku.Name, parameters.Sku.Name);
     Assert.Equal(profile.Tags.Count, parameters.Tags.Count);
     Assert.True(profile.Tags.SequenceEqual(parameters.Tags));
     Assert.Equal(profile.ProvisioningState, ProvisioningState.Succeeded);
     Assert.Equal(profile.ResourceState, ProfileResourceState.Active);
 }
 /// <summary>
 /// Creates a CDN profile.
 /// </summary>
 /// <param name="cdn">An authenticated CdnManagementClient</param>
 private static void CreateCdnProfile(CdnManagementClient cdn)
 {
     if (profileAlreadyExists)
     {
         Console.WriteLine("Profile {0} already exists.", profileName);
     }
     else
     {
         Console.WriteLine("Creating profile {0}.", profileName);
         ProfileCreateParameters profileParms =
             new ProfileCreateParameters()
         {
             Location = resourceLocation, Sku = new Sku(SkuName.StandardVerizon)
         };
         cdn.Profiles.Create(profileName, profileParms, resourceGroupName);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Creates a new CDN profile with the specified parameters.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='profileName'>
 /// Name of the CDN profile within the resource group.
 /// </param>
 /// <param name='profileProperties'>
 /// Profile properties needed for creation.
 /// </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 <Profile> BeginCreateAsync(this IProfilesOperations operations, string profileName, ProfileCreateParameters profileProperties, string resourceGroupName, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateWithHttpMessagesAsync(profileName, profileProperties, resourceGroupName, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Creates a new CDN profile with the specified parameters.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='profileName'>
 /// Name of the CDN profile within the resource group.
 /// </param>
 /// <param name='profileProperties'>
 /// Profile properties needed for creation.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of the resource group within the Azure subscription.
 /// </param>
 public static Profile BeginCreate(this IProfilesOperations operations, string profileName, ProfileCreateParameters profileProperties, string resourceGroupName)
 {
     return(Task.Factory.StartNew(s => ((IProfilesOperations)s).BeginCreateAsync(profileName, profileProperties, resourceGroupName), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Beispiel #5
0
        public void GenerateSsoUriTest()
        {
            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);
                VerifyProfileCreated(profile, createParameters);

                // Generate Sso Uri on created profile should succeed
                var ssoUri = cdnMgmtClient.Profiles.GenerateSsoUri(profileName, resourceGroupName);
                Assert.NotNull(ssoUri);
                Assert.False(string.IsNullOrWhiteSpace(ssoUri.SsoUriValue));

                // Create a cdn profile and don't wait for creation to finish
                profileName      = TestUtilities.GenerateName("profile");
                createParameters = new ProfileCreateParameters
                {
                    Location = "WestUs",
                    Sku      = new Sku {
                        Name = SkuName.StandardVerizon
                    },
                    Tags = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    }
                };

                cdnMgmtClient.Profiles.BeginCreateAsync(profileName, createParameters, resourceGroupName).Wait(2000);

                // Generate Sso Uri on creating profile should fail
                Assert.ThrowsAny <ErrorResponseException>(() => {
                    cdnMgmtClient.Profiles.GenerateSsoUri(profileName, resourceGroupName);
                });

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
Beispiel #6
0
        public void ProfileListBySubcriptionTest()
        {
            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);

                // List profiles should return none
                var profiles = cdnMgmtClient.Profiles.ListBySubscriptionId();
                Assert.Equal(0, profiles.Count());

                // Create resource group
                var resourceGroupName1 = 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, resourceGroupName1);
                VerifyProfileCreated(profile, createParameters);

                // Get profile returns the created profile
                var existingProfile = cdnMgmtClient.Profiles.Get(profileName, resourceGroupName1);
                VerifyProfilesEqual(profile, existingProfile);

                // List profiles should return one profile
                profiles = cdnMgmtClient.Profiles.ListBySubscriptionId();
                Assert.Equal(1, profiles.Count());

                // Create another resource group
                var resourceGroupName2 = CdnTestUtilities.CreateResourceGroup(resourcesClient);

                // Create a second cdn profile and don't wait for creation to finish
                var profileName2 = TestUtilities.GenerateName("profile");
                createParameters = new ProfileCreateParameters
                {
                    Location = "WestUs",
                    Sku      = new Sku {
                        Name = SkuName.StandardVerizon
                    },
                    Tags = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    }
                };

                profile = cdnMgmtClient.Profiles.Create(profileName2, createParameters, resourceGroupName2);
                VerifyProfileCreated(profile, createParameters);

                // List profiles should return two profiles
                profiles = cdnMgmtClient.Profiles.ListBySubscriptionId();
                Assert.Equal(2, profiles.Count());

                // Delete first profile
                cdnMgmtClient.Profiles.DeleteIfExists(profileName, resourceGroupName1);

                // List profiles should return only one profile
                profiles = cdnMgmtClient.Profiles.ListBySubscriptionId();
                Assert.Equal(1, profiles.Count());

                // Delete second profile
                cdnMgmtClient.Profiles.DeleteIfExists(profileName2, resourceGroupName2);

                // List profiles should none
                profiles = cdnMgmtClient.Profiles.ListBySubscriptionId();
                Assert.Equal(0, profiles.Count());

                // Delete resource groups
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName1);
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName2);
            }
        }
Beispiel #7
0
        public void ProfileCreateTest()
        {
            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);
                VerifyProfileCreated(profile, createParameters);

                // Create a premium cdn profile
                profileName      = TestUtilities.GenerateName("profile");
                createParameters = new ProfileCreateParameters
                {
                    Location = "EastUs",
                    Sku      = new Sku {
                        Name = SkuName.PremiumVerizon
                    },
                    Tags = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    }
                };

                profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName);
                VerifyProfileCreated(profile, createParameters);

                // Create profile with same name but different params should fail
                createParameters = new ProfileCreateParameters
                {
                    Location = "WestUs",
                    Sku      = new Sku {
                        Name = SkuName.StandardVerizon
                    },
                    Tags = new Dictionary <string, string>()
                };

                Assert.ThrowsAny <ErrorResponseException>(() => {
                    cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName);
                });

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
        public void ProfileUpdateTest()
        {
            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);
                VerifyProfileCreated(profile, createParameters);

                // Update profile with new tags
                var newTags = new Dictionary <string, string>
                {
                    { "newkey1", "newValue1" }
                };

                var updatedProfile = cdnMgmtClient.Profiles.Update(profileName, resourceGroupName, newTags);
                VerifyProfileUpdated(profile, updatedProfile, newTags);

                // Create a standard cdn profile and don't wait for creation to finish
                profileName      = TestUtilities.GenerateName("profile");
                createParameters = new ProfileCreateParameters
                {
                    Location = "WestUs",
                    Sku      = new Sku {
                        Name = SkuName.StandardVerizon
                    },
                    Tags = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    }
                };

                cdnMgmtClient.Profiles.BeginCreateAsync(profileName, createParameters, resourceGroupName).Wait(2000);

                // Update profile in creating state should fail
                var tags = new Dictionary <string, string>
                {
                    { "key", "value" }
                };

                Assert.ThrowsAny <ErrorResponseException>(() => {
                    cdnMgmtClient.Profiles.Update(profileName, resourceGroupName, tags);
                });

                // Wait for second profile to complete creation
                CdnTestUtilities.WaitIfNotInPlaybackMode();

                // Update profile now should succeed
                cdnMgmtClient.Profiles.Update(profileName, resourceGroupName, tags);

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
Beispiel #10
0
        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);
            }
        }
Beispiel #11
0
        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);
            }
        }
Beispiel #12
0
        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);
            }
        }
Beispiel #13
0
        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);
            }
        }
Beispiel #14
0
        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);
            }
        }
Beispiel #15
0
        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);
            }
        }
Beispiel #16
0
        public void ProfileGetListTest()
        {
            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);

                // List profiles should return none
                var profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName);
                Assert.Equal(0, profiles.Count());

                // 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);
                VerifyProfileCreated(profile, createParameters);

                // Get profile returns the created profile
                var existingProfile = cdnMgmtClient.Profiles.Get(profileName, resourceGroupName);
                VerifyProfilesEqual(profile, existingProfile);

                // List profiles should return one profile
                profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName);
                Assert.Equal(1, profiles.Count());

                // Create a second cdn profile and don't wait for creation to finish
                var profileName2 = TestUtilities.GenerateName("profile");
                createParameters = new ProfileCreateParameters
                {
                    Location = "WestUs",
                    Sku      = new Sku {
                        Name = SkuName.StandardVerizon
                    },
                    Tags = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    }
                };

                cdnMgmtClient.Profiles.BeginCreateAsync(profileName2, createParameters, resourceGroupName).Wait(2000);

                // List profiles should return two profiles
                profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName);
                Assert.Equal(2, profiles.Count());

                // Delete first profile
                cdnMgmtClient.Profiles.DeleteIfExists(profileName, resourceGroupName);

                // Get deleted profile should fail
                Assert.ThrowsAny <ErrorResponseException>(() => {
                    cdnMgmtClient.Profiles.Get(profileName, resourceGroupName);
                });

                // List profiles should return only one profile
                profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName);
                Assert.Equal(1, profiles.Count());

                // Wait for second profile to complete creation
                CdnTestUtilities.WaitIfNotInPlaybackMode();

                // Delete second profile but don't wait for operation to complete
                cdnMgmtClient.Profiles.BeginDeleteIfExistsAsync(profileName2, resourceGroupName).Wait(2000);

                // Get second profile returns profile in Deleting state
                existingProfile = cdnMgmtClient.Profiles.Get(profileName2, resourceGroupName);
                Assert.Equal(existingProfile.ResourceState, ProfileResourceState.Deleting);

                // Wait for second profile to complete creation
                CdnTestUtilities.WaitIfNotInPlaybackMode();

                // List profiles should none
                profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName);
                Assert.Equal(0, profiles.Count());

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
Beispiel #17
0
        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);
            }
        }
Beispiel #18
0
        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);
            }
        }