/// <summary>
        /// The non-boilerplated test code of the APIs for managing the lifecycle of a given database's security alert policy. It is meant to be called with a name of an already existing database (and therefore already existing 
        /// server and resource group). This test does not create these resources and does not remove them.
        /// </summary>
        private static void TestDatabaseSecurityAlertApis(SqlManagementClient sqlClient, string resourceGroupName, Server server, Database database)
        {
            var getDefaultDatabaseSecurityAlertPolicyResponse = sqlClient.SecurityAlertPolicy.GetDatabaseSecurityAlertPolicy(resourceGroupName, server.Name, database.Name);
            var properties = getDefaultDatabaseSecurityAlertPolicyResponse.SecurityAlertPolicy.Properties;

            // Verify that the initial Get request contains the default policy.
            TestUtilities.ValidateOperationResponse(getDefaultDatabaseSecurityAlertPolicyResponse);
            VerifySecurityAlertPolicyInformation(GetDefaultDatabaseSecurityAlertProperties(), properties);

            // Modify the policy properties, send and receive, see it its still ok
            ChangeSecurityAlertPolicy(properties);
            var updateParams = new DatabaseSecurityAlertPolicyCreateOrUpdateParameters { Properties = properties };

            var updateResponse = sqlClient.SecurityAlertPolicy.CreateOrUpdateDatabaseSecurityAlertPolicy(resourceGroupName, server.Name, database.Name, updateParams);

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

            var getUpdatedPolicyResponse = sqlClient.SecurityAlertPolicy.GetDatabaseSecurityAlertPolicy(resourceGroupName, server.Name, database.Name);
            var updatedProperties = getUpdatedPolicyResponse.SecurityAlertPolicy.Properties;

            // Verify that the Get request contains the updated policy.
            TestUtilities.ValidateOperationResponse(getUpdatedPolicyResponse);
            VerifySecurityAlertPolicyInformation(properties, updatedProperties);
        }
 /// <summary>
 /// Creates or updates an Azure SQL Database security alert policy.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Sql.ISecurityAlertPolicyOperations.
 /// </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 security
 /// alert policy applies.
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for creating or updating a Azure
 /// SQL Database security alert policy.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse CreateOrUpdateDatabaseSecurityAlertPolicy(this ISecurityAlertPolicyOperations operations, string resourceGroupName, string serverName, string databaseName, DatabaseSecurityAlertPolicyCreateOrUpdateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((ISecurityAlertPolicyOperations)s).CreateOrUpdateDatabaseSecurityAlertPolicyAsync(resourceGroupName, serverName, databaseName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Takes the cmdlets model object and transform it to the policy as expected by the endpoint
 /// </summary>
 /// <param name="model">The SecurityAlert model object</param>
 /// <returns>The communication model object</returns>
 private DatabaseSecurityAlertPolicyCreateOrUpdateParameters PolicizeDatabaseSecurityAlertModel(DatabaseThreatDetectionPolicyModel model)
 {
     var updateParameters = new DatabaseSecurityAlertPolicyCreateOrUpdateParameters();
     var properties = PopulatePolicyProperties(model, new DatabaseSecurityAlertPolicyProperties()) as DatabaseSecurityAlertPolicyProperties;
     updateParameters.Properties = properties;
     return updateParameters;
 }
 /// <summary>
 /// Takes the cmdlets model object and transform it to the policy as expected by the endpoint
 /// </summary>
 /// <param name="model">The SecurityAlert model object</param>
 /// <returns>The communication model object</returns>
 private DatabaseSecurityAlertPolicyCreateOrUpdateParameters PolicizeDatabaseSecurityAlertModel(DatabaseThreatDetectionPolicyModel model)
 {
     DatabaseSecurityAlertPolicyCreateOrUpdateParameters updateParameters = new DatabaseSecurityAlertPolicyCreateOrUpdateParameters();
     DatabaseSecurityAlertPolicyProperties properties = new DatabaseSecurityAlertPolicyProperties();
     updateParameters.Properties = properties;
     properties.State = PolicizeThreatDetectionState(model.ThreatDetectionState);
     properties.EmailAddresses = model.NotificationRecipientsEmails ?? "";
     properties.EmailAccountAdmins = model.EmailAdmins
         ? SecurityConstants.ThreatDetectionEndpoint.Enabled
         : SecurityConstants.ThreatDetectionEndpoint.Disabled;
     properties.DisabledAlerts = ExtractExcludedDetectionType(model);
     return updateParameters;
 }
 /// <summary>
 /// Calls the set security alert APIs for the database security alert policy for the given database in the given database server in the given resource group
 /// </summary>
 public void SetDatabaseSecurityAlertPolicy(string resourceGroupName, string serverName, string databaseName, string clientRequestId, DatabaseSecurityAlertPolicyCreateOrUpdateParameters parameters)
 {
     ISecurityAlertPolicyOperations operations = GetCurrentSqlClient(clientRequestId).SecurityAlertPolicy;
     operations.CreateOrUpdateDatabaseSecurityAlertPolicy(resourceGroupName, serverName, databaseName, parameters);
 }
 /// <summary>
 /// Creates or updates an Azure SQL Database security alert policy.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Sql.ISecurityAlertPolicyOperations.
 /// </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 security
 /// alert policy applies.
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for creating or updating a Azure
 /// SQL Database security alert policy.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> CreateOrUpdateDatabaseSecurityAlertPolicyAsync(this ISecurityAlertPolicyOperations operations, string resourceGroupName, string serverName, string databaseName, DatabaseSecurityAlertPolicyCreateOrUpdateParameters parameters)
 {
     return operations.CreateOrUpdateDatabaseSecurityAlertPolicyAsync(resourceGroupName, serverName, databaseName, parameters, CancellationToken.None);
 }