Example #1
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);
            }
        }
Example #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);
            }
        }
Example #3
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);
            }
        }
Example #4
0
        public void CrudProfileFullCycle()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TrafficManagerHelper.GenerateName();
                string        profileName       = TrafficManagerHelper.GenerateName();
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                TrafficManagerHelper.CreateOrUpdateDefaultProfileWithExternalEndpoint(
                    trafficManagerClient,
                    resourceGroup.Name,
                    profileName);

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

                // Delete the profile
                trafficManagerClient.Profiles.Delete(resourceGroup.Name, profileName);
                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Example #5
0
        public void ListAllProfiles()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TrafficManagerHelper.GenerateName();
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);
                List <string> profileNames      = new List <string>();

                for (int i = 0; i < 5; ++i)
                {
                    string profileName = TrafficManagerHelper.GenerateName();
                    profileNames.Add(profileName);

                    TrafficManagerHelper.CreateOrUpdateDefaultProfileWithExternalEndpoint(
                        trafficManagerClient,
                        resourceGroupName,
                        profileName);
                }

                IEnumerable <Profile> listResponse = trafficManagerClient.Profiles.ListBySubscriptionWithHttpMessagesAsync().Result.Body;

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

                // Delete the profiles
                foreach (var profileName in profileNames)
                {
                    trafficManagerClient.Profiles.DeleteWithHttpMessagesAsync(resourceGroup.Name, profileName);
                }

                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Example #6
0
        public void CrudProfileWithMultiValue()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TrafficManagerHelper.GenerateName();
                string        profileName       = TrafficManagerHelper.GenerateName();
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                // Create the profile
                var expectedProfile = TrafficManagerHelper.CreateOrUpdateProfileWithMultiValue(
                    trafficManagerClient,
                    resourceGroupName,
                    profileName,
                    3);

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

                Assert.Equal(3, expectedProfile.MaxReturn);

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

                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Example #7
0
        public void CrudProfileWithoutEndpoints_ThenUpdate()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TrafficManagerHelper.GenerateName();
                string        profileName       = TrafficManagerHelper.GenerateName();
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                // Create the profile
                Profile profile = TrafficManagerHelper.CreateOrUpdateDefaultEmptyProfile(
                    trafficManagerClient,
                    resourceGroupName,
                    profileName);

                Assert.Equal(0, profile.Endpoints.Count);

                // Create the endpoint and associate it with the resource group and profile.
                TrafficManagerHelper.CreateOrUpdateDefaultEndpoint(trafficManagerClient, resourceGroupName, profileName);

                // Confirm the endpoint is associated with the profile.
                Profile updatedProfile = trafficManagerClient.Profiles.Get(
                    resourceGroup.Name,
                    profileName);

                Assert.Equal(1, updatedProfile.Endpoints.Count);

                // Delete the profile. The associated endpoint will also be deleted.
                trafficManagerClient.Profiles.DeleteWithHttpMessagesAsync(resourceGroup.Name, profileName);
                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Example #8
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);
            }
        }
Example #9
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);
            }
        }
Example #10
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);
            }
        }
Example #11
0
        public void GetDefaultGeographicHierarchy()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                GeographicHierarchyGetResponse hierarchyResponse = trafficManagerClient.GeographicHierarchy.GetDefault();
                Assert.NotNull(hierarchyResponse);
                Assert.NotNull(hierarchyResponse.GeographicHierarchy);
                Assert.NotNull(hierarchyResponse.GeographicHierarchy.Properties);
                Assert.NotNull(hierarchyResponse.GeographicHierarchy.Properties.Root);
                HierarchyRoot root = hierarchyResponse.GeographicHierarchy.Properties.Root;

                Assert.Equal("WORLD", root.Code);
                Assert.Equal("World", root.Name);
                Assert.NotEmpty(root.Regions);

                foreach (var grouping in root.Regions)
                {
                    Assert.NotNull(grouping.Code);
                    Assert.NotEmpty(grouping.Code);
                    Assert.NotNull(grouping.Name);
                    Assert.NotEmpty(grouping.Name);
                    Assert.NotEmpty(grouping.Regions);
                }
            }
        }
