public static void DeleteRecordSetsAndZone(SingleRecordSetTestContext testContext, string[] recordSetNames)
        {
            testContext.DnsClient.RecordSets.Delete(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                recordSetNames[0],
                RecordType.TXT,
                new RecordSetDeleteParameters {
                IfMatch = null
            });

            testContext.DnsClient.RecordSets.Delete(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                recordSetNames[1],
                RecordType.TXT,
                new RecordSetDeleteParameters {
                IfMatch = null
            });

            testContext.DnsClient.RecordSets.Delete(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                recordSetNames[2],
                RecordType.AAAA,
                new RecordSetDeleteParameters {
                IfMatch = null
            });

            testContext.DnsClient.Zones.Delete(testContext.ResourceGroup.Name, testContext.ZoneName, new ZoneDeleteParameters());
        }
        internal static void DeleteRecordSetsAndZone(
            SingleRecordSetTestContext testContext,
            string[] recordSetNames)
        {
            testContext.DnsClient.RecordSets.Delete(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                recordSetNames[0],
                RecordType.TXT,
                ifMatch: null);

            testContext.DnsClient.RecordSets.Delete(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                recordSetNames[1],
                RecordType.TXT,
                ifMatch: null);

            testContext.DnsClient.RecordSets.Delete(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                recordSetNames[2],
                RecordType.AAAA,
                ifMatch: null);

            testContext.DnsClient.Zones.Delete(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                ifMatch: null);
        }
        public void UpdateRecordSetPreconditionFailed()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                SingleRecordSetTestContext        testContext      = SetupSingleRecordSetTest();
                RecordSetCreateOrUpdateParameters createParameters = testContext.TestRecordSkeleton;
                createParameters.RecordSet.Properties.CnameRecord = new CnameRecord {
                    Cname = "www.contoso.example.com"
                };

                RecordSetCreateOrUpdateResponse createResponse = testContext.DnsClient.RecordSets.CreateOrUpdate(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.CNAME,
                    ifMatch: null,
                    ifNoneMatch: null,
                    parameters: createParameters);

                RecordSetCreateOrUpdateParameters updateParameters = new RecordSetCreateOrUpdateParameters {
                    RecordSet = createResponse.RecordSet
                };
                updateParameters.RecordSet.ETag = "somegibberish";

                // expect Precondition Failed 412
                TestHelpers.AssertThrows <CloudException>(
                    () => testContext.DnsClient.RecordSets.CreateOrUpdate(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        testContext.RecordSetName,
                        RecordType.CNAME,
                        ifMatch: null,
                        ifNoneMatch: null,
                        parameters: updateParameters),
                    exceptionAsserts: ex => ex.Error.Code == "PreconditionFailed");

                // expect Precondition Failed 412
                TestHelpers.AssertThrows <CloudException>(
                    () => testContext.DnsClient.RecordSets.Delete(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        testContext.RecordSetName,
                        RecordType.CNAME,
                        ifMatch: null,
                        ifNoneMatch: null),
                    exceptionAsserts: ex => ex.Error.Code == "PreconditionFailed");

                testContext.DnsClient.RecordSets.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.CNAME,
                    ifMatch: null,
                    ifNoneMatch: null);

                testContext.DnsClient.Zones.Delete(testContext.ResourceGroup.Name, testContext.ZoneName, ifMatch: null, ifNoneMatch: null);
            }
        }
        internal static void CreateRecordSets(
            SingleRecordSetTestContext testContext,
            string[] recordSetNames)
        {
            var createParameters1 =
                testContext.GetNewTestRecordSkeleton(recordSetNames[0]);

            createParameters1.TxtRecords = new List <TxtRecord>
            {
                new TxtRecord {
                    Value = new[] { "text1" }.ToList()
                }
            };
            var createParameters2 =
                testContext.GetNewTestRecordSkeleton(recordSetNames[1]);

            createParameters2.TxtRecords = new List <TxtRecord>
            {
                new TxtRecord {
                    Value = new[] { "text1" }.ToList()
                }
            };
            var createParameters3 =
                testContext.GetNewTestRecordSkeleton(recordSetNames[2]);

            createParameters3.AaaaRecords = new List <AaaaRecord>
            {
                new AaaaRecord {
                    Ipv6Address = "123::45"
                }
            };

            testContext.DnsClient.RecordSets.CreateOrUpdate(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                createParameters1.Name,
                RecordType.TXT,
                ifMatch: null,
                ifNoneMatch: null,
                parameters: createParameters1);

            testContext.DnsClient.RecordSets.CreateOrUpdate(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                createParameters2.Name,
                RecordType.TXT,
                ifMatch: null,
                ifNoneMatch: null,
                parameters: createParameters2);

            testContext.DnsClient.RecordSets.CreateOrUpdate(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                createParameters3.Name,
                RecordType.AAAA,
                ifMatch: null,
                ifNoneMatch: null,
                parameters: createParameters3);
        }
        public void UpdateSoa()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                SingleRecordSetTestContext testContext = SetupSingleRecordSetTest();

                // SOA for the zone should already exist
                RecordSetGetResponse getresponse = testContext.DnsClient.RecordSets.Get(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    "@",
                    RecordType.SOA);

                Assert.Equal(HttpStatusCode.OK, getresponse.StatusCode);
                RecordSet soaResource = getresponse.RecordSet;
                Assert.NotNull(soaResource);
                Assert.NotNull(soaResource.Properties.SoaRecord);

                soaResource.Properties.SoaRecord.ExpireTime  = 123;
                soaResource.Properties.SoaRecord.MinimumTtl  = 1234;
                soaResource.Properties.SoaRecord.RefreshTime = 12345;
                soaResource.Properties.SoaRecord.RetryTime   = 123456;

                var updateParameters = new RecordSetCreateOrUpdateParameters {
                    RecordSet = soaResource
                };

                RecordSetCreateOrUpdateResponse updateResponse = testContext.DnsClient.RecordSets.CreateOrUpdate(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    "@",
                    RecordType.SOA,
                    updateParameters);

                Assert.Equal(HttpStatusCode.OK, getresponse.StatusCode);
                Assert.True(
                    TestHelpers.AreEqual(soaResource, updateResponse.RecordSet, ignoreEtag: true),
                    "Response body of Update does not match expectations");

                getresponse = testContext.DnsClient.RecordSets.Get(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    "@",
                    RecordType.SOA);

                Assert.Equal(HttpStatusCode.OK, getresponse.StatusCode);
                Assert.True(
                    TestHelpers.AreEqual(updateResponse.RecordSet, getresponse.RecordSet),
                    "Response body of Get does not match expectations");

                // SOA will get deleted with the zone
                testContext.DnsClient.Zones.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    new ZoneDeleteParameters());
            }
        }
        private void RecordSetCreateGet(
            RecordType recordType,
            Action <RecordSetCreateOrUpdateParameters> setRecordsAction)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(currentMethodStackDepth: 4);
                SingleRecordSetTestContext        testContext      = SetupSingleRecordSetTest();
                RecordSetCreateOrUpdateParameters createParameters = testContext.TestRecordSkeleton;
                setRecordsAction(createParameters);

                RecordSetCreateOrUpdateResponse createResponse = testContext.DnsClient.RecordSets.CreateOrUpdate(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    recordType,
                    ifMatch: null,
                    ifNoneMatch: null,
                    parameters: createParameters);

                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);
                Assert.True(
                    TestHelpers.AreEqual(createParameters.RecordSet, createResponse.RecordSet, ignoreEtag: true),
                    "Response body of Create does not match expectations");
                Assert.False(string.IsNullOrWhiteSpace(createResponse.RecordSet.ETag));

                var getresponse = testContext.DnsClient.RecordSets.Get(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    recordType);

                Assert.Equal(HttpStatusCode.OK, getresponse.StatusCode);
                Assert.True(
                    TestHelpers.AreEqual(createResponse.RecordSet, getresponse.RecordSet, ignoreEtag: false),
                    "Response body of Get does not match expectations");

                // BUG 2364951: should work without specifying ETag
                AzureOperationResponse deleteResponse = testContext.DnsClient.RecordSets.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    recordType,
                    ifMatch: null,
                    ifNoneMatch: null);
                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);

                deleteResponse = testContext.DnsClient.Zones.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    ifMatch: null,
                    ifNoneMatch: null);
            }
        }
 private static SingleRecordSetTestContext SetupSingleRecordSetTest()
 {
     var testContext = new SingleRecordSetTestContext();
     testContext.ZoneName = TestUtilities.GenerateName("hydratestdnszone.com");
     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;
 }
        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);
        }
        public static void CreateRecordSets(SingleRecordSetTestContext testContext, string[] recordSetNames)
        {
            RecordSetCreateOrUpdateParameters createParameters1 = testContext.GetNewTestRecordSkeleton(recordSetNames[0]);

            createParameters1.RecordSet.Properties.TxtRecords = new List <TxtRecord> {
                new TxtRecord {
                    Value = "text1"
                }
            };
            RecordSetCreateOrUpdateParameters createParameters2 = testContext.GetNewTestRecordSkeleton(recordSetNames[1]);

            createParameters2.RecordSet.Properties.TxtRecords = new List <TxtRecord> {
                new TxtRecord {
                    Value = "text2"
                }
            };
            RecordSetCreateOrUpdateParameters createParameters3 = testContext.GetNewTestRecordSkeleton(recordSetNames[2]);

            createParameters3.RecordSet.Properties.AaaaRecords = new List <AaaaRecord> {
                new AaaaRecord {
                    Ipv6Address = "123::45"
                }
            };

            testContext.DnsClient.RecordSets.CreateOrUpdate(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                createParameters1.RecordSet.Name,
                RecordType.TXT,
                createParameters1);

            testContext.DnsClient.RecordSets.CreateOrUpdate(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                createParameters2.RecordSet.Name,
                RecordType.TXT,
                createParameters2);

            testContext.DnsClient.RecordSets.CreateOrUpdate(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                createParameters3.RecordSet.Name,
                RecordType.AAAA,
                createParameters3);
        }
        private void ListRecordsInZoneWithNext(bool isCrossType)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(currentMethodStackDepth: 4);
                SingleRecordSetTestContext testContext = RecordSetScenarioTests.SetupSingleRecordSetTest();

                const string suffix = ".com";

                var recordSetNames = new[] { TestUtilities.GenerateName("hydratestrec") + suffix, TestUtilities.GenerateName("hydratestrec") + ".con", TestUtilities.GenerateName("hydratestrec") + ".con" };

                RecordSetScenarioTests.CreateRecordSets(testContext, recordSetNames);

                RecordSetListResponse listResponse;

                if (isCrossType)
                {
                    listResponse = testContext.DnsClient.RecordSets.ListAll(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        new RecordSetListParameters {
                        Top = "3"
                    });
                }
                else
                {
                    listResponse = testContext.DnsClient.RecordSets.List(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        RecordType.TXT,
                        new RecordSetListParameters {
                        Top = "3"
                    });
                }

                listResponse = testContext.DnsClient.RecordSets.ListNext(listResponse.NextLink);

                Assert.NotNull(listResponse);
                Assert.True(
                    listResponse.RecordSets.Any(recordReturned => string.Equals(recordSetNames[1], recordReturned.Name)),
                    "The returned records do not meet expectations");

                RecordSetScenarioTests.DeleteRecordSetsAndZone(testContext, recordSetNames);
            }
        }
        private void ListRecordsInZone(bool isCrossType)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(currentMethodStackDepth: 4);
                SingleRecordSetTestContext testContext = SetupSingleRecordSetTest();

                var recordSetNames = new[] { TestUtilities.GenerateName("hydratestrec"), TestUtilities.GenerateName("hydratestrec"), TestUtilities.GenerateName("hydratestrec") };

                RecordSetScenarioTests.CreateRecordSets(testContext, recordSetNames);

                if (isCrossType)
                {
                    RecordSetListResponse listresponse = testContext.DnsClient.RecordSets.ListAll(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        new RecordSetListParameters());

                    // not checking for the record count as this will return standard SOA and auth NS records as well
                    Assert.NotNull(listresponse);
                    Assert.True(
                        listresponse.RecordSets.Any(recordSetReturned => string.Equals(recordSetNames[0], recordSetReturned.Name)) &&
                        listresponse.RecordSets.Any(recordSetReturned => string.Equals(recordSetNames[1], recordSetReturned.Name)) &&
                        listresponse.RecordSets.Any(recordSetReturned => string.Equals(recordSetNames[2], recordSetReturned.Name)),
                        "The returned records do not meet expectations");
                }
                else
                {
                    RecordSetListResponse listresponse = testContext.DnsClient.RecordSets.List(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        RecordType.TXT,
                        new RecordSetListParameters());

                    Assert.NotNull(listresponse);
                    Assert.Equal(2, listresponse.RecordSets.Count);
                    Assert.True(
                        listresponse.RecordSets.Any(recordSetReturned => string.Equals(recordSetNames[0], recordSetReturned.Name)) &&
                        listresponse.RecordSets.Any(recordSetReturned => string.Equals(recordSetNames[1], recordSetReturned.Name)),
                        "The returned records do not meet expectations");
                }

                RecordSetScenarioTests.DeleteRecordSetsAndZone(testContext, recordSetNames);
            }
        }
        private void ListRecordsInZoneWithTop(bool isCrossType)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(currentMethodStackDepth: 4);
                SingleRecordSetTestContext testContext = RecordSetScenarioTests.SetupSingleRecordSetTest();

                var recordSetNames = new[] { TestUtilities.GenerateName("hydratestrec") + ".com", TestUtilities.GenerateName("hydratestrec") + ".con", TestUtilities.GenerateName("hydratestrec") + ".con" };

                RecordSetScenarioTests.CreateRecordSets(testContext, recordSetNames);

                RecordSetListResponse listResponse;

                if (isCrossType)
                {
                    // Using top = 3, it will pick up SOA, NS and the first TXT
                    listResponse = testContext.DnsClient.RecordSets.ListAll(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        new RecordSetListParameters {
                        Top = "3"
                    });
                }
                else
                {
                    // Using top = 3, it will pick up SOA, NS and the first TXT, process it and return just the TXT
                    listResponse = testContext.DnsClient.RecordSets.List(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        RecordType.TXT,
                        new RecordSetListParameters {
                        Top = "3"
                    });
                }

                Assert.NotNull(listResponse);
                Assert.True(
                    listResponse.RecordSets.Any(recordReturned => string.Equals(recordSetNames[0], recordReturned.Name)),
                    "The returned records do not meet expectations");

                RecordSetScenarioTests.DeleteRecordSetsAndZone(testContext, recordSetNames);
            }
        }
        private void ListRecordsInZoneWithFilter(bool isCrossType)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(currentMethodStackDepth: 4);
                SingleRecordSetTestContext testContext = RecordSetScenarioTests.SetupSingleRecordSetTest();

                var recordSetNames = new[] { TestUtilities.GenerateName("hydratestrec"), TestUtilities.GenerateName("hydratestrec"), TestUtilities.GenerateName("hydratestrec") };

                RecordSetScenarioTests.CreateRecordSets(testContext, recordSetNames);

                RecordSetListResponse listResponse;

                if (isCrossType)
                {
                    listResponse = testContext.DnsClient.RecordSets.ListAll(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        new RecordSetListParameters {
                        Filter = string.Format("endswith(Name,'{0}')", recordSetNames[0])
                    });
                }
                else
                {
                    listResponse = testContext.DnsClient.RecordSets.List(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        RecordType.TXT,
                        new RecordSetListParameters {
                        Filter = string.Format("endswith(Name,'{0}')", recordSetNames[0])
                    });
                }

                // not checking for the record count as this will return standard SOA and auth NS records as well
                Assert.NotNull(listResponse);
                Assert.Equal(1, listResponse.RecordSets.Count);
                Assert.NotNull(listResponse.RecordSets.FirstOrDefault());
                Assert.Equal(recordSetNames[0], listResponse.RecordSets.FirstOrDefault().Name);

                RecordSetScenarioTests.DeleteRecordSetsAndZone(testContext, recordSetNames);
            }
        }
        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);
        }
        public static void DeleteRecordSetsAndZone(SingleRecordSetTestContext testContext, string[] recordSetNames)
        {
            testContext.DnsClient.RecordSets.Delete(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        recordSetNames[0],
                        RecordType.TXT,
                        ifMatch: null,
                        ifNoneMatch: null);

            testContext.DnsClient.RecordSets.Delete(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        recordSetNames[1],
                        RecordType.TXT,
                        ifMatch: null,
                        ifNoneMatch: null);

            testContext.DnsClient.RecordSets.Delete(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        recordSetNames[2],
                        RecordType.AAAA,
                        ifMatch: null,
                        ifNoneMatch: null);

            testContext.DnsClient.Zones.Delete(testContext.ResourceGroup.Name, testContext.ZoneName, ifMatch: null, ifNoneMatch: null);
        }
