Example #1
0
        public void UpdateZonePreconditionFailed()
        {
            using (
                MockContext context = MockContext.Start(this.GetType().FullName)
                )
            {
                var resourcesHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                var dnsHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                DnsManagementClient dnsClient =
                    ResourceGroupHelper.GetDnsClient(context, dnsHandler);

                string zoneName =
                    TestUtilities.GenerateName("hydratest.dnszone.com");
                var resourceManagementClient =
                    ResourceGroupHelper.GetResourcesClient(
                        context,
                        resourcesHandler);
                string location =
                    ResourceGroupHelper.GetResourceLocation(
                        resourceManagementClient,
                        "microsoft.network/dnszones");

                ResourceGroup resourceGroup =
                    ResourceGroupHelper.CreateResourceGroup(
                        resourceManagementClient);
                var createdZone = ResourceGroupHelper.CreateZone(
                    dnsClient,
                    zoneName,
                    location,
                    resourceGroup);

                // expect Precondition Failed 412
                TestHelpers.AssertThrows <CloudException>(
                    () =>
                    dnsClient.Zones.CreateOrUpdate(
                        resourceGroup.Name,
                        zoneName,
                        createdZone,
                        "somegibberish",
                        null),
                    ex => ex.Body.Code == "PreconditionFailed");

                dnsClient.Zones.Delete(
                    resourceGroup.Name,
                    zoneName,
                    ifMatch: null);

                dnsClient.Zones.Delete(
                    resourceGroup.Name,
                    "hiya.com",
                    ifMatch: null);
                //Assert.Null(result);
            }
        }
Example #2
0
        internal static void CreatePrivateZones(
            DnsManagementClient dnsClient,
            ResourceGroup resourceGroup,
            IList <string> zonesNames,
            ResourceManagementClient resourcesClient,
            NetworkManagementClient networkManagementClient)
        {
            var location = ResourceGroupHelper.GetResourceLocation(resourcesClient, "microsoft.network/dnszones");

            foreach (var zonesName in zonesNames)
            {
                var registrationVnets = Enumerable.Range(0, 1).Select(i => ResourceGroupHelper.CreateVirtualNetwork(resourceGroup.Name, networkManagementClient)).ToList();
                var resolutionVnets   = Enumerable.Range(0, 1).Select(i => ResourceGroupHelper.CreateVirtualNetwork(resourceGroup.Name, networkManagementClient)).ToList();

                ResourceGroupHelper.CreatePrivateZone(
                    dnsClient,
                    zonesName,
                    location,
                    registrationVnets.Select(vNet => new SubResource {
                    Id = vNet.Id
                }).ToList(),
                    resolutionVnets.Select(vNet => new SubResource {
                    Id = vNet.Id
                }).ToList(),
                    resourceGroup);
            }
        }
Example #3
0
        public void UpdateZonePreconditionFailed()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient();

                string zoneName = TestUtilities.GenerateName("hydratestdnszone");
                string location = ResourceGroupHelper.GetResourceLocation(ResourceGroupHelper.GetResourcesClient(), "microsoft.network/dnszones");
                ResourceGroupExtended      resourceGroup  = ResourceGroupHelper.CreateResourceGroup();
                ZoneCreateOrUpdateResponse createresponse = ResourceGroupHelper.CreateZone(dnsClient, zoneName, location, resourceGroup);

                ZoneCreateOrUpdateParameters updateParameters = new ZoneCreateOrUpdateParameters {
                    Zone = createresponse.Zone
                };
                updateParameters.Zone.ETag = "somegibberish";

                // expect Precondition Failed 412
                TestHelpers.AssertThrows <CloudException>(
                    () => dnsClient.Zones.CreateOrUpdate(resourceGroup.Name, zoneName, updateParameters),
                    ex => ex.Error.Code == "PreconditionFailed");

                // expect Precondition Failed 412
                TestHelpers.AssertThrows <CloudException>(
                    () => dnsClient.Zones.Delete(resourceGroup.Name, zoneName, new ZoneDeleteParameters {
                    IfMatch = "somemoregib"
                }),
                    ex => ex.Error.Code == "PreconditionFailed");

                dnsClient.Zones.Delete(resourceGroup.Name, zoneName, new ZoneDeleteParameters());
            }
        }