Example #12
0
        public void EmptyHeatMapData()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TrafficManagerHelper.GenerateName();
                string        profileName       = TrafficManagerHelper.GenerateName();
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                TrafficManagerHelper.CreateOrUpdateDefaultProfileWithExternalEndpoint(
                    trafficManagerClient,
                    resourceGroup.Name,
                    profileName,
                    "Performance",
                    "Enabled");

                try
                {
                    trafficManagerClient.HeatMap.Get(resourceGroupName, profileName);
                }
                catch (Microsoft.Rest.Azure.CloudException e)
                {
                    Assert.Contains("NotFound", e.Body.Code);
                }
            }
        }
Example #13
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);
            }
        }
Example #14
0
        public void CrudEndpointGeographicProfile()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TrafficManagerHelper.GenerateName();
                string        profileName       = TrafficManagerHelper.GenerateName();
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                // Create the profile
                Profile profile = trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    TrafficManagerHelper.GenerateDefaultEmptyProfile(profileName, "Geographic"));

                Assert.Equal("Geographic", profile.TrafficRoutingMethod);

                Endpoint endpoint = new Endpoint(
                    null,
                    "My external endpoint",
                    "Microsoft.Network/trafficManagerProfiles/ExternalEndpoints");
                endpoint.TargetResourceId = null;
                endpoint.Target           = "foobar.contoso.com";
                endpoint.EndpointStatus   = "Enabled";
                endpoint.GeoMapping       = new[] { "GEO-AS", "GEO-AF" };

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

                Assert.Equal("GEO-AS", createEndpointResponse.GeoMapping[0]);
                Assert.Equal("GEO-AF", createEndpointResponse.GeoMapping[1]);

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

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

                // Delete the profile
                trafficManagerClient.Profiles.Delete(resourceGroup.Name, profileName);
                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Example #15
0
        public void CrudProfileWithMinChildEndpointsIp()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TrafficManagerHelper.GenerateName();
                string        profileName       = TrafficManagerHelper.GenerateName();
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                // Create the profile. This is multi-value and will have non-default min child endpoints.
                var expectedProfile = TrafficManagerHelper.CreateOrUpdateProfileWithMultiValue(
                    trafficManagerClient,
                    resourceGroupName,
                    profileName,
                    3,
                    77,
                    66,
                    55);

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

                Assert.Equal(5, expectedProfile.Endpoints.Count);

                Assert.Equal(77, expectedProfile.Endpoints[0].MinChildEndpoints);
                Assert.Equal(66, expectedProfile.Endpoints[0].MinChildEndpointsIPv4);
                Assert.Equal(55, expectedProfile.Endpoints[0].MinChildEndpointsIPv6);

                Assert.Equal(78, expectedProfile.Endpoints[1].MinChildEndpoints);
                Assert.Equal(67, expectedProfile.Endpoints[1].MinChildEndpointsIPv4);
                Assert.Equal(56, expectedProfile.Endpoints[1].MinChildEndpointsIPv6);

                Assert.Equal(79, expectedProfile.Endpoints[2].MinChildEndpoints);
                Assert.Equal(68, expectedProfile.Endpoints[2].MinChildEndpointsIPv4);
                Assert.Equal(57, expectedProfile.Endpoints[2].MinChildEndpointsIPv6);

                Assert.Equal(80, expectedProfile.Endpoints[3].MinChildEndpoints);
                Assert.Equal(69, expectedProfile.Endpoints[3].MinChildEndpointsIPv4);
                Assert.Equal(58, expectedProfile.Endpoints[3].MinChildEndpointsIPv6);

                Assert.Equal(81, expectedProfile.Endpoints[4].MinChildEndpoints);
                Assert.Equal(70, expectedProfile.Endpoints[4].MinChildEndpointsIPv4);
                Assert.Equal(59, expectedProfile.Endpoints[4].MinChildEndpointsIPv6);

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

                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Example #16