Example #16
0
        public void CrudRecordSetFullCycle()
        {
            using (
                MockContext context = MockContext.Start(this.GetType().FullName)
                )
            {
                SingleRecordSetTestContext testContext =
                    SetupSingleRecordSetTest(context);
                var recordSetToBeCreated = testContext.TestRecordSkeleton;
                recordSetToBeCreated.ARecords = new List <ARecord>
                {
                    new ARecord {
                        Ipv4Address = "123.32.1.0"
                    }
                };
                recordSetToBeCreated.TTL = 60;

                // Create the records clean, verify response
                var createResponse = testContext.DnsClient.RecordSets
                                     .CreateOrUpdate(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A,
                    ifMatch: null,
                    ifNoneMatch: null,
                    parameters: recordSetToBeCreated);

                Assert.True(
                    TestHelpers.AreEqual(
                        recordSetToBeCreated,
                        createResponse,
                        ignoreEtag: true),
                    "Response body of Create does not match expectations");
                Assert.False(string.IsNullOrWhiteSpace(createResponse.Etag));

                // Retrieve the zone after create, verify response
                var getresponse = testContext.DnsClient.RecordSets.Get(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A);

                Assert.True(
                    TestHelpers.AreEqual(
                        createResponse,
                        getresponse,
                        ignoreEtag: false),
                    "Response body of Get does not match expectations");

                // Call Update on the object returned by Create (important distinction from Get below)
                Models.RecordSet createdRecordSet = createResponse;

                createdRecordSet.TTL      = 120;
                createdRecordSet.Metadata = new Dictionary <string, string>
                {
                    { "tag1", "value1" },
                    { "tag2", "value2" }
                };
                createdRecordSet.ARecords = new List <ARecord>
                {
                    new ARecord {
                        Ipv4Address = "123.32.1.0"
                    },
                    new ARecord {
                        Ipv4Address = "101.10.0.1"
                    }
                };

                var updateResponse = testContext.DnsClient.RecordSets
                                     .CreateOrUpdate(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A,
                    ifMatch: null,
                    ifNoneMatch: null,
                    parameters: createdRecordSet);

                Assert.True(
                    TestHelpers.AreEqual(
                        createdRecordSet,
                        updateResponse,
                        ignoreEtag: true),
                    "Response body of Update does not match expectations");
                Assert.False(string.IsNullOrWhiteSpace(updateResponse.Etag));

                // Retrieve the records after create, verify response
                getresponse = testContext.DnsClient.RecordSets.Get(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A);

                Assert.True(
                    TestHelpers.AreEqual(updateResponse, getresponse),
                    "Response body of Get does not match expectations");

                // Call Update on the object returned by Get (important distinction from Create above)
                Models.RecordSet retrievedRecordSet = getresponse;
                retrievedRecordSet.TTL      = 180;
                retrievedRecordSet.ARecords = new List <ARecord>
                {
                    new ARecord {
                        Ipv4Address = "123.32.1.0"
                    },
                    new ARecord {
                        Ipv4Address = "101.10.0.1"
                    },
                    new ARecord {
                        Ipv4Address = "22.33.44.55"
                    },
                };

                updateResponse = testContext.DnsClient.RecordSets.CreateOrUpdate
                                 (
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A,
                    ifMatch: null,
                    ifNoneMatch: null,
                    parameters: retrievedRecordSet);

                Assert.True(
                    TestHelpers.AreEqual(
                        retrievedRecordSet,
                        updateResponse,
                        ignoreEtag: true),
                    "Response body of Update does not match expectations");
                Assert.False(string.IsNullOrWhiteSpace(updateResponse.Etag));

                // Delete the record set
                testContext.DnsClient.RecordSets.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A,
                    ifMatch: null,
                    ifNoneMatch: null);

                // Delete the zone
                var deleteResponse = testContext.DnsClient.Zones.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    ifMatch: null,
                    ifNoneMatch: null);
            }
        }