Example #4
0
        public void UpdateZonePreconditionFailed()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient();

                string zoneName = TestUtilities.GenerateName("hydratestdnszone.com");
                string location = ResourceGroupHelper.GetResourceLocation(ResourceGroupHelper.GetResourcesClient(), "microsoft.network/dnszones");
                ResourceGroupExtended      resourceGroup  = ResourceGroupHelper.CreateResourceGroup();
                ZoneCreateOrUpdateResponse createresponse = ResourceGroupHelper.CreateZone(dnsClient, zoneName, location, resourceGroup);

                ZoneCreateOrUpdateParameters updateParameters = new ZoneCreateOrUpdateParameters {
                    Zone = createresponse.Zone
                };
                updateParameters.Zone.ETag = "somegibberish";

                // expect Precondition Failed 412
                TestHelpers.AssertThrows <CloudException>(
                    () => dnsClient.Zones.CreateOrUpdate(resourceGroup.Name, zoneName, ifMatch: null, ifNoneMatch: null, parameters: updateParameters),
                    ex => ex.Error.Code == "PreconditionFailed");

                var result = dnsClient.Zones.Delete(resourceGroup.Name, zoneName, ifMatch: null, ifNoneMatch: null);
                Assert.Equal(HttpStatusCode.OK, result.StatusCode);

                result = dnsClient.Zones.Delete(resourceGroup.Name, "hiya.com", ifMatch: null, ifNoneMatch: null);
                Assert.Equal(HttpStatusCode.NoContent, result.StatusCode);
            }
        }
Example #5
0
        public void CrudZoneSetsTheCurrentAndMaxRecordSetNumbersInResponse()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient();

                string zoneName = TestUtilities.GenerateName("hydratestdnszone");
                string location = ResourceGroupHelper.GetResourceLocation(ResourceGroupHelper.GetResourcesClient(), "microsoft.network/dnszones");
                ResourceGroupExtended resourceGroup = ResourceGroupHelper.CreateResourceGroup();

                // Create the zone clean
                ZoneCreateOrUpdateResponse createResponse = dnsClient.Zones.CreateOrUpdate(
                    resourceGroup.Name,
                    zoneName,
                    new ZoneCreateOrUpdateParameters
                {
                    Zone = new Microsoft.Azure.Management.Dns.Models.Zone
                    {
                        Location   = location,
                        Name       = zoneName,
                        Properties = new Microsoft.Azure.Management.Dns.Models.ZoneProperties
                        {
                            MaxNumberOfRecordSets = 42,                 // Test that specifying this value does not break Create (it must be ignored on server side).
                            NumberOfRecordSets    = 65,                 // Test that specifying this value does not break Create (it must be ignored on server side).
                        }
                    }
                });

                // Verify RecordSet numbers in the response.
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                // Retrieve the zone after create
                ZoneGetResponse getResponse = dnsClient.Zones.Get(resourceGroup.Name, zoneName);

                // Verify RecordSet numbers in the response.
                Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);
                Assert.True(getResponse.Zone.Properties.NumberOfRecordSets == 2);

                Zone retrievedZone = getResponse.Zone;
                retrievedZone.Tags = new Dictionary <string, string> {
                    { "tag1", "value1" }
                };
                retrievedZone.Properties.NumberOfRecordSets    = null;
                retrievedZone.Properties.MaxNumberOfRecordSets = null;

                // Update the zone
                ZoneCreateOrUpdateResponse updateResponse = dnsClient.Zones.CreateOrUpdate(resourceGroup.Name, zoneName, new ZoneCreateOrUpdateParameters {
                    Zone = retrievedZone
                });

                // Verify RecordSet numbers in the response.
                Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode);

                // Delete the zone
                AzureOperationResponse deleteResponse = dnsClient.Zones.Delete(resourceGroup.Name, zoneName, new ZoneDeleteParameters());
                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);
            }
        }
Example #6
0
        public void CrudZoneSetsTheCurrentAndMaxRecordSetNumbersInResponse()
        {
            using (
                MockContext context = MockContext.Start(this.GetType().FullName)
                )
            {
                var resourcesHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                var dnsHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                DnsManagementClient dnsClient =
                    ResourceGroupHelper.GetDnsClient(context, dnsHandler);

                string zoneName =
                    TestUtilities.GenerateName("hydratest.dnszone.com");
                var resourceManagementClient =
                    ResourceGroupHelper.GetResourcesClient(
                        context,
                        resourcesHandler);
                string location =
                    ResourceGroupHelper.GetResourceLocation(
                        resourceManagementClient,
                        "microsoft.network/dnszones");

                ResourceGroup resourceGroup =
                    ResourceGroupHelper.CreateResourceGroup(
                        resourceManagementClient);

                // Create the zone clean
                dnsClient.Zones.CreateOrUpdate(
                    resourceGroup.Name,
                    zoneName,
                    new Zone
                {
                    Location = location,
                });

                // Retrieve the zone after create
                Zone retrievedZone = dnsClient.Zones.Get(
                    resourceGroup.Name,
                    zoneName);

                // Verify RecordSet numbers in the response.
                Assert.True(retrievedZone.NumberOfRecordSets == 2);

                retrievedZone.Tags = new Dictionary <string, string>
                {
                    { "tag1", "value1" }
                };

                // Delete the zone
                DeleteZones(dnsClient, resourceGroup, new[] { zoneName });
            }
        }
