Пример #1
0
        public void NameAvailabilityTest_NameNotAvailable()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                string relativeName = TestUtilities.GenerateName("hydratestrelativename");
                string profileName  = TestUtilities.GenerateName("hydratestwatmv2profile");
                ResourceGroupExtended resourceGroup = TrafficManagerHelper.CreateResourceGroup();

                // Create the profile
                trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    new ProfileCreateOrUpdateParameters
                {
                    Profile = TrafficManagerHelper.GenerateDefaultProfile(profileName, relativeName)
                });

                var parameters = new CheckTrafficManagerRelativeDnsNameAvailabilityParameters
                {
                    Name = relativeName,
                    Type = "microsoft.network/trafficmanagerprofiles"
                };

                CheckTrafficManagerRelativeDnsNameAvailabilityResponse response = trafficManagerClient.Profiles.CheckTrafficManagerRelativeDnsNameAvailability(parameters);

                Assert.False(response.NameAvailable);
            }
        }
Пример #2
0
        public void CrudProfileFullCycle()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                string profileName = TestUtilities.GenerateName("hydratestwatmv2profile");
                ResourceGroupExtended resourceGroup = TrafficManagerHelper.CreateResourceGroup();

                // Create the profile
                ProfileCreateOrUpdateResponse createResponse = trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    new ProfileCreateOrUpdateParameters
                {
                    Profile = TrafficManagerHelper.GenerateDefaultProfile(profileName)
                });

                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                // Get the profile
                ProfileGetResponse getResponse = trafficManagerClient.Profiles.Get(
                    resourceGroup.Name,
                    profileName);

                Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);

                // Delete the profile
                AzureOperationResponse deleteResponse = trafficManagerClient.Profiles.Delete(resourceGroup.Name, profileName);
                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);
            }
        }
Пример #3
0
        public void ListProfilesByResourceGroup()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                ResourceGroupExtended resourceGroup = TrafficManagerHelper.CreateResourceGroup();

                for (int i = 0; i < 5; ++i)
                {
                    string profileName = TestUtilities.GenerateName("watmv2profilehydratest");

                    trafficManagerClient.Profiles.CreateOrUpdate(
                        resourceGroup.Name,
                        profileName,
                        new ProfileCreateOrUpdateParameters
                    {
                        Profile = TrafficManagerHelper.GenerateDefaultProfile(profileName)
                    });
                }

                ProfileListResponse listResponse = trafficManagerClient.Profiles.ListAllInResourceGroup(resourceGroup.Name);

                Assert.Equal(5, listResponse.Profiles.Count);
            }
        }
Пример #4
0
        public void CrudProfileFullCycle()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TestUtilities.GenerateName("resourcegroup");
                string        profileName       = TestUtilities.GenerateName("atmprofile");
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                // Create the profile
                trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    TrafficManagerHelper.GenerateDefaultProfile(profileName));

                // Get the profile
                trafficManagerClient.Profiles.Get(
                    resourceGroup.Name,
                    profileName);

                // Delete the profile
                trafficManagerClient.Profiles.Delete(resourceGroup.Name, profileName);

                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Пример #5
0
        public void ListAllProfiles()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TestUtilities.GenerateName("resourcegroup");
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                for (int i = 0; i < 5; ++i)
                {
                    string profileName = TestUtilities.GenerateName("atmprofile");

                    trafficManagerClient.Profiles.CreateOrUpdate(
                        resourceGroup.Name,
                        profileName,
                        TrafficManagerHelper.GenerateDefaultProfile(profileName));
                }

                IEnumerable <Profile> listResponse = trafficManagerClient.Profiles.ListAll();

                // Just in case the subscription had some other profiles
                Assert.True(5 <= listResponse.Count());

                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Пример #6
0
        public void ListProfilesByResourceGroup()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TestUtilities.GenerateName("resourcegroup");
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                for (int i = 0; i < 5; ++i)
                {
                    string profileName = TestUtilities.GenerateName("atmprofile");

                    trafficManagerClient.Profiles.CreateOrUpdate(
                        resourceGroup.Name,
                        profileName,
                        TrafficManagerHelper.GenerateDefaultProfile(profileName));
                }

                List <Profile> listResponse = trafficManagerClient.Profiles.ListAllInResourceGroup(resourceGroup.Name).ToList();

                Assert.Equal(5, listResponse.Count);

                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Пример #7
