Esempio n. 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);
            }
        }
Esempio n. 2
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());
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
            }
        }
        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);
        }
Esempio n. 6
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);
            }
        }
        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);
        }