Example #17
0
        public void UpdateSoa()
        {
            using (
                MockContext context = MockContext.Start(this.GetType().FullName)
                )
            {
                SingleRecordSetTestContext testContext =
                    SetupSingleRecordSetTest(context);

                // SOA for the zone should already exist
                var getresponse = testContext.DnsClient.RecordSets.Get(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    "@",
                    RecordType.SOA);

                RecordSet soaResource = getresponse;
                Assert.NotNull(soaResource);
                Assert.NotNull(soaResource.SoaRecord);

                soaResource.SoaRecord.ExpireTime  = 123;
                soaResource.SoaRecord.MinimumTtl  = 1234;
                soaResource.SoaRecord.RefreshTime = 12345;
                soaResource.SoaRecord.RetryTime   = 123456;

                var updateParameters = soaResource;

                var updateResponse = testContext.DnsClient.RecordSets
                                     .CreateOrUpdate(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    "@",
                    RecordType.SOA,
                    ifMatch: null,
                    ifNoneMatch: null,
                    parameters: updateParameters);

                Assert.True(
                    TestHelpers.AreEqual(
                        soaResource,
                        updateResponse,
                        ignoreEtag: true),
                    "Response body of Update does not match expectations");

                getresponse = testContext.DnsClient.RecordSets.Get(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    "@",
                    RecordType.SOA);

                Assert.True(
                    TestHelpers.AreEqual(updateResponse, getresponse),
                    "Response body of Get does not match expectations");

                // SOA will get deleted with the zone
                testContext.DnsClient.Zones.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    ifMatch: null,
                    ifNoneMatch: null);
            }
        }
        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 #19