0
        public void CrudProfileWithCustomHeaders()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TrafficManagerHelper.GenerateName();
                string        profileName       = TrafficManagerHelper.GenerateName();
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                // Create the profile
                var expectedProfile = TrafficManagerHelper.CreateOrUpdateProfileWithCustomHeadersAndStatusCodeRanges(
                    trafficManagerClient,
                    resourceGroupName,
                    profileName);

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

                Assert.Equal(expectedProfile.MonitorConfig.CustomHeaders.Count, actualProfile.MonitorConfig.CustomHeaders.Count);
                for (var i = 0; i < expectedProfile.MonitorConfig.CustomHeaders.Count; ++i)
                {
                    Assert.Equal(expectedProfile.MonitorConfig.CustomHeaders[i].Name, actualProfile.MonitorConfig.CustomHeaders[i].Name);
                    Assert.Equal(expectedProfile.MonitorConfig.CustomHeaders[i].Value, actualProfile.MonitorConfig.CustomHeaders[i].Value);
                }

                for (var i = 0; i < expectedProfile.MonitorConfig.ExpectedStatusCodeRanges.Count; ++i)
                {
                    Assert.Equal(expectedProfile.MonitorConfig.ExpectedStatusCodeRanges[i].Min, actualProfile.MonitorConfig.ExpectedStatusCodeRanges[i].Min);
                    Assert.Equal(expectedProfile.MonitorConfig.ExpectedStatusCodeRanges[i].Max, actualProfile.MonitorConfig.ExpectedStatusCodeRanges[i].Max);
                }

                for (var i = 0; i < expectedProfile.Endpoints.Count; ++i)
                {
                    for (var j = 0; j < expectedProfile.Endpoints[i].CustomHeaders.Count; ++j)
                    {
                        Assert.Equal(expectedProfile.Endpoints[i].CustomHeaders[j].Name, actualProfile.Endpoints[i].CustomHeaders[j].Name);
                        Assert.Equal(expectedProfile.Endpoints[i].CustomHeaders[j].Value, actualProfile.Endpoints[i].CustomHeaders[j].Value);
                    }
                }

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

                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Example #17
0
        public EndpointScenarioTests()
        {
            // Cleanup
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                ProfileListResponse listResponse = trafficManagerClient.Profiles.ListAll();

                foreach (Profile profile in listResponse.Profiles)
                {
                    string resourceGroup = TrafficManagerHelper.ExtractResourceGroupFromId(profile.Id);
                    trafficManagerClient.Profiles.Delete(resourceGroup, profile.Name);
                }
            }
        }
Example #18
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);
            }
        }
Example #19
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);
            }
        }
Example #20
0
        public void NameAvailabilityTest_NameAvailable()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                string relativeName = TestUtilities.GenerateName("hydratestrelativename");

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

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

                Assert.True(response.NameAvailable);
            }
        }
Example #21
0
        public ProfileScenarioTests()
        {
            // Cleanup
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                try
                {
                    ProfileListResponse listResponse = trafficManagerClient.Profiles.ListAll();

                    foreach (Profile profile in listResponse.Profiles)
                    {
                        string resourceGroup = TrafficManagerHelper.ExtractResourceGroupFromId(profile.Id);
                        trafficManagerClient.Profiles.Delete(resourceGroup, profile.Name);
                    }
                }
                catch (Exception)
                {
                    // TODO: (alguerra) Remove after we fix bug on list operation
                }
            }
        }
Example #22
0
        public void CrudProfileWithCustomSubnets()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TrafficManagerHelper.GenerateName();
                string        profileName       = TrafficManagerHelper.GenerateName();
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                // Create the profile
                var expectedProfile = TrafficManagerHelper.CreateOrUpdateProfileWithSubnets(
                    trafficManagerClient,
                    resourceGroupName,
                    profileName);

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

                for (var i = 0; i < expectedProfile.Endpoints.Count; ++i)
                {
                    Assert.Equal(2, expectedProfile.Endpoints[i].Subnets.Count);
                    Assert.Equal($"1.2.{i}.0", expectedProfile.Endpoints[i].Subnets[0].First);
                    Assert.Equal($"1.2.{i}.250", expectedProfile.Endpoints[i].Subnets[0].Last);
                    Assert.Equal($"3.4.{i}.0", expectedProfile.Endpoints[i].Subnets[1].First);
                    Assert.Equal(24, expectedProfile.Endpoints[i].Subnets[1].Scope);
                }

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

                this.DeleteResourceGroup(context, resourceGroupName);
            }
        }
Example #23
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);
            }
        }