Example #7
0
        public static void CreateZones(DnsManagementClient dnsClient, ResourceGroupExtended resourceGroup, string[] zoneNames)
        {
            string location = ResourceGroupHelper.GetResourceLocation(ResourceGroupHelper.GetResourcesClient(), "microsoft.network/dnszones");

            foreach (string zoneName in zoneNames)
            {
                ResourceGroupHelper.CreateZone(dnsClient, zoneName, location, resourceGroup);
            }
        }
Example #8
0
        public void ListZones()
        {
            using (
                MockContext context = MockContext.Start(this.GetType().FullName)
                )
            {
                var resourcesHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = HttpStatusCode.OK
                };
                var dnsHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = HttpStatusCode.OK
                };
                DnsManagementClient dnsClient =
                    ResourceGroupHelper.GetDnsClient(context, dnsHandler);

                var zoneNames = new[]
                {
                    TestUtilities.GenerateName("hydratest.dnszone.com"),
                    TestUtilities.GenerateName("hydratest.dnszone.com")
                };
                var resourceManagementClient =
                    ResourceGroupHelper.GetResourcesClient(
                        context,
                        resourcesHandler);
                ResourceGroup resourceGroup =
                    ResourceGroupHelper.CreateResourceGroup(
                        resourceManagementClient);
                ZoneScenarioTests.CreateZones(
                    dnsClient,
                    resourceGroup,
                    zoneNames,
                    resourceManagementClient);

                var listresponse =
                    dnsClient.Zones.ListInResourceGroup(resourceGroup.Name);

                Assert.NotNull(listresponse);
                Assert.Equal(2, listresponse.Count());
                Assert.True(
                    listresponse.Any(
                        zoneReturned =>
                        string.Equals(zoneNames[0], zoneReturned.Name))
                    &&
                    listresponse.Any(
                        zoneReturned =>
                        string.Equals(zoneNames[1], zoneReturned.Name)),
                    "The response of the List request does not meet expectations.");

                ZoneScenarioTests.DeleteZones(
                    dnsClient,
                    resourceGroup,
                    zoneNames);
            }
        }
        private static SingleRecordSetTestContext SetupSingleRecordSetTest()
        {
            var testContext = new SingleRecordSetTestContext();

            testContext.ZoneName      = TestUtilities.GenerateName("hydratestdnszone");
            testContext.RecordSetName = TestUtilities.GenerateName("hydratestdnsrec");
            testContext.Location      = ResourceGroupHelper.GetResourceLocation(ResourceGroupHelper.GetResourcesClient(), "microsoft.network/dnszones");
            testContext.ResourceGroup = ResourceGroupHelper.CreateResourceGroup();
            testContext.DnsClient     = ResourceGroupHelper.GetDnsClient();
            ResourceGroupHelper.CreateZone(testContext.DnsClient, testContext.ZoneName, testContext.Location, testContext.ResourceGroup);
            return(testContext);
        }
Example #10
0
        public void ListZonesWithListNext()
        {
            using (
                MockContext context = MockContext.Start(this.GetType().FullName)
                )
            {
                var resourcesHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                var dnsHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                DnsManagementClient dnsClient =
                    ResourceGroupHelper.GetDnsClient(context, dnsHandler);

                var zoneNames = new[]
                {
                    TestUtilities.GenerateName("hydratest.dnszone.com"),
                    TestUtilities.GenerateName("hydratest.dnszone.com")
                };
                var resourceManagementClient =
                    ResourceGroupHelper.GetResourcesClient(
                        context,
                        resourcesHandler);
                ResourceGroup resourceGroup =
                    ResourceGroupHelper.CreateResourceGroup(
                        resourceManagementClient);
                ZoneScenarioTests.CreateZones(
                    dnsClient,
                    resourceGroup,
                    zoneNames,
                    resourceManagementClient);

                var listresponse =
                    dnsClient.Zones.ListByResourceGroup(resourceGroup.Name, 1);

                Assert.NotNull(listresponse.NextPageLink);

                listresponse =
                    dnsClient.Zones.ListByResourceGroupNext(
                        (listresponse.NextPageLink));

                Assert.Single(listresponse);

                ZoneScenarioTests.DeleteZones(
                    dnsClient,
                    resourceGroup,
                    zoneNames);
            }
        }
Example #11
0
        public void ListZonesWithTopParameter()
        {
            using (
                MockContext context = MockContext.Start(this.GetType().FullName)
                )
            {
                var resourcesHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = HttpStatusCode.OK
                };
                var dnsHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = HttpStatusCode.OK
                };
                DnsManagementClient dnsClient =
                    ResourceGroupHelper.GetDnsClient(context, dnsHandler);

                var zoneNames = new[]
                {
                    TestUtilities.GenerateName("hydratest.dnszone") + ".com",
                    TestUtilities.GenerateName("hydratest.dnszone") + ".com"
                };
                var resourceManagementClient =
                    ResourceGroupHelper.GetResourcesClient(
                        context,
                        resourcesHandler);
                ResourceGroup resourceGroup =
                    ResourceGroupHelper.CreateResourceGroup(
                        resourceManagementClient);
                ZoneScenarioTests.CreateZones(
                    dnsClient,
                    resourceGroup,
                    zoneNames,
                    resourceManagementClient);

                var listresponse =
                    dnsClient.Zones.ListInResourceGroup(resourceGroup.Name, "1");

                Assert.NotNull(listresponse);
                Assert.Equal(1, listresponse.Count());
                Assert.True(
                    zoneNames.Any(
                        zoneName => zoneName == listresponse.ElementAt(0).Name));

                ZoneScenarioTests.DeleteZones(
                    dnsClient,
                    resourceGroup,
                    zoneNames);
            }
        }