0
        private void ListRecordsInZone(
            bool isCrossType,
            [System.Runtime.CompilerServices.CallerMemberName] string methodName
            = "testframework_failed")
        {
            using (
                MockContext context = MockContext.Start(
                    this.GetType().FullName,
                    methodName))
            {
                SingleRecordSetTestContext testContext =
                    SetupSingleRecordSetTest(context);

                var recordSetNames = new[]
                {
                    TestUtilities.GenerateName("hydratestrec"),
                    TestUtilities.GenerateName("hydratestrec"),
                    TestUtilities.GenerateName("hydratestrec")
                };

                RecordSetScenarioTests.CreateRecordSets(
                    testContext,
                    recordSetNames);

                if (isCrossType)
                {
                    var listresponse = testContext.DnsClient.RecordSets
                                       .ListAllInResourceGroup(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName);

                    // not checking for the record count as this will return standard SOA and auth NS records as well
                    Assert.NotNull(listresponse);
                    Assert.True(
                        listresponse.Any(
                            recordSetReturned =>
                            string.Equals(
                                recordSetNames[0],
                                recordSetReturned.Name))
                        &&
                        listresponse.Any(
                            recordSetReturned =>
                            string.Equals(
                                recordSetNames[1],
                                recordSetReturned.Name))
                        &&
                        listresponse.Any(
                            recordSetReturned =>
                            string.Equals(
                                recordSetNames[2],
                                recordSetReturned.Name)),
                        "The returned records do not meet expectations");
                }
                else
                {
                    var listresponse = testContext.DnsClient.RecordSets
                                       .ListByType(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        RecordType.TXT);

                    Assert.NotNull(listresponse);
                    Assert.Equal(2, listresponse.Count());
                    Assert.True(
                        listresponse.Any(
                            recordSetReturned =>
                            string.Equals(
                                recordSetNames[0],
                                recordSetReturned.Name))
                        &&
                        listresponse.Any(
                            recordSetReturned =>
                            string.Equals(
                                recordSetNames[1],
                                recordSetReturned.Name)),
                        "The returned records do not meet expectations");
                }

                RecordSetScenarioTests.DeleteRecordSetsAndZone(
                    testContext,
                    recordSetNames);
            }
        }
