/// <summary>
        /// Call Sync command to delete items.
        /// </summary>
        /// <param name="collectionId">The CollectionId of the folder.</param>
        /// <param name="syncKey">The latest SyncKey.</param>
        /// <param name="serverIds">The ServerId of the items to delete.</param>
        /// <returns>The SyncStore instance returned from Sync command.</returns>
        protected SyncStore SyncDelete(string collectionId, string syncKey, string[] serverIds)
        {
            List <Request.SyncCollectionDelete> deleteCollection = new List <Request.SyncCollectionDelete>();

            foreach (string itemId in serverIds)
            {
                Request.SyncCollectionDelete delete = new Request.SyncCollectionDelete {
                    ServerId = itemId
                };
                deleteCollection.Add(delete);
            }

            Request.SyncCollection collection = new Request.SyncCollection
            {
                Commands                = deleteCollection.ToArray(),
                DeletesAsMoves          = true,
                DeletesAsMovesSpecified = true,
                CollectionId            = collectionId,
                SyncKey = syncKey
            };

            SyncRequest syncRequest = Common.CreateSyncRequest(new Request.SyncCollection[] { collection });

            SyncStore syncStore = this.CONAdapter.Sync(syncRequest);

            // Verify Sync command response.
            Site.Assert.AreEqual <byte>(
                1,
                syncStore.CollectionStatus,
                "If the Sync command executes successfully, the Status in response should be 1.");

            return(syncStore);
        }
Beispiel #2
0
        /// <summary>
        /// Call Sync command to delete a task.
        /// </summary>
        /// <param name="syncKey">The sync key.</param>
        /// <param name="serverId">The server id of the task, which is returned by server.</param>
        /// <returns>Return the sync delete result.</returns>
        protected SyncStore SyncDeleteTask(string syncKey, string serverId)
        {
            List <object> deleteData = new List <object>();

            Request.SyncCollectionDelete delete = new Request.SyncCollectionDelete {
                ServerId = serverId
            };
            deleteData.Add(delete);

            SyncRequest syncRequest  = TestSuiteHelper.CreateSyncRequest(syncKey, this.UserInformation.TasksCollectionId, deleteData);
            SyncStore   syncResponse = this.TASKAdapter.Sync(syncRequest);

            return(syncResponse);
        }
        /// <summary>
        /// Create a Sync delete operation request which would be used to delete items permanently.
        /// </summary>
        /// <param name="syncKey">The synchronization state of a collection.</param>
        /// <param name="collectionId">The server ID of the folder.</param>
        /// <param name="serverId">The server ID of the item which will be deleted.</param>
        /// <returns>The Sync delete operation request.</returns>
        protected static SyncRequest CreateSyncPermanentDeleteRequest(string syncKey, string collectionId, string serverId)
        {
            Request.SyncCollection syncCollection = new Request.SyncCollection
            {
                SyncKey = syncKey,
                CollectionId = collectionId,
                WindowSize = "100",
                DeletesAsMoves = false,
                DeletesAsMovesSpecified = true
            };

            Request.SyncCollectionDelete deleteData = new Request.SyncCollectionDelete { ServerId = serverId };

            syncCollection.Commands = new object[] { deleteData };

            return Common.CreateSyncRequest(new Request.SyncCollection[] { syncCollection });
        }
        /// <summary>
        /// Builds a Sync delete request by using the specified sync key, folder collection ID, item serverID and deletesAsMoves option.
        /// In general, returns the XML formatted Sync request as follows:
        /// <!--
        /// <?xml version="1.0" encoding="utf-8"?>
        /// <Sync xmlns="AirSync">
        ///   <Collections>
        ///     <Collection>
        ///       <SyncKey>0</SyncKey>
        ///       <CollectionId>5</CollectionId>
        ///       <GetChanges>1</GetChanges>
        ///       <DeletesAsMoves>1</DeletesAsMoves>
        ///       <WindowSize>100</WindowSize>
        ///       <Commands>
        ///         <Delete>
        ///           <ServerId>5:1</ServerId>
        ///         </Delete>
        ///       </Commands>
        ///     </Collection>
        ///   </Collections>
        /// </Sync>
        /// -->
        /// </summary>
        /// <param name="collectionId">Specify the serverId of the folder to be synchronized, which can be returned by ActiveSync FolderSync command(Refer to [MS-ASCMD]2.2.3.30.5)</param>
        /// <param name="syncKey">Specify the sync key obtained from the last sync response(Refer to [MS-ASCMD]2.2.3.166.4)</param>
        /// <param name="serverId">Specify a unique identifier that was assigned by the server for a mailItem, which can be returned by ActiveSync Sync command</param>
        /// <returns>Returns the SyncRequest instance</returns>
        internal static SyncRequest CreateSyncDeleteRequest(string collectionId, string syncKey, string serverId)
        {
            Request.SyncCollection syncCollection = new Request.SyncCollection
            {
                SyncKey                 = syncKey,
                CollectionId            = collectionId,
                WindowSize              = "100",
                DeletesAsMoves          = false,
                DeletesAsMovesSpecified = true
            };

            Request.SyncCollectionDelete deleteData = new Request.SyncCollectionDelete {
                ServerId = serverId
            };

            syncCollection.Commands = new object[] { deleteData };

            return(Common.CreateSyncRequest(new Request.SyncCollection[] { syncCollection }));
        }