Example #12
0
        public void ListZonesInSubscription()
        {
            using (
                MockContext context = MockContext.Start(this.GetType().FullName)
                )
            {
                var resourcesHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                var dnsHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                var networkHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };

                var dnsClient = ResourceGroupHelper.GetDnsClient(context, dnsHandler);

                var numPublicZones   = 2;
                var numPrivateZones  = 2;
                var publicZoneNames  = Enumerable.Range(0, numPublicZones).Select(i => TestUtilities.GenerateName("hydratest.dnszone.com")).ToArray();
                var privateZoneNames = Enumerable.Range(0, numPrivateZones).Select(i => TestUtilities.GenerateName("hydratest.privatednszone.com")).ToArray();

                var resourceManagementClient = ResourceGroupHelper.GetResourcesClient(context, resourcesHandler);
                var networkManagementClient  = ResourceGroupHelper.GetNetworkClient(context, networkHandler);

                var resourceGroup = ResourceGroupHelper.CreateResourceGroup(resourceManagementClient);
                CreateZones(dnsClient, resourceGroup, publicZoneNames, resourceManagementClient);
                CreatePrivateZones(dnsClient, resourceGroup, privateZoneNames, resourceManagementClient, networkManagementClient);

                var expectedZoneNames = publicZoneNames.Concat(privateZoneNames).ToArray();
                var listresponse      = dnsClient.Zones.List();

                Assert.NotNull(listresponse);
                Assert.True(listresponse.Count() >= (numPublicZones + numPrivateZones));
                Assert.True(expectedZoneNames.All(expectedZoneName => listresponse.Any(resp => string.Equals(resp.Name, expectedZoneName))), "The response of the List request does not meet expectations.");

                DeleteZones(dnsClient, resourceGroup, expectedZoneNames);
            }
        }
Example #13
0
        internal static void CreateZones(
            DnsManagementClient dnsClient,
            ResourceGroup resourceGroup,
            string[] zoneNames,
            ResourceManagementClient resourcesClient)
        {
            string location =
                ResourceGroupHelper.GetResourceLocation(
                    resourcesClient,
                    "microsoft.network/dnszones");

            foreach (string zoneName in zoneNames)
            {
                ResourceGroupHelper.CreateZone(
                    dnsClient,
                    zoneName,
                    location,
                    resourceGroup);
            }
        }
Example #14
0
        public void ListZonesWithFilterParameter()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient();

                var zoneNames = new[] { TestUtilities.GenerateName("hydratestdnszone"), TestUtilities.GenerateName("hydratestdnszone") };
                ResourceGroupExtended resourceGroup = ResourceGroupHelper.CreateResourceGroup();
                ZoneScenarioTests.CreateZones(dnsClient, resourceGroup, zoneNames);

                ZoneListResponse listresponse = dnsClient.Zones.List(resourceGroup.Name, new ZoneListParameters {
                    Filter = string.Format("endswith(Name,'{0}')", zoneNames[0])
                });

                Assert.NotNull(listresponse);
                Assert.Equal(1, listresponse.Zones.Count);

                ZoneScenarioTests.DeleteZones(dnsClient, resourceGroup, zoneNames);
            }
        }
        private static SingleRecordSetTestContext SetupSingleRecordSetTestForPublicZone(
            MockContext context)
        {
            var testContext = new SingleRecordSetTestContext();

            testContext.ResourcesHandler = new RecordedDelegatingHandler
            {
                StatusCodeToReturn = System.Net.HttpStatusCode.OK
            };
            testContext.DnsHandler = new RecordedDelegatingHandler
            {
                StatusCodeToReturn = System.Net.HttpStatusCode.OK
            };
            testContext.DnsClient = ResourceGroupHelper.GetDnsClient(
                context,
                testContext.DnsHandler);
            var resourceManagementClient =
                ResourceGroupHelper.GetResourcesClient(
                    context,
                    testContext.ResourcesHandler);

            testContext.ZoneName =
                TestUtilities.GenerateName("hydratest.dnszone.com");
            testContext.RecordSetName =
                TestUtilities.GenerateName("hydratestdnsrec");
            testContext.Location =
                ResourceGroupHelper.GetResourceLocation(
                    resourceManagementClient,
                    "microsoft.network/dnszones");
            testContext.ResourceGroup =
                ResourceGroupHelper.CreateResourceGroup(
                    resourceManagementClient);
            ResourceGroupHelper.CreateZone(
                testContext.DnsClient,
                testContext.ZoneName,
                testContext.Location,
                testContext.ResourceGroup);
            return(testContext);
        }
