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);
            }
        }
        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);
            }
        }
        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);
        }
        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());
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a RecordSet within a DNS zone.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Dns.IRecordSetOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='zoneName'>
 /// Required. The name of the zone without a terminating dot.
 /// </param>
 /// <param name='relativeRecordSetName'>
 /// Required. The name of the RecordSet, relative to the name of the
 /// zone.
 /// </param>
 /// <param name='recordType'>
 /// Required. The type of DNS record.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the CreateOrUpdate operation.
 /// </param>
 /// <returns>
 /// The response to a RecordSet CreateOrUpdate operation.
 /// </returns>
 public static Task <RecordSetCreateOrUpdateResponse> CreateOrUpdateAsync(this IRecordSetOperations operations, string resourceGroupName, string zoneName, string relativeRecordSetName, RecordType recordType, RecordSetCreateOrUpdateParameters parameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, zoneName, relativeRecordSetName, recordType, parameters, CancellationToken.None));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates a RecordSet within a DNS zone.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Dns.IRecordSetOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='zoneName'>
 /// Required. The name of the zone without a terminating dot.
 /// </param>
 /// <param name='relativeRecordSetName'>
 /// Required. The name of the RecordSet, relative to the name of the
 /// zone.
 /// </param>
 /// <param name='recordType'>
 /// Required. The type of DNS record.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the CreateOrUpdate operation.
 /// </param>
 /// <returns>
 /// The response to a RecordSet CreateOrUpdate operation.
 /// </returns>
 public static RecordSetCreateOrUpdateResponse CreateOrUpdate(this IRecordSetOperations operations, string resourceGroupName, string zoneName, string relativeRecordSetName, RecordType recordType, RecordSetCreateOrUpdateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IRecordSetOperations)s).CreateOrUpdateAsync(resourceGroupName, zoneName, relativeRecordSetName, recordType, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }