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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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]); } }