Example #16
0
        public void ListZonesWithTopParameter()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient();

                var zoneNames = new[] { TestUtilities.GenerateName("hydratestdnszone") + ".com", TestUtilities.GenerateName("hydratestdnszone") + ".con" };
                ResourceGroupExtended resourceGroup = ResourceGroupHelper.CreateResourceGroup();
                ZoneScenarioTests.CreateZones(dnsClient, resourceGroup, zoneNames);

                ZoneListResponse listresponse = dnsClient.Zones.List(resourceGroup.Name, new ZoneListParameters {
                    Top = "1"
                });

                Assert.NotNull(listresponse);
                Assert.Equal(1, listresponse.Zones.Count);
                Assert.True(listresponse.Zones.Any(zoneReturned => string.Equals(zoneNames[0], zoneReturned.Name)),
                            "The response of the List request does not meet expectations.");

                ZoneScenarioTests.DeleteZones(dnsClient, resourceGroup, zoneNames);
            }
        }
        public void ListZonesWithTopParameter()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient();

                var zoneNames = new[] { TestUtilities.GenerateName("hydratestdnszone") + ".com", TestUtilities.GenerateName("hydratestdnszone") + ".com" };
                ResourceGroupExtended resourceGroup = ResourceGroupHelper.CreateResourceGroup();
                ZoneScenarioTests.CreateZones(dnsClient, resourceGroup, zoneNames);

                ZoneListResponse listresponse = dnsClient.Zones.ListZonesInResourceGroup(resourceGroup.Name, new ZoneListParameters {
                    Top = "1"
                });

                Assert.NotNull(listresponse);
                Assert.Equal(1, listresponse.Zones.Count);
                Assert.True(zoneNames.Any(zoneName => zoneName == listresponse.Zones[0].Name), string.Format(" did not find zone name {0} in list ", listresponse.Zones[0].Name));
                Assert.True(listresponse.Zones[0].Properties.ParentResourceGroupName == resourceGroup.Name, string.Format(" expected resource group name {0} is different from actual {1}", resourceGroup.Name, listresponse.Zones[0].Properties.ParentResourceGroupName));

                ZoneScenarioTests.DeleteZones(dnsClient, resourceGroup, zoneNames);
            }
        }
Example #18
0
        public void GetNonExistingZoneFailsAsExpected()
        {
            using (
                MockContext context = MockContext.Start(this.GetType().FullName)
                )
            {
                var resourcesHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                var dnsHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                DnsManagementClient dnsClient =
                    ResourceGroupHelper.GetDnsClient(context, dnsHandler);

                string zoneName =
                    TestUtilities.GenerateName("hydratest.dnszone.com");
                var resourceManagementClient =
                    ResourceGroupHelper.GetResourcesClient(
                        context,
                        resourcesHandler);
                string location =
                    ResourceGroupHelper.GetResourceLocation(
                        resourceManagementClient,
                        "microsoft.network/dnszones");

                ResourceGroup resourceGroup =
                    ResourceGroupHelper.CreateResourceGroup(
                        resourceManagementClient);

                TestHelpers.AssertThrows <CloudException>(
                    () => dnsClient.Zones.Get(resourceGroup.Name, zoneName),
                    ex => ex.Body.Code == "ResourceNotFound");
            }
        }
Example #19
0
        public void ListZonesWithListNext()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient();

                var zoneNames = new[] { TestUtilities.GenerateName("hydratestdnszone.com"), TestUtilities.GenerateName("hydratestdnszone.com") };
                ResourceGroupExtended resourceGroup = ResourceGroupHelper.CreateResourceGroup();
                ZoneScenarioTests.CreateZones(dnsClient, resourceGroup, zoneNames);

                ZoneListResponse listresponse = dnsClient.Zones.ListZonesInResourceGroup(resourceGroup.Name, new ZoneListParameters {
                    Top = "1"
                });

                Assert.NotNull(listresponse.NextLink);

                listresponse = dnsClient.Zones.ListNext(listresponse.NextLink);

                Assert.Equal(1, listresponse.Zones.Count);

                ZoneScenarioTests.DeleteZones(dnsClient, resourceGroup, zoneNames);
            }
        }
