static private CreateSyncRequest ( string syncKey, string collectionId, |
||
syncKey | string | Specify the sync key obtained from the last sync response(Refer to [MS-ASCMD]2.2.3.166.4) |
collectionId | string | Specify the server ID of the folder to be synchronized, which can be returned by ActiveSync FolderSync command(Refer to [MS-ASCMD]2.2.3.30.5) |
bodyPreference | Sets preference information related to the type and size of information for body (Refer to [MS-ASAIRS] 2.2.2.7) | |
return | SyncRequest |
/// <summary> /// Synchronize item with specified subject. /// </summary> /// <param name="subject">The subject of the item.</param> /// <param name="collectionId">The collection id which to sync with.</param> /// <param name="commands">The sync commands.</param> /// <param name="bodyPreferences">The bodyPreference in the options element.</param> /// <param name="bodyPartPreferences">The bodyPartPreference in the options element.</param> /// <returns>The item with specified subject.</returns> protected DataStructures.Sync GetSyncResult(string subject, string collectionId, object[] commands, Request.BodyPreference[] bodyPreferences, Request.BodyPartPreference[] bodyPartPreferences) { DataStructures.SyncStore syncStore; DataStructures.Sync item = null; SyncRequest request = TestSuiteHelper.CreateSyncRequest(this.GetInitialSyncKey(collectionId), collectionId, commands, bodyPreferences, bodyPartPreferences); int counter = 0; int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); int retryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); do { Thread.Sleep(waitTime); syncStore = this.ASAIRSAdapter.Sync(request); if (syncStore != null && syncStore.CollectionStatus == 1) { item = TestSuiteHelper.GetSyncAddItem(syncStore, subject); } counter++; }while ((syncStore == null || item == null) && counter < retryCount); this.Site.Assert.IsNotNull(item, "The email item with subject {0} should be found, retry count: {1}.", subject, counter); this.SyncKey = syncStore.SyncKey; return(item); }
/// <summary> /// Sync changes between client and server /// </summary> /// <param name="syncKey">The synchronization key returned by last request.</param> /// <param name="collectionId">Identify the folder as the collection being synchronized.</param> /// <param name="bodyPreference">Sets preference information related to the type and size of information for body</param> /// <returns>Return change result</returns> private SyncStore SyncChanges(string syncKey, string collectionId, Request.BodyPreference bodyPreference) { // Get changes from server use initial syncKey SyncRequest syncRequest = TestSuiteHelper.CreateSyncRequest(syncKey, collectionId, bodyPreference); SyncStore syncResult = this.ASAIRSAdapter.Sync(syncRequest); return(syncResult); }
/// <summary> /// Delete all the items in a folder. /// </summary> /// <param name="createdItemsCollection">The created items collection which should be deleted.</param> private void DeleteItemsInFolder(Collection <CreatedItems> createdItemsCollection) { foreach (CreatedItems createdItems in createdItemsCollection) { string syncKey = this.GetInitialSyncKey(createdItems.CollectionId); SyncRequest request = TestSuiteHelper.CreateSyncRequest(syncKey, createdItems.CollectionId, null, null, null); DataStructures.SyncStore result = this.ASAIRSAdapter.Sync(request); List <Request.SyncCollectionDelete> deleteData = new List <Request.SyncCollectionDelete>(); foreach (string subject in createdItems.ItemSubject) { string serverId = null; if (result != null) { foreach (DataStructures.Sync item in result.AddElements) { if (item.Email.Subject != null && item.Email.Subject.Equals(subject, StringComparison.CurrentCulture)) { serverId = item.ServerId; break; } if (item.Contact.FileAs != null && item.Contact.FileAs.Equals(subject, StringComparison.CurrentCulture)) { serverId = item.ServerId; break; } if (item.Calendar.Subject != null && item.Calendar.Subject.Equals(subject, StringComparison.CurrentCulture)) { serverId = item.ServerId; break; } } } this.Site.Assert.IsNotNull(serverId, "The item with subject '{0}' should be found!", subject); deleteData.Add(new Request.SyncCollectionDelete() { ServerId = serverId }); } Request.SyncCollection syncCollection = TestSuiteHelper.CreateSyncCollection(result.SyncKey, createdItems.CollectionId); syncCollection.Commands = deleteData.ToArray(); syncCollection.DeletesAsMoves = false; syncCollection.DeletesAsMovesSpecified = true; SyncRequest syncRequest = Common.CreateSyncRequest(new Request.SyncCollection[] { syncCollection }); DataStructures.SyncStore deleteResult = this.ASAIRSAdapter.Sync(syncRequest); this.Site.Assert.AreEqual <byte>( 1, deleteResult.CollectionStatus, "The value of Status should be 1 to indicate the Sync command executes successfully."); } }
/// <summary> /// Create a sync add request. /// </summary> /// <param name="syncKey">Specify the sync key obtained from the last sync response</param> /// <param name="collectionId">Specify the server ID of the folder to be synchronized, which can be returned by ActiveSync FolderSync command.</param> /// <param name="applicationData">Contains the data used to specify the Add element for Sync command.</param> /// <returns>Returns the SyncRequest instance.</returns> internal static SyncRequest CreateSyncAddRequest(string syncKey, string collectionId, Request.SyncCollectionAddApplicationData applicationData) { SyncRequest syncAddRequest = TestSuiteHelper.CreateSyncRequest(syncKey, collectionId, null); Request.SyncCollectionAdd add = new Request.SyncCollectionAdd { ClientId = GetClientId(), ApplicationData = applicationData }; List <object> commandList = new List <object> { add }; syncAddRequest.RequestData.Collections[0].Commands = commandList.ToArray(); return(syncAddRequest); }
public void MSASAIRS_S04_TC06_MultipleBodyPreferenceHaveSameTypeValue() { #region Send a plain text email string subject = Common.GenerateResourceName(Site, "Subject"); string body = Common.GenerateResourceName(Site, "Body"); this.SendEmail(EmailType.Plaintext, subject, body); // Make sure the email has reached the inbox folder of the recipient this.GetSyncResult(subject, this.User2Information.InboxCollectionId, null, null, null); #endregion #region Set two BodyPreference elements with same type value Request.BodyPreference[] bodyPreference = new Request.BodyPreference[] { new Request.BodyPreference() { Type = 1, TruncationSize = 100, TruncationSizeSpecified = true, AllOrNone = true, AllOrNoneSpecified = true }, new Request.BodyPreference() { Type = 1, TruncationSize = 100, TruncationSizeSpecified = true, AllOrNone = true, AllOrNoneSpecified = true } }; #endregion #region Verify multiple BodyPreference elements with same type value in Sync for related requirements SyncRequest request = TestSuiteHelper.CreateSyncRequest(this.GetInitialSyncKey(this.User2Information.InboxCollectionId), this.User2Information.InboxCollectionId, null, bodyPreference, null); if (Common.IsRequirementEnabled(10015, this.Site)) { try { this.ASAIRSAdapter.Sync(request); Site.Assert.Fail("The server should return an HTTP error 500 if multiple BodyPreference elements are present with the same value in the Type child element."); } catch (WebException exception) { int errorCode = ((HttpWebResponse)exception.Response).StatusCode.GetHashCode(); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASAIRS_R10015"); // Verify MS-ASAIRS requirement: MS-ASAIRS_R10015 Site.CaptureRequirementIfAreEqual <int>( 500, errorCode, 10015, @"[In Appendix B: Product Behavior] Implementation does return an HTTP error 500 instead of a Status value of 4 when multiple BodyPreference elements are present with the same value in the Type child element. (<1> Section 3.2.5.1: Exchange 2007 SP1 returns an HTTP error 500 instead of a Status value of 4 when multiple BodyPreference elements are present with the same value in the Type child element.)"); } } if (Common.IsRequirementEnabled(10016, this.Site)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(request.GetRequestDataSerializedXML()); SendStringResponse syncAddResponse = this.ASAIRSAdapter.Sync(doc.OuterXml); string status = this.GetStatusCodeFromXPath(syncAddResponse, "/a:Sync/a:Status"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASAIRS_R10016"); // Verify MS-ASAIRS requirement: MS-ASAIRS_R10016 Site.CaptureRequirementIfAreEqual( "4", status, 10016, @"[In Appendix B: Product Behavior] Implementation does return 4 (for Sync command) if multiple BodyPreference elements are present with the same value in the Type child element. (Exchange Server 2010 and above follow this behavior.)"); } #endregion }
public void MSASAIRS_S04_TC05_IncorrectPlacement() { #region Send a plain text email string subject = Common.GenerateResourceName(Site, "Subject"); string body = Common.GenerateResourceName(Site, "Body"); this.SendEmail(EmailType.Plaintext, subject, body); #endregion #region Set BodyPreference element Request.BodyPreference[] bodyPreference = new Request.BodyPreference[] { new Request.BodyPreference() { Type = 1, TruncationSize = 100, TruncationSizeSpecified = true, AllOrNone = true, AllOrNoneSpecified = true } }; #endregion #region Call ItemOperations command with incorrect placement of BodyPreference element. DataStructures.Sync syncItem = this.GetSyncResult(subject, this.User2Information.InboxCollectionId, null, bodyPreference, null); if (Common.IsRequirementEnabled(10032, this.Site)) { ItemOperationsRequest itemOperationRequest = TestSuiteHelper.CreateItemOperationsRequest(this.User2Information.InboxCollectionId, syncItem.ServerId, null, bodyPreference, null); XmlDocument doc = new XmlDocument(); doc.LoadXml(itemOperationRequest.GetRequestDataSerializedXML()); XmlNode bodyPreferenceNode = doc.SelectSingleNode("//*[name()='BodyPreference']"); // Add another BodyPreference element in the BodyPreference element, the placement is invalid. XmlNode temp = bodyPreferenceNode.Clone(); temp.SelectSingleNode("//*[name()='Type']").InnerText = "2"; bodyPreferenceNode.AppendChild(temp); SendStringResponse itemOperationResponse = this.ASAIRSAdapter.ItemOperations(doc.OuterXml); string status = this.GetStatusCodeFromXPath(itemOperationResponse, "/i:ItemOperations/i:Status"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASAIRS_R10032"); // Verify MS-ASAIRS requirement: MS-ASAIRS_R10032 Site.CaptureRequirementIfAreEqual( "2", status, 10032, @"[In Appendix B: Product Behavior] Implementation does return protocol status error 2 for an ItemOperations command (as specified in [MS-ASCMD] section 2.2.2.8), if an element does not meet the requirements[any of the XML elements specified in section 2.2.2 that are present in the command's XML body to ensure they comply with the requirements regarding placement] specified for that element, unless specified in the following table[section 3.2.5.1]. (Exchange Server 2007 SP1 and above follow this behavior.)"); } #endregion #region Call Search command with incorrect placement of BodyPreference element. if (Common.IsRequirementEnabled(10036, this.Site)) { SearchRequest searchRequest = TestSuiteHelper.CreateSearchRequest(subject, this.User2Information.InboxCollectionId, null, bodyPreference, null); XmlDocument doc = new XmlDocument(); doc.LoadXml(searchRequest.GetRequestDataSerializedXML()); XmlNode bodyPreferenceNode = doc.SelectSingleNode("//*[name()='BodyPreference']"); // Add another BodyPreference element in the BodyPreference element, the placement is invalid. XmlNode temp = bodyPreferenceNode.Clone(); temp.SelectSingleNode("//*[name()='Type']").InnerText = "2"; bodyPreferenceNode.AppendChild(temp); SendStringResponse searchResponse = this.ASAIRSAdapter.Search(doc.OuterXml); string searchStatus = this.GetStatusCodeFromXPath(searchResponse, "/s:Search/s:Status"); int retryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); int counter = 1; while (counter < retryCount && searchStatus.Equals("10")) { Thread.Sleep(waitTime); searchResponse = this.ASAIRSAdapter.Search(doc.OuterXml); searchStatus = this.GetStatusCodeFromXPath(searchResponse, "/s:Search/s:Status"); counter++; } string status = this.GetStatusCodeFromXPath(searchResponse, "/s:Search/s:Response/s:Store/s:Status"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASAIRS_R10036"); // Verify MS-ASAIRS requirement: MS-ASAIRS_R10036 Site.CaptureRequirementIfAreEqual( "2", status, 10036, @"[In Appendix B: Product Behavior] Implementation does return protocol status error 2 for a Search command (as specified in [MS-ASCMD] section 2.2.2.14), if an element does not meet the requirements[any of the XML elements specified in section 2.2.2 that are present in the command's XML body to ensure they comply with the requirements regarding placement] specified for that element, unless specified in the following table[section 3.2.5.1]. (Exchange Server 2007 SP1 and above follow this behavior.)"); } #endregion #region Call Sync add command with incorrect placement of Type element. if (Common.IsRequirementEnabled(10039, this.Site)) { SyncRequest syncAddRequest = TestSuiteHelper.CreateSyncRequest(this.GetInitialSyncKey(this.User2Information.InboxCollectionId), this.User2Information.InboxCollectionId, CreateSyncAddCommands(), null, null); XmlDocument doc = new XmlDocument(); doc.LoadXml(syncAddRequest.GetRequestDataSerializedXML()); XmlNode bodyNode = doc.SelectSingleNode("//*[name()='Body']"); // Add another body element in the body element, the placement is invalid. XmlNode temp = bodyNode.Clone(); temp.SelectSingleNode("//*[name()='Type']").InnerText = "2"; bodyNode.AppendChild(temp); SendStringResponse syncAddResponse = this.ASAIRSAdapter.Sync(doc.OuterXml); string status = this.GetStatusCodeFromXPath(syncAddResponse, "/a:Sync/a:Collections/a:Collection/a:Responses/a:Add/a:Status"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASAIRS_R10039"); // Verify MS-ASAIRS requirement: MS-ASAIRS_R10039 Site.CaptureRequirementIfAreEqual( "6", status, 10039, @"[In Appendix B: Product Behavior] Implementation does return protocol status error 6 for a Sync command (as specified in [MS-ASCMD] section 2.2.2.19), if an element does not meet the requirements[any of the XML elements specified in section 2.2.2 that are present in the command's XML body to ensure they comply with the requirements regarding placement] specified for that element, unless specified in the following table[section 3.2.5.1]. (Exchange Server 2007 SP1 and above follow this behavior.)"); } #endregion }
public void MSASAIRS_S04_TC01_Sync_Status4() { #region Send a plain text email string subject = Common.GenerateResourceName(Site, "Subject"); string body = Common.GenerateResourceName(Site, "Body"); this.SendEmail(EmailType.Plaintext, subject, body); // Make sure the email has reached the inbox folder of the recipient this.GetSyncResult(subject, this.User2Information.InboxCollectionId, null, null, null); #endregion #region Set BodyPreference element Request.BodyPreference[] bodyPreference = new Request.BodyPreference[] { new Request.BodyPreference() { Type = 1, TruncationSize = 100, TruncationSizeSpecified = true, AllOrNone = true, AllOrNoneSpecified = true } }; #endregion #region Call Sync command with incorrect order of child elements of BodyPreference SyncRequest request = TestSuiteHelper.CreateSyncRequest(this.GetInitialSyncKey(this.User2Information.InboxCollectionId), this.User2Information.InboxCollectionId, null, bodyPreference, null); XmlDocument doc = new XmlDocument(); doc.LoadXml(request.GetRequestDataSerializedXML()); XmlNode bodyPreferenceNode = doc.SelectSingleNode("//*[name()='BodyPreference']"); // Put the first node to the end. XmlNode temp = bodyPreferenceNode.ChildNodes[0]; bodyPreferenceNode.RemoveChild(temp); bodyPreferenceNode.AppendChild(temp); SendStringResponse response = this.ASAIRSAdapter.Sync(doc.OuterXml); string status = this.GetStatusCodeFromXPath(response, "/a:Sync/a:Status"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASAIRS_R348"); // Verify MS-ASAIRS requirement: MS-ASAIRS_R348 Site.CaptureRequirementIfAreEqual( "4", status, 348, @"[In Validating XML] If the child elements of BodyPreference (section 2.2.2.12) are not in the correct order, the server returns protocol status error 4 (for a Sync command)."); #endregion #region Call Sync command with a non-boolean value of AllOrNone element doc.LoadXml(request.GetRequestDataSerializedXML()); XmlNode allOrNoneNode = doc.SelectSingleNode("//*[name()='AllOrNone']"); // Set the AllOrNone element value to non-boolean. allOrNoneNode.InnerText = "a"; response = this.ASAIRSAdapter.Sync(doc.OuterXml); status = this.GetStatusCodeFromXPath(response, "/a:Sync/a:Status"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASAIRS_R350"); // Verify MS-ASAIRS requirement: MS-ASAIRS_R350 Site.CaptureRequirementIfAreEqual( "4", status, 350, @"[In Validating XML] If the AllOrNone (section 2.2.2.3.2) element is not of type boolean, the server returns protocol status error 4 (for Sync command)."); #endregion #region Call Sync command with multiple AllOrNone elements in a single BodyPreference element doc.LoadXml(request.GetRequestDataSerializedXML()); bodyPreferenceNode = doc.SelectSingleNode("//*[name()='BodyPreference']"); allOrNoneNode = doc.SelectSingleNode("//*[name()='AllOrNone']"); temp = allOrNoneNode.Clone(); bodyPreferenceNode.AppendChild(temp); response = this.ASAIRSAdapter.Sync(doc.OuterXml); status = this.GetStatusCodeFromXPath(response, "/a:Sync/a:Status"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASAIRS_R351"); // Verify MS-ASAIRS requirement: MS-ASAIRS_R351 Site.CaptureRequirementIfAreEqual( "4", status, 351, @"[In Validating XML] If multiple AllOrNone elements are in a single BodyPreference element, the server returns protocol status error 4 (for Sync command)."); #endregion }