public void ServerCommunicationLinkCrud()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string commLinkName = TestUtilities.GenerateName("csm-sql-commlinkcrud-");

                Sql2ScenarioHelper.RunTwoServersTestInEnvironment(
                    handler,
                    "12.0",
                    false,
                    (sqlClient, resGroupName, server1, server2) =>
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create Test
                    var linkProperties = new ServerCommunicationLinkCreateOrUpdateProperties()
                    {
                        PartnerServer = server2.Name
                    };

                    var link1 = sqlClient.CommunicationLinks.CreateOrUpdate(resGroupName, server1.Name, commLinkName, new ServerCommunicationLinkCreateOrUpdateParameters()
                    {
                        Location   = server1.Location,
                        Properties = linkProperties
                    });

                    TestUtilities.ValidateOperationResponse(link1, HttpStatusCode.Created);
                    ValidateServerCommunicationLink(
                        link1.ServerCommunicationLink,
                        commLinkName,
                        linkProperties.PartnerServer);

                    //////////////////////////////////////////////////////////////////////
                    // Get Test.
                    var link2 = sqlClient.CommunicationLinks.Get(resGroupName, server1.Name, commLinkName);

                    TestUtilities.ValidateOperationResponse(link2, HttpStatusCode.OK);
                    ValidateServerCommunicationLink(
                        link2.ServerCommunicationLink,
                        commLinkName,
                        linkProperties.PartnerServer);

                    //////////////////////////////////////////////////////////////////////
                    // List Test.
                    var links = sqlClient.CommunicationLinks.List(resGroupName, server1.Name);

                    TestUtilities.ValidateOperationResponse(links, HttpStatusCode.OK);
                    Assert.Equal(1, links.ServerCommunicationLinks.Count);

                    //////////////////////////////////////////////////////////////////////
                    // Delete Test.
                    var resp = sqlClient.CommunicationLinks.Delete(resGroupName, server1.Name, link1.ServerCommunicationLink.Name);
                    TestUtilities.ValidateOperationResponse(resp, HttpStatusCode.OK);
                });
            }
        }
예제 #2
0
        public void ServerDisasterRecoveryConfigurationCrud()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string failoverAliasName = TestUtilities.GenerateName("csm-sql-drc-alias-");

                Sql2ScenarioHelper.RunTwoServersTestInEnvironment(
                    handler,
                    "12.0",
                    true,
                    (sqlClient, resGroupName, server1, server2) =>
                {
                    validateDrcNotExist(sqlClient, resGroupName, server1.Name, failoverAliasName);
                    validateDrcNotExist(sqlClient, resGroupName, server2.Name, failoverAliasName);

                    // Create and verify
                    //
                    ServerDisasterRecoveryConfigurationCreateOrUpdateResponse createResponse = CreateDrc(sqlClient, resGroupName, server1, server2, failoverAliasName);
                    TestUtilities.ValidateOperationResponse(createResponse, HttpStatusCode.Created);

                    GetAndValidateDrc(sqlClient, resGroupName, server1.Name, failoverAliasName, server2.Name, true);
                    GetAndValidateDrc(sqlClient, resGroupName, server2.Name, failoverAliasName, server1.Name, false);

                    // Invalid failover, then valid failover and verify
                    //
                    Assert.Throws <Hyak.Common.CloudException>(() => sqlClient.ServerDisasterRecoveryConfigurations.Failover(resGroupName, server1.Name, failoverAliasName));
                    AzureOperationResponse failoverResponse = sqlClient.ServerDisasterRecoveryConfigurations.Failover(resGroupName, server2.Name, failoverAliasName);
                    TestUtilities.ValidateOperationResponse(failoverResponse);

                    GetAndValidateDrc(sqlClient, resGroupName, server1.Name, failoverAliasName, server2.Name, false);
                    GetAndValidateDrc(sqlClient, resGroupName, server2.Name, failoverAliasName, server1.Name, true);

                    // Delete and verify
                    //
                    AzureOperationResponse deleteResponse = sqlClient.ServerDisasterRecoveryConfigurations.Delete(resGroupName, server1.Name, failoverAliasName);
                    TestUtilities.ValidateOperationResponse(deleteResponse);

                    validateDrcNotExist(sqlClient, resGroupName, server1.Name, failoverAliasName);
                    validateDrcNotExist(sqlClient, resGroupName, server2.Name, failoverAliasName);
                });
            }
        }