Beispiel #5
0
        /// <summary>
        /// Delete the specified item.
        /// </summary>
        /// <param name="itemsToDelete">The collection of the items to delete.</param>
        private void DeleteCreatedItems(Collection <CreatedItems> itemsToDelete)
        {
            foreach (CreatedItems itemToDelete in itemsToDelete)
            {
                SyncRequest syncRequest = Common.CreateInitialSyncRequest(itemToDelete.CollectionId);
                DataStructures.SyncStore initSyncResult = this.ASRMAdapter.Sync(syncRequest);
                DataStructures.SyncStore result         = this.SyncChanges(initSyncResult.SyncKey, itemToDelete.CollectionId, false);
                int i = 0;
                if (result.AddElements != null)
                {
                    Request.SyncCollectionDelete[] deletes = new Request.SyncCollectionDelete[result.AddElements.Count];
                    foreach (DataStructures.Sync item in result.AddElements)
                    {
                        foreach (string subject in itemToDelete.ItemSubject)
                        {
                            if (item.Email.Subject.Equals(subject))
                            {
                                Request.SyncCollectionDelete delete = new Request.SyncCollectionDelete
                                {
                                    ServerId = item.ServerId
                                };
                                deletes[i] = delete;
                            }
                        }

                        i++;
                    }

                    Request.SyncCollection syncCollection = TestSuiteHelper.CreateSyncCollection(result.SyncKey, itemToDelete.CollectionId);
                    syncCollection.Commands = deletes;

                    syncRequest = Common.CreateSyncRequest(new Request.SyncCollection[] { syncCollection });
                    DataStructures.SyncStore deleteResult = this.ASRMAdapter.Sync(syncRequest);
                    this.Site.Assert.AreEqual <byte>(
                        1,
                        deleteResult.CollectionStatus,
                        "The value of 'Status' should be 1 which indicates the Sync command executes successfully.");
                }
            }
        }
        /// <summary>
        /// Call Sync command to delete a task.
        /// </summary>
        /// <param name="syncKey">The sync key.</param>
        /// <param name="serverId">The server id of the task, which is returned by server.</param>
        /// <returns>Return the sync delete result.</returns>
        protected SyncStore SyncDeleteTask(string syncKey, string serverId)
        {
            List<object> deleteData = new List<object>();
            Request.SyncCollectionDelete delete = new Request.SyncCollectionDelete { ServerId = serverId };
            deleteData.Add(delete);

            SyncRequest syncRequest = TestSuiteHelper.CreateSyncRequest(syncKey, this.UserInformation.TasksCollectionId, deleteData);
            SyncStore syncResponse = this.TASKAdapter.Sync(syncRequest);

            return syncResponse;
        }
        /// <summary>
        /// Delete the specified item.
        /// </summary>
        /// <param name="itemsToDelete">The collection of the items to delete.</param>
        private void DeleteCreatedItems(Collection<CreatedItems> itemsToDelete)
        {
            foreach (CreatedItems itemToDelete in itemsToDelete)
            {
                SyncRequest syncRequest = Common.CreateInitialSyncRequest(itemToDelete.CollectionId);
                DataStructures.SyncStore initSyncResult = this.ASRMAdapter.Sync(syncRequest);
                DataStructures.SyncStore result = this.SyncChanges(initSyncResult.SyncKey, itemToDelete.CollectionId, false);
                int i = 0;
                if (result.AddElements != null)
                {
                    Request.SyncCollectionDelete[] deletes = new Request.SyncCollectionDelete[result.AddElements.Count];
                    foreach (DataStructures.Sync item in result.AddElements)
                    {
                        foreach (string subject in itemToDelete.ItemSubject)
                        {
                            if (item.Email.Subject.Equals(subject))
                            {
                                Request.SyncCollectionDelete delete = new Request.SyncCollectionDelete
                                {
                                    ServerId = item.ServerId
                                };
                                deletes[i] = delete;
                            }
                        }

                        i++;
                    }

                    Request.SyncCollection syncCollection = TestSuiteHelper.CreateSyncCollection(result.SyncKey, itemToDelete.CollectionId);
                    syncCollection.Commands = deletes;

                    syncRequest = Common.CreateSyncRequest(new Request.SyncCollection[] { syncCollection });
                    DataStructures.SyncStore deleteResult = this.ASRMAdapter.Sync(syncRequest);
                    this.Site.Assert.AreEqual<byte>(
                        1,
                        deleteResult.CollectionStatus,
                        "The value of 'Status' should be 1 which indicates the Sync command executes successfully.");
                }
            }
        }
        /// <summary>
        /// Delete the specified item.
        /// </summary>
        /// <param name="itemsToDelete">The collection of the items to delete.</param>
        private void DeleteCreatedItems(Collection<CreatedItems> itemsToDelete)
        {
            foreach (CreatedItems itemToDelete in itemsToDelete)
            {
                SyncStore syncResponse = this.CallSyncCommand(itemToDelete.CollectionId);
                Site.Assert.AreNotEqual<int>(0, syncResponse.AddCommands.Count, "There is not items added in {0} folder.", itemToDelete.CollectionId);
                List<Request.SyncCollectionDelete> deleteList = new List<Request.SyncCollectionDelete>();
                foreach (string itemSubject in itemToDelete.ItemSubject)
                {
                    Request.SyncCollectionDelete appData = new Request.SyncCollectionDelete
                    {
                        ServerId = TestSuiteHelper.GetServerIdFromSyncResponse(syncResponse, itemSubject)
                    };

                    Site.Assert.IsNotNull(appData.ServerId, "The item with subject {0} in {1} folder is not found.", itemSubject, itemToDelete.CollectionId);
                    deleteList.Add(appData);
                }

                // Create the Sync command request.
                Request.SyncCollection[] syncCollections = new Request.SyncCollection[1];
                syncCollections[0] = new Request.SyncCollection
                {
                    CollectionId = itemToDelete.CollectionId,
                    SyncKey = syncResponse.SyncKey,
                    Commands = deleteList.ToArray(),
                    DeletesAsMoves = false,
                    DeletesAsMovesSpecified = true
                };
                SyncRequest syncRequest = Common.CreateSyncRequest(syncCollections);

                // Call Sync command to delete the specified item.
                SendStringResponse syncResponseString = this.HTTPAdapter.HTTPPOST(CommandName.Sync, null, syncRequest.GetRequestDataSerializedXML());

                // Check the command is executed successfully.
                this.CheckResponseStatus(syncResponseString.ResponseDataXML);
            }
        }
        /// <summary>
        /// Delete all the user created items
        /// </summary>
        /// <param name="userInformation">The user information which contains user created items</param>
        private void DeleteItemsInFolder(UserInformation userInformation)
        {
            foreach (CreatedItems userItem in userInformation.UserCreatedItems)
            {
                SyncRequest emptySyncRequest = TestSuiteBase.CreateEmptySyncRequest(userItem.CollectionId);
                SyncResponse emptySyncResult = this.Sync(emptySyncRequest);
                SyncStore emptySyncResponse = Common.LoadSyncResponse(emptySyncResult);
                int retryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site));
                int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site));
                int counter = 0;

                do
                {
                    Thread.Sleep(waitTime);

                    emptySyncResult = this.Sync(emptySyncRequest);
                    emptySyncResponse = Common.LoadSyncResponse(emptySyncResult);
                    if (emptySyncResponse != null)
                    {
                        if (emptySyncResponse.CollectionStatus == 1)
                        {
                            break;
                        }
                    }

                    counter++;
                }
                while (counter < retryCount / 10);

                if (emptySyncResponse.AddElements != null)
                {
                    SyncRequest deleteRequest;
                    foreach (SyncItem item in emptySyncResponse.AddElements)
                    {
                        deleteRequest = CreateSyncPermanentDeleteRequest(emptySyncResponse.SyncKey, userItem.CollectionId, item.ServerId);
                        SyncResponse resultDelete = this.Sync(deleteRequest);
                        SyncStore deleteResult = Common.LoadSyncResponse(resultDelete);
                        Site.Assert.AreEqual<byte>(1, deleteResult.CollectionStatus, "Item should be deleted.");
                    }
                }

                SyncResponse result = this.SyncChanges(userItem.CollectionId);
                string syncKey = this.LastSyncKey;
                if (result.ResponseData != null && result.ResponseData.Item != null)
                {
                    List<Request.SyncCollectionDelete> deleteData = new List<Request.SyncCollectionDelete>();
                    foreach (string subject in userItem.ItemSubject)
                    {
                        if (userItem.CollectionId == userInformation.ContactsCollectionId)
                        {
                            foreach (string itemServerID in TestSuiteBase.FindServerIdList(result, "FileAs", subject))
                            {
                                Request.SyncCollectionDelete deleteItem = new Request.SyncCollectionDelete
                                {
                                    ServerId = itemServerID
                                };

                                deleteData.Add(deleteItem);
                            }
                        }
                        else
                        {
                            foreach (string itemServerID in TestSuiteBase.FindServerIdList(result, "Subject", subject))
                            {
                                Request.SyncCollectionDelete deleteItem = new Request.SyncCollectionDelete
                                {
                                    ServerId = itemServerID
                                };

                                deleteData.Add(deleteItem);
                            }
                        }
                    }

                    if (deleteData.Count > 0)
                    {
                        Request.SyncCollection syncCollection = new Request.SyncCollection
                        {
                            SyncKey = syncKey,
                            GetChanges = true,
                            GetChangesSpecified = true,
                            CollectionId = userItem.CollectionId,
                            Commands = deleteData.ToArray(),
                            DeletesAsMoves = false,
                            DeletesAsMovesSpecified = true
                        };

                        SyncRequest syncRequest = Common.CreateSyncRequest(new Request.SyncCollection[] { syncCollection });
                        SyncResponse deleteResult = this.Sync(syncRequest);
                        string deleteResultStatus = this.GetStatusCode(deleteResult.ResponseDataXML);

                        Site.Assert.AreEqual<string>(
                            "1",
                            deleteResultStatus,
                            "The value of 'Status' should be 1 which indicates the Sync command executes successfully.",
                            deleteResultStatus);
                    }
                }
            }
        }
        public void MSASCMD_S19_TC48_Sync_Collection_LimitValue()
        {
            Site.Assume.IsTrue(Common.IsRequirementEnabled(5671, this.Site) || Common.IsRequirementEnabled(5673, this.Site), "Update Rollup 6 for Exchange 2010 SP2 and Exchange 2013 use the specified limit values by default.");

            #region Create 51 Add elements, 50 Change elements, 50 Delete elements and 50 Fetch elements for the Commands element of Sync command.
            this.Sync(TestSuiteBase.CreateEmptySyncRequest(this.User1Information.ContactsCollectionId));

            List<object> commands = new List<object>();

            for (int i = 0; i < 50; i++)
            {
                string contactFileAS = Common.GenerateResourceName(Site, "FileAS");
                Request.SyncCollectionAdd addData = this.CreateAddContactCommand("FirstName", "MiddleName", "LastName", contactFileAS, null);
                commands.Add(addData);

                string serverId = this.User1Information.ContactsCollectionId + ":" + Guid.NewGuid().ToString();
                string updatedContactFileAS = Common.GenerateResourceName(Site, "UpdatedFileAS");
                Request.SyncCollectionChange changeData = CreateChangedContact(serverId, new Request.ItemsChoiceType7[] { Request.ItemsChoiceType7.FileAs }, new object[] { updatedContactFileAS });
                commands.Add(changeData);

                Request.SyncCollectionDelete deleteData = new Request.SyncCollectionDelete { ServerId = serverId };
                commands.Add(deleteData);

                Request.SyncCollectionFetch fetchData = new Request.SyncCollectionFetch { ServerId = serverId };
                commands.Add(fetchData);
            }

            string contactFileASFor51Add = Common.GenerateResourceName(Site, "FileAS");
            Request.SyncCollectionAdd addDataFor51Add = this.CreateAddContactCommand("FirstName", "MiddleName", "LastName", contactFileASFor51Add, null);
            commands.Add(addDataFor51Add);
            #endregion

            #region Call Sync command on the Contacts folder
            Request.SyncCollection collection = new Request.SyncCollection
            {
                SyncKey = this.LastSyncKey,
                GetChanges = true,
                CollectionId = this.User1Information.ContactsCollectionId,
                Commands = commands.ToArray()
            };

            SyncRequest syncRequest = Common.CreateSyncRequest(new Request.SyncCollection[] { collection });
            SyncResponse syncResponse = this.Sync(syncRequest);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R5659
            Site.CaptureRequirementIfAreEqual<int>(
                4,
                int.Parse(syncResponse.ResponseData.Status),
                5659,
                @"[In Limiting Size of Command Requests] In Sync (section 2.2.2.19) command request, when the limit value of Add, Change, Delete and Fetch elements is bigger than 200 (minimum 1, maximum 2,147,483,647), the error returned by server is Status element (section 2.2.3.162.16) value of 4.");
            #endregion
        }
        public void MSASCMD_S19_TC35_Sync_DeletesAsMovesIsFalse()
        {
            #region Send a MIME-formatted email to User2.
            string emailSubject = Common.GenerateResourceName(Site, "subject");
            this.SendPlainTextEmail(null, emailSubject, this.User1Information.UserName, this.User2Information.UserName, null);
            #endregion

            this.SwitchUser(this.User2Information);
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject);

            SyncResponse syncResponse = this.SyncChanges(this.User2Information.DeletedItemsCollectionId);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject), "The email should not be found in the DeletedItems folder.");

            syncResponse = this.GetMailItem(this.User2Information.InboxCollectionId, emailSubject);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            string serverId = TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject);
            Site.Assert.IsTrue(!string.IsNullOrEmpty(serverId), "The email should be found in the Inbox folder.");

            #region Delete the added email item.
            Request.SyncCollectionDelete appDataDelete = new Request.SyncCollectionDelete { ServerId = serverId };

            Request.SyncCollection collection = new Request.SyncCollection
            {
                SyncKey = this.LastSyncKey,
                GetChanges = true,
                CollectionId = this.User2Information.InboxCollectionId,
                Commands = new object[] { appDataDelete },
                DeletesAsMoves = false,
                DeletesAsMovesSpecified = true
            };

            Request.Sync syncRequestData = new Request.Sync { Collections = new Request.SyncCollection[] { collection } };

            SyncRequest syncRequestDelete = new SyncRequest { RequestData = syncRequestData };
            this.Sync(syncRequestDelete);
            #endregion

            #region Verify if the email has been deleted from the Inbox folder and not placed into the DeletedItems folder.
            syncResponse = this.SyncChanges(this.User2Information.InboxCollectionId);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject), "The email deleted should not be found in the Inbox folder.");
            TestSuiteBase.RemoveRecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject);

            syncResponse = this.SyncChanges(this.User2Information.DeletedItemsCollectionId);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject), "The email deleted should not be found in the DeletedItems folder.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R2158
            // If the deleted email can not be found in both Inbox and Deleted Items folder, this requirement can be captured directly.
            Site.CaptureRequirement(
                2158,
                @"[In DeletesAsMoves] If the DeletesAsMoves element is set to false, the deletion is permanent.");
            #endregion
        }