Example #20
0
        private void ListRecordsInZoneWithTop(
            bool isCrossType,
            [System.Runtime.CompilerServices.CallerMemberName] string methodName
            = "testframework_failed")
        {
            using (
                MockContext context = MockContext.Start(
                    this.GetType().FullName,
                    methodName))
            {
                SingleRecordSetTestContext testContext =
                    RecordSetScenarioTests.SetupSingleRecordSetTest(context);

                var recordSetNames = new[]
                {
                    TestUtilities.GenerateName("hydratestrec") + ".com",
                    TestUtilities.GenerateName("hydratestrec") + ".com",
                    TestUtilities.GenerateName("hydratestrec") + ".com"
                };

                RecordSetScenarioTests.CreateRecordSets(
                    testContext,
                    recordSetNames);

                IPage <RecordSet> listResponse;

                if (isCrossType)
                {
                    // Using top = 3, it will pick up SOA, NS and the first TXT
                    listResponse = testContext.DnsClient.RecordSets
                                   .ListAllInResourceGroup(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        "3");
                    // verify if TXT is in the list
                    Assert.True(
                        listResponse.Where(rs => rs.Type == "TXT")
                        .All(
                            listedRecordSet =>
                            recordSetNames.Any(
                                createdName =>
                                createdName == listedRecordSet.Name)),
                        "The returned records do not meet expectations");
                }
                else
                {
                    // Using top = 3, it will pick up SOA, NS and the first TXT, process it and return just the TXT
                    listResponse = testContext.DnsClient.RecordSets.ListByType(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        RecordType.TXT,
                        "3");
                    Assert.True(
                        listResponse.All(
                            listedRecordSet =>
                            recordSetNames.Any(
                                createdName =>
                                createdName == listedRecordSet.Name)),
                        "The returned records do not meet expectations");
                }

                RecordSetScenarioTests.DeleteRecordSetsAndZone(
                    testContext,
                    recordSetNames);
            }
        }