Example #24
0
        public void TrafficViewEnableDisableQuerySizeScope()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TrafficManagerHelper.GetPersistentResourceGroupName();
                string        profileName       = TrafficManagerHelper.GetPersistentTrafficViewProfile();
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                Profile profile = TrafficManagerHelper.CreateOrUpdateDefaultProfileWithExternalEndpoint(
                    trafficManagerClient,
                    resourceGroup.Name,
                    profileName);

                bool authorized = true;
                bool found      = true;
                try
                {
                    trafficManagerClient.HeatMap.Get(resourceGroupName, profileName);
                }
                catch (Microsoft.Rest.Azure.CloudException e)
                {
                    authorized = !e.Body.Code.Contains("NotAuthorized");

                    // 'NotFound' can happen if there were no queries to the endpoint since it was provisioned.
                    found = !(authorized && e.Body.Code.Contains("NotFound")); // Let's hope you were paying attention in that math logic class.
                }

                if (!found)
                {
                    // Pause, then retry once.
                    System.Threading.Thread.Sleep(TimeSpan.FromSeconds(120));
                    try
                    {
                        trafficManagerClient.HeatMap.Get(resourceGroupName, profileName);
                    }
                    catch (Microsoft.Rest.Azure.CloudException e)
                    {
                        authorized = !e.Body.Code.Contains("NotAuthorized");
                    }
                }

                Assert.False(authorized);

                // Change the enrollment status and update the profile.
                // Clear the endpoints first; those are not serializable as child objects because they have their own resource info.
                profile.TrafficViewEnrollmentStatus = "Enabled";
                profile.Endpoints = null;
                trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroupName,
                    profileName,
                    profile);

                HeatMapModel heatMapModel = trafficManagerClient.HeatMap.Get(resourceGroupName, profileName);

                Assert.True(heatMapModel.StartTime.Value.CompareTo(System.DateTime.MinValue) > 0, "Invalid start time");
                Assert.True(heatMapModel.StartTime.Value.CompareTo(heatMapModel.EndTime.Value) <= 0, "Start time smaller than end time");
                Assert.True(heatMapModel.Endpoints.Count > 0, "Endpoint list empty, Not really an error but can not run test with no heatmap data.");
                foreach (HeatMapEndpoint ep in heatMapModel.Endpoints)
                {
                    Assert.True((ep.EndpointId ?? -1) >= 0, "Endpoint id null or out of range");
                    Assert.False(string.IsNullOrWhiteSpace(ep.ResourceId), "Resource Id undefined");
                }
                foreach (TrafficFlow tf in heatMapModel.TrafficFlows)
                {
                    Assert.False(string.IsNullOrWhiteSpace(tf.SourceIp), "SourceIp is undefined");
                    foreach (QueryExperience qe in tf.QueryExperiences)
                    {
                        Assert.True(heatMapModel.Endpoints.Where(ep => ep.EndpointId == qe.EndpointId).Count() > 0, "Query Experience does not match an existing endpoint");
                    }
                }

                IList <TrafficFlow> trafficFlowList = heatMapModel.TrafficFlows;


                foreach (TrafficFlow tf in trafficFlowList)
                {
                    if ((tf.Latitude - .1 >= -90.0) && (tf.Latitude + .1 <= 90.0) && (tf.Longitude - .1 >= -180.0) && (tf.Longitude + .1 <= 180.0))
                    {
                        heatMapModel = trafficManagerClient.HeatMap.Get(resourceGroupName, profileName, new List <double?>()
                        {
                            (tf.Latitude + .10), (tf.Longitude - .10)
                        }, new List <double?>()
                        {
                            (tf.Latitude - 0.10), (tf.Longitude + 0.10)
                        });
                        Assert.True(heatMapModel.TrafficFlows.Where(currentTF => (currentTF.Latitude == tf.Latitude && currentTF.Longitude == tf.Longitude)).Count() > 0, "Subset of coordinates not found");

                        heatMapModel = trafficManagerClient.HeatMap.Get(resourceGroupName, profileName, new List <double?>()
                        {
                            (tf.Latitude + .10), (tf.Longitude - .10)
                        }, new List <double?>()
                        {
                            (tf.Latitude + 0.05), (tf.Longitude - 0.05)
                        });
                        Assert.True(heatMapModel.TrafficFlows.Where(currentTF => (currentTF.Latitude == tf.Latitude && currentTF.Longitude == tf.Longitude)).Count() == 0, "Subset of coordinates not expected");
                    }
                }
            }
        }
Example #25
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]);
            }
        }