Example #20
0
        public void CrudPrivateZoneFullCycle()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                var resourcesHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = HttpStatusCode.OK
                };
                var dnsHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = HttpStatusCode.OK
                };
                var networkHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = HttpStatusCode.OK
                };

                var dnsClient = ResourceGroupHelper.GetDnsClient(context, dnsHandler);
                var resourceManagementClient = ResourceGroupHelper.GetResourcesClient(context, resourcesHandler);
                var networkManagementClient  = ResourceGroupHelper.GetNetworkClient(context, networkHandler);

                var zoneName         = TestUtilities.GenerateName("hydratest.privatednszone.com");
                var location         = ResourceGroupHelper.GetResourceLocation(resourceManagementClient, "microsoft.network/dnszones");
                var resourceGroup    = ResourceGroupHelper.CreateResourceGroup(resourceManagementClient);
                var registrationVnet = ResourceGroupHelper.CreateVirtualNetwork(resourceGroup.Name, networkManagementClient);
                var resolutionVnet   = ResourceGroupHelper.CreateVirtualNetwork(resourceGroup.Name, networkManagementClient);

                void AssertPrivateZoneInvariants(Zone zone)
                {
                    if (zone == null)
                    {
                        throw new ArgumentNullException(nameof(zone));
                    }

                    Assert.Equal(zoneName, zone.Name);
                    Assert.Equal(ZoneType.Private, zone.ZoneType);
                    Assert.False(string.IsNullOrEmpty(zone.Etag));
                }

                // Create private zone clean, verify reponse
                var createdPrivateZone = dnsClient.Zones.CreateOrUpdate(
                    resourceGroup.Name,
                    zoneName,
                    new Zone
                {
                    Location = location,
                    ZoneType = ZoneType.Private,
                    Tags     = new Dictionary <string, string> {
                        { "tag1", "value1" }
                    },
                    RegistrationVirtualNetworks = new List <SubResource>
                    {
                        new SubResource(registrationVnet.Id)
                    },
                    ResolutionVirtualNetworks = new List <SubResource>
                    {
                        new SubResource(resolutionVnet.Id)
                    }
                });

                AssertPrivateZoneInvariants(createdPrivateZone);
                Assert.Equal(1, createdPrivateZone.Tags.Count);
                Assert.True(!createdPrivateZone.NameServers.IsAny());

                // Ensure that Id is parseable into resourceGroup
                var resourceGroupName = ExtractResourceGroupNameFromId(createdPrivateZone.Id);
                Assert.Equal(resourceGroupName, resourceGroup.Name);

                var regVirtualNetworkName = ExtractVirtualNetworkNameFromId(createdPrivateZone.RegistrationVirtualNetworks[0].Id);
                Assert.Equal(regVirtualNetworkName, registrationVnet.Name);

                var resVirtualNetworkName = ExtractVirtualNetworkNameFromId(createdPrivateZone.ResolutionVirtualNetworks[0].Id);
                Assert.Equal(resVirtualNetworkName, resolutionVnet.Name);

                // Retrieve the zone after create, verify response
                var retrievedPrivateZone = dnsClient.Zones.Get(resourceGroup.Name, zoneName);
                AssertPrivateZoneInvariants(retrievedPrivateZone);
                Assert.Equal(1, retrievedPrivateZone.Tags.Count);
                Assert.True(!retrievedPrivateZone.NameServers.IsAny());

                // Call Update on the object returned by Create (important distinction from Get below)
                createdPrivateZone.Tags = new Dictionary <string, string>
                {
                    { "tag1", "value1" },
                    { "tag2", "value2" }
                };

                var updateResponse = dnsClient.Zones.CreateOrUpdate(resourceGroup.Name, zoneName, ifMatch: null, ifNoneMatch: null, parameters: createdPrivateZone);
                AssertPrivateZoneInvariants(updateResponse);
                Assert.Equal(2, updateResponse.Tags.Count);

                // Retrieve the zone after create, verify response
                retrievedPrivateZone = dnsClient.Zones.Get(resourceGroup.Name, zoneName);
                AssertPrivateZoneInvariants(retrievedPrivateZone);
                Assert.Equal(2, retrievedPrivateZone.Tags.Count);

                // Call Update on the object returned by Get (important distinction from Create above)
                retrievedPrivateZone.Tags = new Dictionary <string, string>
                {
                    { "tag1", "value1" },
                    { "tag2", "value2" },
                    { "tag3", "value3" }
                };

                updateResponse = dnsClient.Zones.CreateOrUpdate(resourceGroup.Name, zoneName, ifMatch: null, ifNoneMatch: null, parameters: retrievedPrivateZone);
                AssertPrivateZoneInvariants(updateResponse);
                Assert.Equal(3, updateResponse.Tags.Count);

                // Delete the zone
                DeleteZones(dnsClient, resourceGroup, new[] { zoneName });
            }
        }