Example #21
0
        public void UpdateRecordSetPreconditionFailed()
        {
            using (
                MockContext context = MockContext.Start(this.GetType().FullName)
                )
            {
                SingleRecordSetTestContext testContext =
                    SetupSingleRecordSetTest(context);
                var createParameters = testContext.TestRecordSkeleton;
                createParameters.CnameRecord = new CnameRecord
                {
                    Cname = "www.contoso.example.com"
                };

                var createResponse = testContext.DnsClient.RecordSets
                                     .CreateOrUpdate(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.CNAME,
                    ifMatch: null,
                    ifNoneMatch: null,
                    parameters: createParameters);

                var updateParameters = createResponse;

                // expect Precondition Failed 412
                TestHelpers.AssertThrows <CloudException>(
                    () => testContext.DnsClient.RecordSets.CreateOrUpdate(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        testContext.RecordSetName,
                        RecordType.CNAME,
                        ifMatch: "somegibberish",
                        ifNoneMatch: null,
                        parameters: updateParameters),
                    exceptionAsserts: ex => ex.Body.Code == "PreconditionFailed");

                // expect Precondition Failed 412
                TestHelpers.AssertThrows <CloudException>(
                    () => testContext.DnsClient.RecordSets.Delete(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        testContext.RecordSetName,
                        RecordType.CNAME,
                        ifMatch: "somegibberish",
                        ifNoneMatch: null),
                    exceptionAsserts: ex => ex.Body.Code == "PreconditionFailed");

                testContext.DnsClient.RecordSets.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.CNAME,
                    ifMatch: null,
                    ifNoneMatch: null);

                testContext.DnsClient.Zones.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    ifMatch: null,
                    ifNoneMatch: null);
            }
        }
        public static void CreateRecordSets(SingleRecordSetTestContext testContext, string[] recordSetNames)
        {
            RecordSetCreateOrUpdateParameters createParameters1 = testContext.GetNewTestRecordSkeleton(recordSetNames[0]);
            createParameters1.RecordSet.Properties.TxtRecords = new List<TxtRecord> { new TxtRecord { Value = new [] { "text1" }.ToList() } };
            RecordSetCreateOrUpdateParameters createParameters2 = testContext.GetNewTestRecordSkeleton(recordSetNames[1]);
            createParameters2.RecordSet.Properties.TxtRecords = new List<TxtRecord> { new TxtRecord { Value = new[] { "text1" }.ToList() } };
            RecordSetCreateOrUpdateParameters createParameters3 = testContext.GetNewTestRecordSkeleton(recordSetNames[2]);
            createParameters3.RecordSet.Properties.AaaaRecords = new List<AaaaRecord> { new AaaaRecord { Ipv6Address = "123::45" } };

            testContext.DnsClient.RecordSets.CreateOrUpdate(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                createParameters1.RecordSet.Name,
                RecordType.TXT,
                ifMatch: null,
                ifNoneMatch: null,
                parameters: createParameters1);

            testContext.DnsClient.RecordSets.CreateOrUpdate(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                createParameters2.RecordSet.Name,
                RecordType.TXT,
                ifMatch: null,
                ifNoneMatch: null,
                parameters: createParameters2);

            testContext.DnsClient.RecordSets.CreateOrUpdate(
                testContext.ResourceGroup.Name,
                testContext.ZoneName,
                createParameters3.RecordSet.Name,
                RecordType.AAAA,
                ifMatch: null,
                ifNoneMatch: null,
                parameters: createParameters3);
        }
