public void CreateDefinitionAny() { using (var undoContext = UndoContext.Current) { undoContext.Start(); //Arrange LoadBalancingMethod testMethod = LoadBalancingMethod.Failover; DefinitionEndpointCreateParameters endpointParam = new DefinitionEndpointCreateParameters(); endpointParam.DomainName = ExternalDomain; endpointParam.Status = EndpointStatus.Enabled; endpointParam.Type = EndpointType.Any; endpointParam.Weight = 1; //Arrange + Act + Assert testCreateDefinition(testMethod, endpointParam); } }
public void CreateDefinitionWebsite() { using (var undoContext = UndoContext.Current) { undoContext.Start(); //Arrange using (TrafficManagerTestBase _testFixture = new TrafficManagerTestBase()) { string websiteDomain = _testFixture.CreateTestWebsite(); LoadBalancingMethod testMethod = LoadBalancingMethod.Performance; DefinitionEndpointCreateParameters endpointParam = new DefinitionEndpointCreateParameters(); endpointParam.DomainName = websiteDomain; endpointParam.Status = EndpointStatus.Enabled; endpointParam.Type = EndpointType.AzureWebsite; endpointParam.Weight = 3; //Arrange + Act + Assert testCreateDefinition(testMethod, endpointParam); } } }
public void CreateDefinitionCloudService() { using (var undoContext = UndoContext.Current) { undoContext.Start(); System.Diagnostics.Trace.WriteLine("Cloud service test"); //Arrange using (TrafficManagerTestBase _testFixture = new TrafficManagerTestBase()) { string serviceDomain = _testFixture.CreateTestCloudService(); LoadBalancingMethod testMethod = LoadBalancingMethod.Failover; DefinitionEndpointCreateParameters endpointParam = new DefinitionEndpointCreateParameters(); endpointParam.DomainName = serviceDomain; endpointParam.Status = EndpointStatus.Enabled; endpointParam.Type = EndpointType.CloudService; endpointParam.Weight = 2; //Arrange + Act + Assert testCreateDefinition(testMethod, endpointParam); } } }
public void CreateADefinitionAndEnableTheProfile( string profileName, LoadBalancingMethod loadBalancingMethod, DefinitionEndpointCreateParameters endpointParameter) { CreateADefinitionAndEnableTheProfile( profileName, loadBalancingMethod, new List<DefinitionEndpointCreateParameters>() { endpointParameter }); }
public void CreateADefinitionAndEnableTheProfile( string profileName, string domain, EndpointType endpointType, LoadBalancingMethod testMethod = LoadBalancingMethod.Performance) { DefinitionEndpointCreateParameters endpointParameter = new DefinitionEndpointCreateParameters(); endpointParameter.DomainName = domain; endpointParameter.Status = EndpointStatus.Enabled; endpointParameter.Type = endpointType; CreateADefinitionAndEnableTheProfile(profileName, LoadBalancingMethod.Performance, endpointParameter); }
public DefinitionCreateParameters InstantiateTrafficManagerDefinition( string loadBalancingMethod, int monitorPort, string monitorProtocol, string monitorRelativePath, int ttl, IList<TrafficManagerEndpoint> endpoints) { // Create the definition var definitionParameter = new DefinitionCreateParameters(); var dnsOptions = new DefinitionDnsOptions(); var monitor = new DefinitionMonitor(); var policyParameter = new DefinitionPolicyCreateParameters(); var monitorHttpOption = new DefinitionMonitorHTTPOptions(); dnsOptions.TimeToLiveInSeconds = ttl; monitorHttpOption.RelativePath = monitorRelativePath; monitorHttpOption.Verb = Constants.monitorHttpOptionVerb; monitorHttpOption.ExpectedStatusCode = Constants.monitorHttpOptionExpectedStatusCode; monitor.Protocol = (DefinitionMonitorProtocol)Enum.Parse(typeof(DefinitionMonitorProtocol), monitorProtocol); monitor.IntervalInSeconds = Constants.monitorIntervalInSeconds; monitor.TimeoutInSeconds = Constants.monitorTimeoutInSeconds; monitor.ToleratedNumberOfFailures = Constants.monitorToleratedNumberOfFailures; monitor.Port = monitorPort; policyParameter.LoadBalancingMethod = (LoadBalancingMethod)Enum.Parse(typeof(LoadBalancingMethod), loadBalancingMethod); policyParameter.Endpoints = new List<DefinitionEndpointCreateParameters>(); foreach (TrafficManagerEndpoint endpoint in endpoints) { var endpointParam = new DefinitionEndpointCreateParameters { DomainName = endpoint.DomainName, Location = endpoint.Location, Status = endpoint.Status, Type = endpoint.Type, Weight = endpoint.Weight }; policyParameter.Endpoints.Add(endpointParam); } definitionParameter.DnsOptions = dnsOptions; definitionParameter.Policy = policyParameter; definitionParameter.Monitors.Add(monitor); monitor.HttpOptions = monitorHttpOption; return definitionParameter; }
public DefinitionCreateParameters InstantiateTrafficManagerDefinition(Definition definition) { var definitionCreateParams = new DefinitionCreateParameters(); var endpoints = new List<DefinitionEndpointCreateParameters>(); foreach (DefinitionEndpointResponse endpointReponse in definition.Policy.Endpoints) { var endpoint = new DefinitionEndpointCreateParameters { DomainName = endpointReponse.DomainName, Location = endpointReponse.Location, Type = endpointReponse.Type, Status = endpointReponse.Status, Weight = endpointReponse.Weight }; endpoints.Add(endpoint); } definitionCreateParams.Policy = new DefinitionPolicyCreateParameters { Endpoints = endpoints, LoadBalancingMethod = definition.Policy.LoadBalancingMethod }; definitionCreateParams.DnsOptions = definition.DnsOptions; definitionCreateParams.Monitors = definition.Monitors; return definitionCreateParams; }
public void CreateDefinitionAnyWithLocation() { using (var undoContext = UndoContext.Current) { undoContext.Start(); LoadBalancingMethod testMethod = LoadBalancingMethod.Performance; DefinitionEndpointCreateParameters endpointParam = new DefinitionEndpointCreateParameters(); endpointParam.DomainName = ExternalDomain; endpointParam.Status = EndpointStatus.Enabled; endpointParam.Type = EndpointType.Any; endpointParam.Weight = 1; endpointParam.Location = "West US"; testCreateDefinition(testMethod, endpointParam); } }
private string testCreateDefinition(LoadBalancingMethod testMethod, DefinitionEndpointCreateParameters endpoint) { //Arrange using (TrafficManagerTestBase _testFixture = new TrafficManagerTestBase()) { string profileName = _testFixture.CreateTestProfile(); _testFixture.CreateADefinitionAndEnableTheProfile( profileName, testMethod, endpoint); //Act, try 'List' DefinitionsListResponse listResponse = _testFixture.TrafficManagerClient.Definitions.List(profileName); //Assert Assert.Equal(1, listResponse.Count()); Assert.Equal(testMethod, listResponse.First().Policy.LoadBalancingMethod); //Act, try 'Get' DefinitionGetResponse getResponse = _testFixture.TrafficManagerClient.Definitions.Get(profileName); //Assert Assert.Equal(testMethod, getResponse.Definition.Policy.LoadBalancingMethod); Assert.Equal(1, getResponse.Definition.Policy.Endpoints.Count); Assert.Equal(endpoint.Type, getResponse.Definition.Policy.Endpoints[0].Type); Assert.Equal(endpoint.Weight ?? 1, getResponse.Definition.Policy.Endpoints[0].Weight); Assert.Equal(endpoint.Location, getResponse.Definition.Policy.Endpoints[0].Location); Assert.Equal(endpoint.MinChildEndpoints, getResponse.Definition.Policy.Endpoints[0].MinChildEndpoints); //verify the profile itself has an associated definition enabled. //(due to the service limitation of one defintion per one profile, the enabled version is 1 always ProfileGetResponse profileGetResponse = _testFixture.TrafficManagerClient.Profiles.Get(profileName); Assert.Equal(1, profileGetResponse.Profile.StatusDetails.EnabledDefinitionVersion); return profileGetResponse.Profile.DomainName; } }
public void CreateDefinitionWithTrafficManagerEndpoint() { using (var undoContext = UndoContext.Current) { undoContext.Start(); LoadBalancingMethod testMethod = LoadBalancingMethod.Failover; // Create the nested profile DefinitionEndpointCreateParameters nestedEndpointParam = new DefinitionEndpointCreateParameters(); nestedEndpointParam.DomainName = ExternalDomain; nestedEndpointParam.Status = EndpointStatus.Enabled; nestedEndpointParam.Type = EndpointType.Any; nestedEndpointParam.Location = "West US"; string nestedProfileDomainName = testCreateDefinition(testMethod, nestedEndpointParam); // Create the top level profile DefinitionEndpointCreateParameters topLevelEndpointParam = new DefinitionEndpointCreateParameters(); topLevelEndpointParam.DomainName = nestedProfileDomainName; topLevelEndpointParam.Status = EndpointStatus.Enabled; topLevelEndpointParam.Type = EndpointType.TrafficManager; topLevelEndpointParam.MinChildEndpoints = 2; topLevelEndpointParam.Location = "West US"; testCreateDefinition(testMethod, topLevelEndpointParam); } }
public void CreateDefinitionPerformanceAnyNoLocationFails() { using (var undoContext = UndoContext.Current) { undoContext.Start(); LoadBalancingMethod testMethod = LoadBalancingMethod.Performance; DefinitionEndpointCreateParameters endpointParam = new DefinitionEndpointCreateParameters(); endpointParam.DomainName = ExternalDomain; endpointParam.Status = EndpointStatus.Enabled; endpointParam.Type = EndpointType.Any; endpointParam.Location = "West US"; try { testCreateDefinition(testMethod, endpointParam); } catch (CloudException ce) { if (ce.Error.Message != "The location must be specified for endpoints of type 'Any' in a policy of type 'Performance'.") { throw; } } } }