Example #21
0
        public void CrudZoneFullCycle()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient();

                string zoneName = TestUtilities.GenerateName("hydratestdnszone");
                string location = ResourceGroupHelper.GetResourceLocation(ResourceGroupHelper.GetResourcesClient(), "microsoft.network/dnszones");
                ResourceGroupExtended resourceGroup = ResourceGroupHelper.CreateResourceGroup();

                Action <Zone> assertZoneInvariants = zone =>
                {
                    Assert.Equal(zoneName, zone.Name);
                    Assert.False(string.IsNullOrEmpty(zone.ETag));
                };

                // Create the zone clean, verify response
                ZoneCreateOrUpdateResponse createResponse = dnsClient.Zones.CreateOrUpdate(
                    resourceGroup.Name,
                    zoneName,
                    new ZoneCreateOrUpdateParameters
                {
                    Zone = new Microsoft.Azure.Management.Dns.Models.Zone
                    {
                        Location = location,
                        Name     = zoneName,
                        Tags     = new Dictionary <string, string> {
                            { "tag1", "value1" }
                        },
                        ETag       = null,
                        Properties = new Microsoft.Azure.Management.Dns.Models.ZoneProperties
                        {
                        }
                    }
                });

                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);
                assertZoneInvariants(createResponse.Zone);
                Assert.Equal(1, createResponse.Zone.Tags.Count);

                // Retrieve the zone after create, verify response
                var getresponse = dnsClient.Zones.Get(resourceGroup.Name, zoneName);

                Assert.Equal(HttpStatusCode.OK, getresponse.StatusCode);
                assertZoneInvariants(getresponse.Zone);
                Assert.Equal(1, getresponse.Zone.Tags.Count);

                // Call Update on the object returned by Create (important distinction from Get below)
                Zone createdZone = createResponse.Zone;
                createdZone.Tags = new Dictionary <string, string> {
                    { "tag1", "value1" }, { "tag2", "value2" }
                };

                ZoneCreateOrUpdateResponse updateResponse = dnsClient.Zones.CreateOrUpdate(resourceGroup.Name, zoneName, new ZoneCreateOrUpdateParameters {
                    Zone = createdZone
                });

                Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode);
                assertZoneInvariants(updateResponse.Zone);
                Assert.Equal(2, updateResponse.Zone.Tags.Count);

                // Retrieve the zone after create, verify response
                getresponse = dnsClient.Zones.Get(resourceGroup.Name, zoneName);

                Assert.Equal(HttpStatusCode.OK, getresponse.StatusCode);
                assertZoneInvariants(getresponse.Zone);
                Assert.Equal(2, getresponse.Zone.Tags.Count);

                // Call Update on the object returned by Get (important distinction from Create above)
                Zone retrievedZone = getresponse.Zone;
                retrievedZone.Tags = new Dictionary <string, string> {
                    { "tag1", "value1" }, { "tag2", "value2" }, { "tag3", "value3" }
                };

                updateResponse = dnsClient.Zones.CreateOrUpdate(resourceGroup.Name, zoneName, new ZoneCreateOrUpdateParameters {
                    Zone = retrievedZone
                });

                Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode);
                assertZoneInvariants(updateResponse.Zone);
                Assert.Equal(3, updateResponse.Zone.Tags.Count);

                // Delete the zone
                AzureOperationResponse deleteResponse = dnsClient.Zones.Delete(resourceGroup.Name, zoneName, new ZoneDeleteParameters());
                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);
            }
        }
        private static SingleRecordSetTestContext SetupSingleRecordSetTestForPrivateZone(
            MockContext context)
        {
            var testContext = new SingleRecordSetTestContext();

            testContext.ResourcesHandler = new RecordedDelegatingHandler
            {
                StatusCodeToReturn = System.Net.HttpStatusCode.OK
            };
            testContext.DnsHandler = new RecordedDelegatingHandler
            {
                StatusCodeToReturn = System.Net.HttpStatusCode.OK
            };
            testContext.NetworkHandler = new RecordedDelegatingHandler
            {
                StatusCodeToReturn = System.Net.HttpStatusCode.OK
            };

            testContext.DnsClient = ResourceGroupHelper.GetDnsClient(
                context,
                testContext.DnsHandler);
            testContext.NetworkClient = ResourceGroupHelper.GetNetworkClient(
                context,
                testContext.NetworkHandler);
            var resourceManagementClient =
                ResourceGroupHelper.GetResourcesClient(
                    context,
                    testContext.ResourcesHandler);

            testContext.ZoneName =
                TestUtilities.GenerateName("hydratest.dnszone.com");
            testContext.RecordSetName =
                TestUtilities.GenerateName("hydratestdnsrec");
            testContext.Location =
                ResourceGroupHelper.GetResourceLocation(
                    resourceManagementClient,
                    "microsoft.network/dnszones");
            testContext.ResourceGroup =
                ResourceGroupHelper.CreateResourceGroup(
                    resourceManagementClient);
            testContext.RegistationVirtualNetworks = new List <VirtualNetwork>
            {
                ResourceGroupHelper.CreateVirtualNetwork(testContext.ResourceGroup.Name, testContext.NetworkClient)
            };
            testContext.ResolutionVirtualNetworks = new List <VirtualNetwork>
            {
                ResourceGroupHelper.CreateVirtualNetwork(testContext.ResourceGroup.Name, testContext.NetworkClient)
            };
            ResourceGroupHelper.CreatePrivateZone(
                testContext.DnsClient,
                testContext.ZoneName,
                testContext.Location,
                testContext.RegistationVirtualNetworks.Select(vNet => new SubResource {
                Id = vNet.Id
            }).ToList(),
                testContext.ResolutionVirtualNetworks.Select(vNet => new SubResource {
                Id = vNet.Id
            }).ToList(),
                testContext.ResourceGroup);
            return(testContext);
        }