0
        public void CrudProfileWithoutEndpoints_ThenUpdate()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                string profileName = TestUtilities.GenerateName("hydratestwatmv2profile");
                ResourceGroupExtended resourceGroup = TrafficManagerHelper.CreateResourceGroup();

                Profile profile = TrafficManagerHelper.GenerateDefaultProfile(profileName);
                profile.Properties.Endpoints = null;

                // Create the profile
                ProfileCreateOrUpdateResponse createResponse = trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    new ProfileCreateOrUpdateParameters
                {
                    Profile = profile
                });

                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                profile.Properties.Endpoints = new[]
                {
                    new Endpoint
                    {
                        Id         = null,
                        Name       = "My external endpoint",
                        Type       = "Microsoft.network/TrafficManagerProfiles/ExternalEndpoints",
                        Properties = new EndpointProperties
                        {
                            TargetResourceId = null,
                            Target           = "foobar.contoso.com",
                            EndpointLocation = "North Europe",
                            EndpointStatus   = "Enabled"
                        }
                    }
                };

                // Update the profile
                ProfileCreateOrUpdateResponse updateResponse = trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    new ProfileCreateOrUpdateParameters
                {
                    Profile = profile
                });

                Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode);
            }
        }
Пример #8
0
        public void ListAllProfiles()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                // This tests the list operation at subscription level therefore
                // we can't use any granularity (e.g. resource groups) to isolate test runs
                int numberOfProfilesBeforeTest = trafficManagerClient.Profiles.ListAll().Profiles.Count;

                ResourceGroupExtended resourceGroup1 = TrafficManagerHelper.CreateResourceGroup();
                ResourceGroupExtended resourceGroup2 = TrafficManagerHelper.CreateResourceGroup();

                // Create 2 resource groups with two profiles each
                for (int i = 0; i < 2; ++i)
                {
                    string profileName = TestUtilities.GenerateName("hydratestwatmv2profile");

                    trafficManagerClient.Profiles.CreateOrUpdate(
                        resourceGroup1.Name,
                        profileName,
                        new ProfileCreateOrUpdateParameters
                    {
                        Profile = TrafficManagerHelper.GenerateDefaultProfile(profileName)
                    });

                    trafficManagerClient.Profiles.CreateOrUpdate(
                        resourceGroup2.Name,
                        profileName,
                        new ProfileCreateOrUpdateParameters
                    {
                        Profile = TrafficManagerHelper.GenerateDefaultProfile(profileName)
                    });
                }

                ProfileListResponse listResponse = trafficManagerClient.Profiles.ListAll();

                // At the end of the test we should have 4 profiles more than when we started
                Assert.Equal(numberOfProfilesBeforeTest + 4, listResponse.Profiles.Count);
            }
        }
Пример #9
0
        public void CrudProfileWithoutEndpoints_ThenUpdate()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TestUtilities.GenerateName("resourcegroup");
                string        profileName       = TestUtilities.GenerateName("atmprofile");
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                Profile profile = TrafficManagerHelper.GenerateDefaultProfile(profileName);
                profile.Endpoints = null;

                // Create the profile
                trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    profile);

                profile.Endpoints = new[]
                {
                    new Endpoint
                    {
                        Id               = null,
                        Name             = "My external endpoint",
                        Type             = "Microsoft.network/TrafficManagerProfiles/ExternalEndpoints",
                        TargetResourceId = null,
                        Target           = "foobar.contoso.com",
                        EndpointLocation = "North Europe",
                        EndpointStatus   = "Enabled"
                    }
                };

                // Create the profile
                trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    profile);

                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Пример #10