Example #23
0
        private void RecordSetCreateGet(
            RecordType recordType,
            Action <RecordSet> setRecordsAction,
            [System.Runtime.CompilerServices.CallerMemberName] string methodName
            = "testframework_failed")
        {
            using (
                MockContext context = MockContext.Start(
                    this.GetType().FullName,
                    methodName))
            {
                SingleRecordSetTestContext testContext =
                    SetupSingleRecordSetTest(context);
                var createParameters = testContext.TestRecordSkeleton;
                setRecordsAction(createParameters);

                var createResponse = testContext.DnsClient.RecordSets
                                     .CreateOrUpdate(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    recordType,
                    ifMatch: null,
                    ifNoneMatch: null,
                    parameters: createParameters);

                Assert.True(
                    TestHelpers.AreEqual(
                        createParameters,
                        createResponse,
                        ignoreEtag: true),
                    "Response body of Create does not match expectations");
                Assert.False(string.IsNullOrWhiteSpace(createResponse.Etag));

                var getresponse = testContext.DnsClient.RecordSets.Get(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    recordType);

                Assert.True(
                    TestHelpers.AreEqual(
                        createResponse,
                        getresponse,
                        ignoreEtag: false),
                    "Response body of Get does not match expectations");

                // BUG 2364951: should work without specifying ETag
                testContext.DnsClient.RecordSets.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    recordType,
                    ifMatch: null,
                    ifNoneMatch: null);

                var deleteResponse = testContext.DnsClient.Zones.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    ifMatch: null,
                    ifNoneMatch: null);
            }
        }
        public void CrudRecordSetFullCycle()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                SingleRecordSetTestContext        testContext      = SetupSingleRecordSetTest();
                RecordSetCreateOrUpdateParameters createParameters = testContext.TestRecordSkeleton;
                createParameters.RecordSet.Properties.ARecords = new List <ARecord> {
                    new ARecord {
                        Ipv4Address = "123.32.1.0"
                    }
                };
                createParameters.RecordSet.Properties.Ttl = 60;

                // Create the records clean, verify response
                RecordSetCreateOrUpdateResponse createResponse = testContext.DnsClient.RecordSets.CreateOrUpdate(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A,
                    createParameters);

                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);
                Assert.True(
                    TestHelpers.AreEqual(createParameters.RecordSet, createResponse.RecordSet, ignoreEtag: true),
                    "Response body of Create does not match expectations");
                Assert.False(string.IsNullOrWhiteSpace(createResponse.RecordSet.ETag));

                // Retrieve the zone after create, verify response
                var getresponse = testContext.DnsClient.RecordSets.Get(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A);

                Assert.Equal(HttpStatusCode.OK, getresponse.StatusCode);
                Assert.True(
                    TestHelpers.AreEqual(createResponse.RecordSet, getresponse.RecordSet, ignoreEtag: false),
                    "Response body of Get does not match expectations");

                // Call Update on the object returned by Create (important distinction from Get below)
                Models.RecordSet createdRecordSet = createResponse.RecordSet;
                createdRecordSet.Tags = new Dictionary <string, string> {
                    { "tag1", "value1" }, { "tag2", "value2" }
                };
                createdRecordSet.Properties.Ttl      = 120;
                createdRecordSet.Properties.ARecords = new List <ARecord>
                {
                    new ARecord {
                        Ipv4Address = "123.32.1.0"
                    },
                    new ARecord {
                        Ipv4Address = "101.10.0.1"
                    }
                };

                RecordSetCreateOrUpdateResponse updateResponse = testContext.DnsClient.RecordSets.CreateOrUpdate(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A,
                    new RecordSetCreateOrUpdateParameters {
                    RecordSet = createdRecordSet
                });

                Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode);
                Assert.True(
                    TestHelpers.AreEqual(createdRecordSet, updateResponse.RecordSet, ignoreEtag: true),
                    "Response body of Update does not match expectations");
                Assert.False(string.IsNullOrWhiteSpace(updateResponse.RecordSet.ETag));

                // Retrieve the records after create, verify response
                getresponse = testContext.DnsClient.RecordSets.Get(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A);

                Assert.Equal(HttpStatusCode.OK, getresponse.StatusCode);
                Assert.True(
                    TestHelpers.AreEqual(updateResponse.RecordSet, getresponse.RecordSet),
                    "Response body of Get does not match expectations");

                // Call Update on the object returned by Get (important distinction from Create above)
                Models.RecordSet retrievedRecordSet = getresponse.RecordSet;
                retrievedRecordSet.Tags = new Dictionary <string, string> {
                    { "tag1", "value1" }, { "tag2", "value2" }, { "tag3", "value3" }
                };
                retrievedRecordSet.Properties.Ttl      = 180;
                retrievedRecordSet.Properties.ARecords = new List <ARecord>
                {
                    new ARecord {
                        Ipv4Address = "123.32.1.0"
                    },
                    new ARecord {
                        Ipv4Address = "101.10.0.1"
                    },
                    new ARecord {
                        Ipv4Address = "22.33.44.55"
                    },
                };

                updateResponse = testContext.DnsClient.RecordSets.CreateOrUpdate(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A,
                    new RecordSetCreateOrUpdateParameters {
                    RecordSet = retrievedRecordSet
                });

                Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode);
                Assert.True(
                    TestHelpers.AreEqual(retrievedRecordSet, updateResponse.RecordSet, ignoreEtag: true),
                    "Response body of Update does not match expectations");
                Assert.False(string.IsNullOrWhiteSpace(updateResponse.RecordSet.ETag));

                // Delete the record set
                AzureOperationResponse deleteResponse = testContext.DnsClient.RecordSets.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    testContext.RecordSetName,
                    RecordType.A,
                    new RecordSetDeleteParameters());
                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);

                // Delete the zone
                deleteResponse = testContext.DnsClient.Zones.Delete(
                    testContext.ResourceGroup.Name,
                    testContext.ZoneName,
                    new ZoneDeleteParameters());
            }
        }
        public static void DeleteRecordSetsAndZone(SingleRecordSetTestContext testContext, string[] recordSetNames)
        {
            testContext.DnsClient.RecordSets.Delete(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        recordSetNames[0],
                        RecordType.TXT,
                        new RecordSetDeleteParameters { IfMatch = null });

            testContext.DnsClient.RecordSets.Delete(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        recordSetNames[1],
                        RecordType.TXT,
                        new RecordSetDeleteParameters { IfMatch = null });

            testContext.DnsClient.RecordSets.Delete(
                        testContext.ResourceGroup.Name,
                        testContext.ZoneName,
                        recordSetNames[2],
                        RecordType.AAAA,
                        new RecordSetDeleteParameters { IfMatch = null });

            testContext.DnsClient.Zones.Delete(testContext.ResourceGroup.Name, testContext.ZoneName, new ZoneDeleteParameters());
        }