Wrapper class of the result data from Sync command response.
Exemplo n.º 1
0
        /// <summary>
        /// Load sync response to sync store.
        /// </summary>
        /// <param name="response">The response of Sync command.</param>
        /// <returns>The sync store instance.</returns>
        public static SyncStore LoadSyncResponse(ActiveSyncResponseBase <Response.Sync> response)
        {
            if (response.ResponseData.Item == null)
            {
                return(null);
            }

            SyncStore result = new SyncStore();

            Response.SyncCollectionsCollection collection = ((Response.SyncCollections)response.ResponseData.Item).Collection[0];
            for (int i = 0; i < collection.ItemsElementName.Length; i++)
            {
                switch (collection.ItemsElementName[i])
                {
                case Response.ItemsChoiceType10.CollectionId:
                    result.CollectionId = collection.Items[i].ToString();
                    break;

                case Response.ItemsChoiceType10.SyncKey:
                    result.SyncKey = collection.Items[i].ToString();
                    break;

                case Response.ItemsChoiceType10.Status:
                    result.Status = Convert.ToByte(collection.Items[i]);
                    break;

                case Response.ItemsChoiceType10.Commands:
                    Response.SyncCollectionsCollectionCommands commands = collection.Items[i] as Response.SyncCollectionsCollectionCommands;
                    if (commands != null)
                    {
                        foreach (SyncItem item in LoadAddCommands(commands))
                        {
                            result.AddCommands.Add(item);
                        }
                    }

                    break;

                case Response.ItemsChoiceType10.Responses:
                    Response.SyncCollectionsCollectionResponses responses = collection.Items[i] as Response.SyncCollectionsCollectionResponses;
                    if (responses != null)
                    {
                        if (responses.Add != null)
                        {
                            foreach (Response.SyncCollectionsCollectionResponsesAdd add in responses.Add)
                            {
                                result.AddResponses.Add(add);
                            }
                        }
                    }

                    break;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get ServerId from Sync response.
        /// </summary>
        /// <param name="syncResponse">The response of Sync command.</param>
        /// <param name="subject">The subject of the email to get.</param>
        /// <returns>The ServerId of the email.</returns>
        public static string GetServerIdFromSyncResponse(SyncStore syncResponse, string subject)
        {
            string itemServerId = null;

            foreach (SyncItem add in syncResponse.AddCommands)
            {
                if (add.Subject == subject)
                {
                    itemServerId = add.ServerId;
                    break;
                }
            }

            return(itemServerId);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Call Sync command to synchronize changes in a folder between the client and the server.
        /// </summary>
        /// <param name="collectionId">The CollectionId of the folder to sync.</param>
        /// <returns>The SyncStore abstracted from the response of Sync command.</returns>
        protected SyncStore CallSyncCommand(string collectionId)
        {
            // Call initial Sync command.
            SyncResponse syncResponse = this.CallInitialSyncCommand(collectionId);

            Site.Assert.IsNotNull(TestSuiteHelper.LoadSyncResponse(syncResponse), "The Sync response should not be null.");

            SyncRequest syncRequest = TestSuiteHelper.GetSyncRequest(collectionId, TestSuiteHelper.LoadSyncResponse(syncResponse).SyncKey);
            syncRequest.RequestData.WindowSize = "512";

            // If there is MoreAvailable tag in the Sync command response, synchronize again to continue getting items from the server.
            SendStringResponse syncResponseString;
            SyncStore syncStoreTotal = new SyncStore();
            do
            {
                // Get the latest SyncKey.
                syncRequest.RequestData.Collections[0].SyncKey = TestSuiteHelper.LoadSyncResponse(syncResponse).SyncKey;

                // Call Sync command by HTTP POST using the SyncKey returned from last sync.
                syncResponseString = this.HTTPAdapter.HTTPPOST(CommandName.Sync, null, syncRequest.GetRequestDataSerializedXML());

                if (!string.IsNullOrEmpty(syncResponseString.ResponseDataXML))
                {
                    // Check the command is executed successfully.
                    this.CheckResponseStatus(syncResponseString.ResponseDataXML);

                    // Convert from SendStringResponse to SyncResponse.
                    syncResponse = TestSuiteHelper.ConvertSyncResponseFromSendString(syncResponseString);
                    SyncStore syncStore = TestSuiteHelper.LoadSyncResponse(syncResponse);
                    syncStoreTotal.SyncKey = syncStore.SyncKey;
                    for (int i = 0; i < syncStore.AddCommands.Count; i++)
                    {
                        syncStoreTotal.AddCommands.Add(syncStore.AddCommands[i]);
                    }
                }
            }
            while (syncResponseString.ResponseDataXML.Contains("<MoreAvailable />"));

            // Return the SyncStore abstracted from the syncResponse.
            return syncStoreTotal;
        }
        public void MSASHTTP_S01_TC11_CommandCode_FolderRelatedCommands()
        {
            string folderNameToCreate = Common.GenerateResourceName(this.Site, "CreatedFolder");
            string folderNameToUpdate = Common.GenerateResourceName(this.Site, "UpdatedFolder");

            #region Call FolderSync command to synchronize the folder hierarchy.
            FolderSyncResponse folderSyncResponse = this.CallFolderSyncCommand();
            #endregion

            #region Call FolderCreate command to create a sub folder under Inbox folder.
            FolderCreateResponse folderCreateResponse = this.CallFolderCreateCommand(folderSyncResponse.ResponseData.SyncKey, folderNameToCreate, Common.GetDefaultFolderServerId(folderSyncResponse, FolderType.Inbox, Site));
            #endregion

            #region Call FolderSync command to synchronize the folder hierarchy.
            folderSyncResponse = this.CallFolderSyncCommand();

            // Get the created folder name using the ServerId returned in FolderSync response.
            string createdFolderName = this.GetFolderFromFolderSyncResponse(folderSyncResponse, folderCreateResponse.ResponseData.ServerId, "DisplayName");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R493");

            // Verify MS-ASHTTP requirement: MS-ASHTTP_R493
            // The created folder could be got in FolderSync response, so this requirement can be captured.
            Site.CaptureRequirementIfAreEqual <string>(
                folderNameToCreate,
                createdFolderName,
                493,
                @"[In Command Codes] [Command] FolderCreate creates an e-mail, [calendar, or contacts folder] on the server.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R491");

            // Verify MS-ASHTTP requirement: MS-ASHTTP_R491
            // R493 is captured, so this requirement can be captured directly.
            Site.CaptureRequirement(
                491,
                @"[In Command Codes] [Command] FolderSync synchronizes the folder hierarchy.");

            // Call the Sync command with latest SyncKey without change in folder.
            SyncStore syncResponse = this.CallSyncCommand(folderCreateResponse.ResponseData.ServerId);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R482");

            // Verify MS-ASHTTP requirement: MS-ASHTTP_R482
            // If response is not in xml, this requirement can be captured.
            Site.CaptureRequirementIfIsNull(
                syncResponse.SyncKey,
                482,
                @"[In Response Body] Three commands have no XML body in certain contexts: [GetAttachment,] Sync [, and Ping].");
            #endregion

            #region Call FolderUpdate command to update the name of the created folder to a new folder name and move the created folder to SentItems folder.
            this.CallFolderUpdateCommand(folderSyncResponse.ResponseData.SyncKey, folderCreateResponse.ResponseData.ServerId, folderNameToUpdate, Common.GetDefaultFolderServerId(folderSyncResponse, FolderType.SentItems, this.Site));
            #endregion

            #region Call FolderSync command to synchronize the folder hierarchy.
            folderSyncResponse = this.CallFolderSyncCommand();

            // Get the updated folder name using the ServerId returned in FolderSync response.
            string updatedFolderName = this.GetFolderFromFolderSyncResponse(folderSyncResponse, folderCreateResponse.ResponseData.ServerId, "DisplayName");
            string updatedParentId   = this.GetFolderFromFolderSyncResponse(folderSyncResponse, folderCreateResponse.ResponseData.ServerId, "ParentId");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R431");

            // Verify MS-ASHTTP requirement: MS-ASHTTP_R431
            // The folder name is updated to the specified name, so this requirement can be captured.
            Site.CaptureRequirementIfAreEqual <string>(
                folderNameToUpdate,
                updatedFolderName,
                431,
                @"[In Command Codes] [Command] FolderUpdate is used to rename folders.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R68");

            // Verify MS-ASHTTP requirement: MS-ASHTTP_R68
            // The folder has been moved to the new created folder, so this requirement can be captured.
            Site.CaptureRequirementIfAreEqual <string>(
                Common.GetDefaultFolderServerId(folderSyncResponse, FolderType.SentItems, this.Site),
                updatedParentId,
                68,
                @"[In Command Codes] [Command] FolderUpdate moves a folder from one location to another on the server.");
            #endregion

            #region Call FolderDelete to delete the folder from the server.
            this.CallFolderDeleteCommand(folderSyncResponse.ResponseData.SyncKey, folderCreateResponse.ResponseData.ServerId);
            #endregion

            #region Call FolderSync command to synchronize the folder hierarchy.
            folderSyncResponse = this.CallFolderSyncCommand();

            // Get the created folder name using the ServerId returned in FolderSync response.
            updatedFolderName = this.GetFolderFromFolderSyncResponse(folderSyncResponse, folderCreateResponse.ResponseData.ServerId, "DisplayName");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R496");

            // Verify MS-ASHTTP requirement: MS-ASHTTP_R496
            // The folder with the specified ServerId could not be got, so this requirement can be captured.
            Site.CaptureRequirementIfIsNull(
                updatedFolderName,
                496,
                @"[In Command Codes] [Command] FolderDelete deletes a folder from the server.");
            #endregion
        }
        /// <summary>
        /// Get ServerId from Sync response.
        /// </summary>
        /// <param name="syncResponse">The response of Sync command.</param>
        /// <param name="subject">The subject of the email to get.</param>
        /// <returns>The ServerId of the email.</returns>
        public static string GetServerIdFromSyncResponse(SyncStore syncResponse, string subject)
        {
            string itemServerId = null;
            foreach (SyncItem add in syncResponse.AddCommands)
            {
                if (add.Subject == subject)
                {
                    itemServerId = add.ServerId;
                    break;
                }
            }

            return itemServerId;
        }
        /// <summary>
        /// Load sync response to sync store.
        /// </summary>
        /// <param name="response">The response of Sync command.</param>
        /// <returns>The sync store instance.</returns>
        public static SyncStore LoadSyncResponse(ActiveSyncResponseBase<Response.Sync> response)
        {
            if (response.ResponseData.Item == null)
            {
                return null;
            }

            SyncStore result = new SyncStore();
            Response.SyncCollectionsCollection collection = ((Response.SyncCollections)response.ResponseData.Item).Collection[0];
            for (int i = 0; i < collection.ItemsElementName.Length; i++)
            {
                switch (collection.ItemsElementName[i])
                {
                    case Response.ItemsChoiceType10.CollectionId:
                        result.CollectionId = collection.Items[i].ToString();
                        break;
                    case Response.ItemsChoiceType10.SyncKey:
                        result.SyncKey = collection.Items[i].ToString();
                        break;
                    case Response.ItemsChoiceType10.Status:
                        result.Status = Convert.ToByte(collection.Items[i]);
                        break;
                    case Response.ItemsChoiceType10.Commands:
                        Response.SyncCollectionsCollectionCommands commands = collection.Items[i] as Response.SyncCollectionsCollectionCommands;
                        if (commands != null)
                        {
                            foreach (SyncItem item in LoadAddCommands(commands))
                            {
                                result.AddCommands.Add(item);
                            }
                        }

                        break;
                    case Response.ItemsChoiceType10.Responses:
                        Response.SyncCollectionsCollectionResponses responses = collection.Items[i] as Response.SyncCollectionsCollectionResponses;
                        if (responses != null)
                        {
                            if (responses.Add != null)
                            {
                                foreach (Response.SyncCollectionsCollectionResponsesAdd add in responses.Add)
                                {
                                    result.AddResponses.Add(add);
                                }
                            }
                        }

                        break;
                }
            }

            return result;
        }