Ejemplo n.º 1
0
        public void SyncMemberCRUDTest()
        {
            var handler = new BasicDelegatingHandler();

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

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for resource group create
                string resGroupName          = TestUtilities.GenerateName("csm-rg-smcrud");
                string resourceGroupLocation = "West US";

                // Variables for server create
                string serverName     = TestUtilities.GenerateName("csm-sql-smcrud-server");
                string serverLocation = "West US 2";

                // Variables for database create
                string databaseName            = TestUtilities.GenerateName("csm-sql-smcrud-db");
                string syncDatabaseName        = TestUtilities.GenerateName("csm-sql-smcrud-syncdb");
                string memberDatabaseName      = TestUtilities.GenerateName("csm-sql-smcrud-memberdb");
                string memberFullDNSServerName = serverName + ".sqltest-eg1.mscds.com";

                // Variables for sync group create
                string syncGroupName = TestUtilities.GenerateName("csm-sql-smcrud-syncgroup");
                string adminLogin    = "******";
                string adminPass     = "******";
                int    interval      = 300;
                ConflictResolutionPolicyType conflictResolutionPolicy = ConflictResolutionPolicyType.Memberwin;
                string subscriptionId = sqlClient.Credentials.SubscriptionId;
                string syncDatabaseId = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}/databases/{3}",
                                                      subscriptionId, resGroupName, serverName, syncDatabaseName);

                // Variables for sync member creation
                string                      syncMemberName1            = TestUtilities.GenerateName("csm-sql-smcrud-sm");
                SyncDirectionEnum           syncDirection              = SyncDirectionEnum.Bidirectional;
                DatabaseTypeEnum            databaseType               = DatabaseTypeEnum.AzureSqlDatabase;
                SyncMemberGeneralParameters syncMemberGeneralParameter = new SyncMemberGeneralParameters()
                {
                    SyncGroupName  = syncGroupName,
                    SyncMemberName = syncMemberName1
                };

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = resourceGroupLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test
                    var createServerResponse = CreateServerForTest(resGroupName, serverName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createServerResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create database for test
                    var createDbResponse = CreateDatabaseForTest(resGroupName, serverName, databaseName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create sync database for test
                    var createDbResponse2 = CreateDatabaseForTest(resGroupName, serverName, syncDatabaseName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createDbResponse2, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create member database for test
                    var createMemberDbResponse = CreateDatabaseForTest(resGroupName, serverName, memberDatabaseName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createMemberDbResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create sync group for test
                    var createSyncGroupResponse = sqlClient.DataSync.CreateOrUpdateSyncGroup(resGroupName, serverName, databaseName, new SyncGroupCreateOrUpdateParameters()
                    {
                        SyncGroupName = syncGroupName,
                        Properties    = new SyncGroupCreateOrUpdateProperties()
                        {
                            Interval = interval,
                            ConflictResolutionPolicy = conflictResolutionPolicy,
                            SyncDatabaseId           = syncDatabaseId,
                        },
                    });

                    //////////////////////////////////////////////////////////////////////
                    // Create sync member for test
                    var createSyncMemberResponse = sqlClient.DataSync.CreateOrUpdateSyncMember(resGroupName, serverName, databaseName, new SyncMemberCreateOrUpdateParameters()
                    {
                        SyncGroupName  = syncGroupName,
                        SyncMemberName = syncMemberName1,
                        Properties     = new SyncMemberCreateOrUpdateProperties()
                        {
                            SyncDirection = syncDirection,
                            DatabaseType  = databaseType,
                            DatabaseName  = memberDatabaseName,
                            ServerName    = memberFullDNSServerName,
                            UserName      = adminLogin,
                            Password      = adminPass,
                        },
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createSyncMemberResponse, HttpStatusCode.Created);
                    VerifySyncMemberInformation(createSyncMemberResponse.SyncMember, syncDirection, databaseType, memberFullDNSServerName, memberDatabaseName);

                    //////////////////////////////////////////////////////////////////////
                    // Get the sync member
                    var getSyncMember1 = sqlClient.DataSync.GetSyncMember(resGroupName, serverName, databaseName, syncMemberGeneralParameter);
                    TestUtilities.ValidateOperationResponse(getSyncMember1);
                    VerifySyncMemberInformation(getSyncMember1.SyncMember, syncDirection, databaseType, memberFullDNSServerName, memberDatabaseName);

                    //////////////////////////////////////////////////////////////////////
                    // List all sync members
                    var listSyncMember = sqlClient.DataSync.ListSyncMember(resGroupName, serverName, databaseName, syncGroupName);
                    TestUtilities.ValidateOperationResponse(listSyncMember);
                    Assert.Equal(1, listSyncMember.SyncMembers.Count);
                    VerifySyncMemberInformation(listSyncMember.SyncMembers[0], syncDirection, databaseType, memberFullDNSServerName, memberDatabaseName);

                    //////////////////////////////////////////////////////////////////////
                    // Update sync member test
                    var updateSyncMember1 = sqlClient.DataSync.UpdateSyncMember(resGroupName, serverName, databaseName, new SyncMemberCreateOrUpdateParameters()
                    {
                        SyncGroupName  = syncGroupName,
                        SyncMemberName = syncMemberName1,
                        Properties     = new SyncMemberCreateOrUpdateProperties()
                        {
                            DatabaseType = DatabaseTypeEnum.AzureSqlDatabase,
                            UserName     = adminLogin,
                            Password     = adminPass
                        },
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(updateSyncMember1);

                    var refreshSchemaResponse = sqlClient.DataSync.InvokeSyncMemberSchemaRefresh(resGroupName, serverName, databaseName, syncMemberGeneralParameter);
                    TestUtilities.ValidateOperationResponse(refreshSchemaResponse);

                    //////////////////////////////////////////////////////////////////////
                    // Get full schema of member database of sync member
                    var getSyncMemberSchema1 = sqlClient.DataSync.GetSyncMemberSchema(resGroupName, serverName, databaseName, syncMemberGeneralParameter);
                    TestUtilities.ValidateOperationResponse(getSyncMemberSchema1);

                    //////////////////////////////////////////////////////////////////////
                    // Delete sync member test.
                    var deleteSyncMember1 = sqlClient.DataSync.DeleteSyncMember(resGroupName, serverName, databaseName, syncMemberGeneralParameter);
                    TestUtilities.ValidateOperationResponse(deleteSyncMember1);

                    //////////////////////////////////////////////////////////////////////
                    // Delete sync group.
                    var deleteSyncGroup1 = sqlClient.DataSync.DeleteSyncGroup(resGroupName, serverName, databaseName, syncGroupName);

                    sqlClient.Servers.Delete(resGroupName, serverName);
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the full schema of member database of a sync member
        /// </summary>
        public SyncFullSchema GetSyncMemberSchema(string resourceGroupName, string serverName, string databaseName, SyncMemberGeneralParameters parameters)
        {
            var result = GetLegacySqlClient().DataSync.GetSyncMemberSchema(resourceGroupName, serverName, databaseName, parameters);

            return(result.FullSchema == null || !result.FullSchema.Any() ? null : result.FullSchema.FirstOrDefault());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Remove a specified sync member
 /// </summary>
 public void RemoveSyncMember(string resourceGroupName, string serverName, string databaseName, SyncMemberGeneralParameters parameters)
 {
     GetLegacySqlClient().DataSync.DeleteSyncMember(resourceGroupName, serverName, databaseName, parameters);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Get a sync group
 /// </summary>
 public SyncMember GetSyncMember(string resourceGroupName, string serverName, string databaseName, SyncMemberGeneralParameters parameters)
 {
     return(GetLegacySqlClient().DataSync.GetSyncMember(resourceGroupName, serverName, databaseName, parameters).SyncMember);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Invoke the schema of member database refreshing
 /// </summary>
 public void InvokeSyncMemberSchemaRefresh(string resourceGroupName, string serverName, string databaseName, SyncMemberGeneralParameters parameters)
 {
     GetLegacySqlClient().DataSync.InvokeSyncMemberSchemaRefresh(resourceGroupName, serverName, databaseName, parameters);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Get a sync group
 /// </summary>
 public Management.Sql.Models.SyncMember GetSyncMember(string resourceGroupName, string serverName, string databaseName, SyncMemberGeneralParameters parameters)
 {
     return(GetCurrentSqlClient().SyncMembers.Get(resourceGroupName, serverName, databaseName, parameters.SyncGroupName, parameters.SyncMemberName));
 }