0
        public void CrudEndpointsFullCycle()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                string profileName  = TestUtilities.GenerateName("hydratestwatmv2profile");
                string endpointName = TestUtilities.GenerateName("hydratestwatmv2endpoint");

                ResourceGroupExtended resourceGroup = TrafficManagerHelper.CreateResourceGroup();

                Profile profile = TrafficManagerHelper.GenerateDefaultProfile(profileName);
                profile.Properties.Endpoints = null;

                // Create profile without endpoints
                trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    new ProfileCreateOrUpdateParameters
                {
                    Profile = profile
                });

                // Create the endpoint
                EndpointCreateOrUpdateResponse createEndpoint = trafficManagerClient.Endpoints.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    "ExternalEndpoints",
                    endpointName,
                    new EndpointCreateOrUpdateParameters
                {
                    Endpoint = TrafficManagerHelper.GenerateDefaultEndpoint(endpointName)
                });

                Assert.Equal(HttpStatusCode.Created, createEndpoint.StatusCode);

                EndpointGetResponse getEndpoint = trafficManagerClient.Endpoints.Get(
                    resourceGroup.Name,
                    profileName,
                    "ExternalEndpoints",
                    endpointName);

                Assert.Equal(HttpStatusCode.OK, getEndpoint.StatusCode);

                Endpoint endpointToUpdate = getEndpoint.Endpoint;

                string oldTarget = endpointToUpdate.Properties.Target;
                string newTarget = "another." + oldTarget;
                endpointToUpdate.Properties.Target = newTarget;

                // Create the endpoint
                EndpointUpdateResponse updateEndpoint = trafficManagerClient.Endpoints.Update(
                    resourceGroup.Name,
                    profileName,
                    "ExternalEndpoints",
                    endpointName,
                    new EndpointUpdateParameters
                {
                    Endpoint = endpointToUpdate
                });

                Assert.Equal(HttpStatusCode.Created, updateEndpoint.StatusCode);
                Assert.Equal(newTarget, updateEndpoint.Endpoint.Properties.Target);

                AzureOperationResponse deleteResponse = trafficManagerClient.Endpoints.Delete(
                    resourceGroup.Name,
                    profileName,
                    "ExternalEndpoints",
                    endpointName);

                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);
            }
        }
Пример #11
0
        public void CrudEndpointGeographicProfile()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                string profileName = TestUtilities.GenerateName("hydratestwatmv2profile");
                ResourceGroupExtended resourceGroup = TrafficManagerHelper.CreateResourceGroup();

                Profile profile = TrafficManagerHelper.GenerateDefaultProfile(profileName);
                profile.Properties.TrafficRoutingMethod = "Geographic";
                profile.Properties.Endpoints            = null;

                // Create the profile
                ProfileCreateOrUpdateResponse createResponse = trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    new ProfileCreateOrUpdateParameters
                {
                    Profile = profile
                });

                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);
                Assert.Equal("Geographic", createResponse.Profile.Properties.TrafficRoutingMethod);

                Endpoint endpoint = new Endpoint
                {
                    Id         = null,
                    Name       = "My external endpoint",
                    Type       = "Microsoft.network/TrafficManagerProfiles/ExternalEndpoints",
                    Properties = new EndpointProperties
                    {
                        TargetResourceId = null,
                        Target           = "foobar.contoso.com",
                        EndpointStatus   = "Enabled",
                        GeoMapping       = new[] { "GEO-AS", "GEO-AF" },
                    }
                };

                // Create the endpoint
                EndpointCreateOrUpdateResponse createEndpointResponse = trafficManagerClient.Endpoints.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    "ExternalEndpoints",
                    endpoint.Name,
                    new EndpointCreateOrUpdateParameters
                {
                    Endpoint = endpoint
                });

                Assert.Equal(HttpStatusCode.Created, createEndpointResponse.StatusCode);
                Assert.Equal("GEO-AS", createEndpointResponse.Endpoint.Properties.GeoMapping[0]);
                Assert.Equal("GEO-AF", createEndpointResponse.Endpoint.Properties.GeoMapping[1]);

                // Get the endpoint
                EndpointGetResponse endpointGetResponse = trafficManagerClient.Endpoints.Get(
                    resourceGroup.Name,
                    profileName,
                    "ExternalEndpoints",
                    endpoint.Name);

                Assert.Equal("GEO-AS", endpointGetResponse.Endpoint.Properties.GeoMapping[0]);
                Assert.Equal("GEO-AF", endpointGetResponse.Endpoint.Properties.GeoMapping[1]);
            }
        }