/// <summary> 
        /// The non-boilerplated test code of the APIs for managing the lifecycle of a given database's secure connection policy. 
        /// It is meant to be called with a name of an already exisiting database (and therefore already existing server and resource group). 
        /// </summary> 
        private void TestSecureConnectionAPIs(SqlManagementClient sqlClient, string resourceGroupName, Server server, Database database)
        {
            DatabaseSecureConnectionPolicyGetResponse getDefaultSecureConnectionPolicyResponse = sqlClient.SecureConnection.GetDatabasePolicy(resourceGroupName, server.Name, database.Name);
            DatabaseSecureConnectionPolicyProperties properties = getDefaultSecureConnectionPolicyResponse.SecureConnectionPolicy.Properties;

            // Verify that the initial Get request contains the default policy.
            TestUtilities.ValidateOperationResponse(getDefaultSecureConnectionPolicyResponse, HttpStatusCode.OK);
            VerifySecureConnectionPolicyInformation(getDefaultSecureConnectionPolicyProperties(server.Name), properties);

            // Modify the policy properties, send and receive, see it its still ok
            properties.SecurityEnabledAccess = "Required";
            DatabaseSecureConnectionPolicyCreateOrUpdateParameters updateParams = new DatabaseSecureConnectionPolicyCreateOrUpdateParameters();
            updateParams.Properties = ConvertToSecureConnectionPolicyCreateProperties(properties);

            var updateResponse = sqlClient.SecureConnection.CreateOrUpdateDatabasePolicy(resourceGroupName, server.Name, database.Name, updateParams);

            // Verify that the initial Get request of contains the default policy.
            TestUtilities.ValidateOperationResponse(updateResponse, HttpStatusCode.OK);

            DatabaseSecureConnectionPolicyGetResponse getUpdatedPolicyResponse = sqlClient.SecureConnection.GetDatabasePolicy(resourceGroupName, server.Name, database.Name);
            DatabaseSecureConnectionPolicyProperties updatedProperties = getUpdatedPolicyResponse.SecureConnectionPolicy.Properties;

            // Verify that the Get request contains the updated policy.
            TestUtilities.ValidateOperationResponse(getUpdatedPolicyResponse, HttpStatusCode.OK);
            VerifySecureConnectionPolicyInformation(properties, updatedProperties);
        }
 /// <summary>
 /// Creates or updates an Azure SQL Connection policy.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Sql.ISecureConnectionPolicyOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the Resource Group to which the server
 /// belongs.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Database Server on which the
 /// database is hosted.
 /// </param>
 /// <param name='databaseName'>
 /// Required. The name of the Azure SQL Database for which the policy
 /// applies.
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for createing or updating a
 /// secure connection policy.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse CreateOrUpdateDatabasePolicy(this ISecureConnectionPolicyOperations operations, string resourceGroupName, string serverName, string databaseName, DatabaseSecureConnectionPolicyCreateOrUpdateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((ISecureConnectionPolicyOperations)s).CreateOrUpdateDatabasePolicyAsync(resourceGroupName, serverName, databaseName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Creates or updates an Azure SQL Connection policy.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Sql.ISecureConnectionPolicyOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the Resource Group to which the server
 /// belongs.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Database Server on which the
 /// database is hosted.
 /// </param>
 /// <param name='databaseName'>
 /// Required. The name of the Azure SQL Database for which the policy
 /// applies.
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for createing or updating a
 /// secure connection policy.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> CreateOrUpdateDatabasePolicyAsync(this ISecureConnectionPolicyOperations operations, string resourceGroupName, string serverName, string databaseName, DatabaseSecureConnectionPolicyCreateOrUpdateParameters parameters)
 {
     return operations.CreateOrUpdateDatabasePolicyAsync(resourceGroupName, serverName, databaseName, parameters, CancellationToken.None);
 }
 /// <summary>
 /// Set (or create) the secure connection policy for a specific database
 /// </summary>
 public void SetDatabaseSecureConnectionPolicy(string resourceGroupName, string serverName, string databaseName, string clientRequestId, DatabaseSecureConnectionPolicyCreateOrUpdateParameters parameters)
 {
     ISecureConnectionPolicyOperations operations = GetCurrentSqlClient(clientRequestId).SecureConnection;
     operations.CreateOrUpdateDatabasePolicy(resourceGroupName, serverName, databaseName, parameters);
 }
 /// <summary>
 /// Takes the cmdlets model object and transform it to the policy as expected by the endpoint
 /// </summary>
 /// <param name="model">The Secure Connection Policy model object</param>
 /// <returns>The communication model object</returns>
 private DatabaseSecureConnectionPolicyCreateOrUpdateParameters PolicizeDatabaseSecureConnectionModel(DatabaseSecureConnectionPolicyModel model)
 {
     DatabaseSecureConnectionPolicyCreateOrUpdateParameters updateParameters = new DatabaseSecureConnectionPolicyCreateOrUpdateParameters();
     DatabaseSecureConnectionPolicyCreateOrUpdateProperties properties = new DatabaseSecureConnectionPolicyCreateOrUpdateProperties();
     updateParameters.Properties = properties;
     properties.SecurityEnabledAccess = model.SecureConnectionState == SecureConnectionStateType.Required ? SecurityConstants.SecureConnectionEndpoint.Required : SecurityConstants.SecureConnectionEndpoint.Optional;
     return updateParameters;
 }