예제 #1
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);
            }
        }