Example #23
0
        public void CrudZoneFullCycle()
        {
            using (
                MockContext context = MockContext.Start(this.GetType().FullName)
                )
            {
                var resourcesHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                var dnsHandler = new RecordedDelegatingHandler
                {
                    StatusCodeToReturn = System.Net.HttpStatusCode.OK
                };
                var dnsClient = ResourceGroupHelper.GetDnsClient(
                    context,
                    dnsHandler);
                var resourceManagementClient =
                    ResourceGroupHelper.GetResourcesClient(
                        context,
                        resourcesHandler);

                string zoneName =
                    TestUtilities.GenerateName("hydratest.dnszone.com");
                string location =
                    ResourceGroupHelper.GetResourceLocation(
                        resourceManagementClient,
                        "microsoft.network/dnszones");
                ResourceGroup resourceGroup =
                    ResourceGroupHelper.CreateResourceGroup(
                        resourceManagementClient);

                Action <Zone> assertZoneInvariants = zone =>
                {
                    Assert.Equal(zoneName, zone.Name);
                    Assert.False(string.IsNullOrEmpty(zone.Etag));
                };

                // Create the zone clean, verify response
                var createdZone = dnsClient.Zones.CreateOrUpdate(
                    resourceGroup.Name,
                    zoneName,
                    ifMatch: null,
                    ifNoneMatch: null,
                    parameters: new Zone
                {
                    Location = location,
                    Tags     =
                        new Dictionary <string, string> {
                        { "tag1", "value1" }
                    },
                });

                assertZoneInvariants(createdZone);
                Assert.Equal(1, createdZone.Tags.Count);
                Assert.True(
                    createdZone.NameServers != null &&
                    createdZone.NameServers.Any(
                        nameServer => !string.IsNullOrWhiteSpace(nameServer)));

                // Ensure that Id is parseable into resourceGroup
                string resourceGroupName =
                    ExtractResourceGroupNameFromId(createdZone.Id);
                Assert.Equal(resourceGroupName, resourceGroup.Name);

                // Retrieve the zone after create, verify response
                var retrievedZone = dnsClient.Zones.Get(
                    resourceGroup.Name,
                    zoneName);

                assertZoneInvariants(retrievedZone);
                Assert.Equal(1, retrievedZone.Tags.Count);

                Assert.True(
                    retrievedZone.NameServers != null &&
                    retrievedZone.NameServers.Any(
                        nameServer => !string.IsNullOrWhiteSpace(nameServer)));

                // Call Update on the object returned by Create (important distinction from Get below)
                createdZone.Tags = new Dictionary <string, string>
                {
                    { "tag1", "value1" },
                    { "tag2", "value2" }
                };

                var updateResponse =
                    dnsClient.Zones.CreateOrUpdate(
                        resourceGroup.Name,
                        zoneName,
                        ifMatch: null,
                        ifNoneMatch: null,
                        parameters: createdZone);

                assertZoneInvariants(updateResponse);
                Assert.Equal(2, updateResponse.Tags.Count);

                // Retrieve the zone after create, verify response
                retrievedZone = dnsClient.Zones.Get(
                    resourceGroup.Name,
                    zoneName);

                assertZoneInvariants(retrievedZone);
                Assert.Equal(2, retrievedZone.Tags.Count);

                // Call Update on the object returned by Get (important distinction from Create above)
                retrievedZone.Tags = new Dictionary <string, string>
                {
                    { "tag1", "value1" },
                    { "tag2", "value2" },
                    { "tag3", "value3" }
                };

                updateResponse =
                    dnsClient.Zones.CreateOrUpdate(
                        resourceGroup.Name,
                        zoneName,
                        ifMatch: null,
                        ifNoneMatch: null,
                        parameters: retrievedZone);

                assertZoneInvariants(updateResponse);
                Assert.Equal(3, updateResponse.Tags.Count);

                // Call Patch operation
                retrievedZone.Tags = new Dictionary <string, string>
                {
                    { "tag1", "value1" },
                    { "tag2", "value2" },
                    { "tag3", "value3" },
                    { "tag4", "value4" }
                };

                updateResponse =
                    dnsClient.Zones.Update(
                        resourceGroup.Name,
                        zoneName,
                        ifMatch: null,
                        tags: retrievedZone.Tags);

                assertZoneInvariants(updateResponse);
                Assert.Equal(4, updateResponse.Tags.Count);

                // Delete the zone
                DeleteZones(dnsClient, resourceGroup, new[] { zoneName });
            }
        }