/// <summary> /// Load the SearchStore from the SearchResponse /// </summary> /// <param name="search">The returned Search response.</param> /// <returns>A SearchStore instance</returns> public static DataStructures.SearchStore LoadSearchResponse(SearchResponse search) { DataStructures.SearchStore searchStore = new DataStructures.SearchStore(); if (search.ResponseData.Status != null) { searchStore.Status = search.ResponseData.Status; if (!searchStore.Status.Equals("1")) { return searchStore; } } searchStore.StoreStatus = search.ResponseData.Response.Store.Status; if (!searchStore.StoreStatus.Equals("1")) { return searchStore; } searchStore.Range = search.ResponseData.Response.Store.Range; if (!string.IsNullOrEmpty(search.ResponseData.Response.Store.Total)) { searchStore.Total = Convert.ToInt32(search.ResponseData.Response.Store.Total, CultureInfo.InvariantCulture); } if (search.ResponseData.Response.Store.Result == null) { return searchStore; } if (search.ResponseData.Response.Store.Result.Length == 1 && search.ResponseData.Response.Store.Result[0].CollectionId == null) { return searchStore; } foreach (Response.SearchResponseStoreResult result in search.ResponseData.Response.Store.Result) { DataStructures.Search searchResult = new DataStructures.Search { LongId = result.LongId, Class = result.Class, CollectionId = result.CollectionId, Note = DataStructures.Note.DeserializeFromSearchProperties<DataStructures.Note>(result.Properties), Calendar = DataStructures.Calendar.DeserializeFromSearchProperties<DataStructures.Calendar>(result.Properties), Contact = DataStructures.Contact.DeserializeFromSearchProperties<DataStructures.Contact>(result.Properties), Email = DataStructures.Email.DeserializeFromSearchProperties<DataStructures.Email>(result.Properties), Task = DataStructures.Task.DeserializeFromSearchProperties<DataStructures.Task>(result.Properties) }; searchStore.Results.Add(searchResult); } return searchStore; }
/// <summary> /// Get elements from Search command response. /// </summary> /// <param name="searchResponse">The Search command response.</param> /// <param name="elementType">The element type need to get.</param> /// <returns>The element object list.</returns> private static List<object> GetElementsFromSearchResponse(SearchResponse searchResponse, Response.ItemsChoiceType6 elementType) { List<object> element = new List<object>(); foreach (Response.SearchResponseStoreResult result in searchResponse.ResponseData.Response.Store.Result) { for (int itemIndex = 0; itemIndex < result.Properties.ItemsElementName.Length; itemIndex++) { if (result.Properties.ItemsElementName[itemIndex] == elementType) { element.Add(result.Properties.Items[itemIndex]); } } } return element; }
/// <summary> /// Verify the Search operation. /// </summary> /// <param name="response">The response of the Search operation.</param> private void VerifySearch(SearchResponse response) { // Only verify the adapter capture code when response is successful. if (string.Equals(response.ResponseData.Response.Store.Status, "1")) { Site.Assert.IsTrue(this.activeSyncClient.ValidationResult, "Schema should be verified successfully."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R110"); // Verify MS-ASDOC requirement: MS-ASDOC_R110 Site.CaptureRequirementIfIsNotNull( response.ResponseData, 110, @"[In Search Command Response] When a client uses the Search command request ([MS-ASCMD] section 2.2.2.14) to retrieve Document class items that match the criteria specified by the client, as specified in section 3.1.5.2, the server responds with a Search command response."); foreach (Microsoft.Protocols.TestSuites.Common.Response.SearchResponseStoreResult result in response.ResponseData.Response.Store.Result) { string linkId = null; DateTime? lastModifiedDate = null; DateTime? creationDate = null; string displayName = null; byte? isFolder = null; byte? isHidden = null; string contentLength = null; string contentType = null; for (int i = 0; i < result.Properties.ItemsElementName.Length; i++) { if (result.Properties.ItemsElementName[i] == Response.ItemsChoiceType6.LinkId) { linkId = (string)result.Properties.Items[i]; } if (result.Properties.ItemsElementName[i] == Response.ItemsChoiceType6.CreationDate) { creationDate = (DateTime)result.Properties.Items[i]; } if (result.Properties.ItemsElementName[i] == Response.ItemsChoiceType6.LastModifiedDate) { lastModifiedDate = (DateTime)result.Properties.Items[i]; } if (result.Properties.ItemsElementName[i] == Response.ItemsChoiceType6.DisplayName) { displayName = (string)result.Properties.Items[i]; } if (result.Properties.ItemsElementName[i] == Response.ItemsChoiceType6.IsHidden) { isHidden = (byte)result.Properties.Items[i]; } if (result.Properties.ItemsElementName[i] == Response.ItemsChoiceType6.IsFolder) { isFolder = (byte)result.Properties.Items[i]; } if (result.Properties.ItemsElementName[i] == Response.ItemsChoiceType6.ContentLength) { contentLength = (string)result.Properties.Items[i]; } if (result.Properties.ItemsElementName[i] == Response.ItemsChoiceType6.ContentType) { contentType = (string)result.Properties.Items[i]; } } // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R15"); // Verify MS-ASDTYPE requirement: MS-ASDTYPE_R15 bool isVerifyR15 = null != lastModifiedDate && null != creationDate; Site.CaptureRequirementIfIsTrue( isVerifyR15, "MS-ASDTYPE", 15, @"[In dateTime Data Type] All dates are given in Coordinated Universal Time (UTC) and are represented as a string in the following format. YYYY-MM-DDTHH:MM:SS.MSSZ where YYYY = Year (Gregorian calendar year) MM = Month (01 - 12) DD = Day (01 - 31) HH = Number of complete hours since midnight (00 - 24) MM = Number of complete minutes since start of hour (00 - 59) SS = Number of seconds since start of minute (00 - 59) MSS = Number of milliseconds"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R16"); // Since schema is validated, this requirement can be captured directly. Site.CaptureRequirement( "MS-ASDTYPE", 16, @"[In dateTime Data Type][in YYYY-MM-DDTHH:MM:SS.MSSZ ] The T serves as a separator, and the Z indicates that this time is in UTC."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R36"); // Verify MS-ASDOC requirement: MS-ASDOC_R36 Site.CaptureRequirementIfIsNotNull( creationDate, 36, @"[In CreationDate] The CreationDate element is a required child element of the search:Properties element ([MS-ASCMD] section 2.2.3.128.2) for Document class items in a Search command response ([MS-ASCMD] section 2.2.2.14) that specifies the date and time when the document or folder was created."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R39"); // Verify MS-ASDOC requirement: MS-ASDOC_R39 Site.CaptureRequirementIfIsNotNull( displayName, 39, @"[In DisplayName] The DisplayName element is a required child element of the search:Properties element ([MS-ASCMD] section 2.2.3.128.2) for Document class items in a Search command response ([MS-ASCMD] section 2.2.2.14) that specifies the name of the document or folder as it is displayed to the user."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R41"); // If the element is returned and schema validation is successful, this requirement can be verified. Site.CaptureRequirement( 41, @"[In DisplayName] The value of this element[DisplayName] is a string data type, as specified in [MS-ASDTYPE] section 2.6."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R94"); // Since schema is validated, this requirement can be captured directly. Site.CaptureRequirement( "MS-ASDTYPE", 94, @"[In string Data Type] Elements of these types [ActiveSync defines several conventions for strings that adhere to commonly used formats] Are defined as string types in XML schemas."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R48"); // Verify MS-ASDOC requirement: MS-ASDOC_R48 Site.CaptureRequirementIfIsNotNull( isHidden, 48, @"[In IsHidden] The IsHidden element is a required child element of the search:Properties element ([MS-ASCMD] section 2.2.3.128.2) for Document class items in a Search command response ([MS-ASCMD] section 2.2.2.14) that specifies whether the document or folder is a hidden object."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R50"); // If the element is returned and schema validation is successful, this requirement can be verified. Site.CaptureRequirement( 50, @"[In IsHidden] The value of this element[IsHidden] is an unsignedByte data type, as specified in [MS-ASDTYPE] section 2.7."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R45, the value of IsFolder is {0}", isFolder); // Verify MS-ASDOC requirement: MS-ASDOC_R45 bool isVerifyR45 = (byte)isFolder == 0 || (byte)isFolder == 1; Site.CaptureRequirementIfIsTrue( isVerifyR45, 45, @"[In IsFolder] Valid values for this element are as follows[0,1]."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R42"); // Verify MS-ASDOC requirement: MS-ASDOC_R42 Site.CaptureRequirementIfIsNotNull( isFolder, 42, @"[In IsFolder] The IsFolder element is a required child element of the search:Properties element ([MS-ASCMD] section 2.2.3.128.2) for Document class items in a Search command response ([MS-ASCMD] section 2.2.2.14) that specifies whether the item is a folder."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R44"); // If the element is returned and schema validation is successful, this requirement can be verified. Site.CaptureRequirement( 44, @"[In IsFolder] The value of this element[IsFolder] is an unsignedByte data type, as specified in [MS-ASDTYPE] section 2."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R51, the value of IsHidden is {0}", isHidden); // Verify MS-ASDOC requirement: MS-ASDOC_R51 bool isVerifyR51 = (byte)isHidden == 0 || (byte)isHidden == 1; Site.CaptureRequirementIfIsTrue( isVerifyR51, 51, @"[In IsHidden] The value of the IsHidden element MUST be one of the following values[0,1]."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R54"); // Verify MS-ASDOC requirement: MS-ASDOC_R54 Site.CaptureRequirementIfIsNotNull( lastModifiedDate, 54, @"[In LastModifiedDate] The LastModifiedDate element is a required child element of the search:Properties element ([MS-ASCMD] section 2.2.3.128.2) for Document class items in a Search command response ([MS-ASCMD] section 2.2.2.14) that specifies the date and time that the document, or the folder, or the properties of either the document or folder were was last modified."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R123"); // Verify MS-ASDOC requirement: MS-ASDOC_R123 Site.CaptureRequirementIfIsNotNull( linkId, 123, @"[In LinkId] It[LinkId] is a required child element of the search:Properties element ([MS-ASCMD] section 2.2.3.128.2) for Document class items in a Search command response."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R114"); // Verify MS-ASDOC requirement: MS-ASDOC_R114 Site.CaptureRequirementIfIsNotNull( result.Properties, 114, @"[In Search Command Response] Document class elements are returned as child elements of the search:Properties element ([MS-ASCMD] section 2.2.3.128) in a Search command response."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R38,the value of CreationDate is:{0}", creationDate); // Verify MS-ASDOC requirement: MS-ASDOC_R38 Site.CaptureRequirementIfIsNotNull( creationDate, 38, @"[In CreationDate] The value of this element[CreationDate] is a datetime data type in Coordinated Universal Time (UTC) format, as specified in [MS-ASDTYPE] section 2.3."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R56, the value of LastModifiedDate is:{0}", lastModifiedDate); // Verify MS-ASDOC requirement: MS-ASDOC_R56 Site.CaptureRequirementIfIsNotNull( lastModifiedDate, 56, @"[In LastModifiedDate] The value of this element[LastModifiedDate] is a datetime data type in UTC format, as specified in [MS-ASDTYPE] section 2.3."); if (null != contentLength) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R31"); // If the schema is verified successfully, this requirement can be covered. Site.CaptureRequirement( 31, @"[In ContentLength] The value of this element[ContentLength] is an integer data type, as specified in[MS-ASDTYPE] section 2.5."); } if (null != contentType) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R35"); // If the schema is verified successfully, this requirement can be covered. Site.CaptureRequirement( 35, @"[In ContentType] The value of this element[ContentType] is a string data type, as specified in [MS-ASDTYPE] section 2.6."); } } // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R12"); // If the schema is verified successfully, this requirement can be covered. Site.CaptureRequirement( "MS-ASDTYPE", 12, @"[In dateTime Data Type] It [dateTime]is declared as an element whose type attribute is set to ""dateTime""."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R20"); // ActiveSyncClient encoded dateTime data as inline strings, so if response is successfully returned this requirement can be verified. // Verify MS-ASDTYPE requirement: MS-ASDTYPE_R20 Site.CaptureRequirement( "MS-ASDTYPE", 20, @"[In dateTime Data Type] Elements with a dateTime data type MUST be encoded and transmitted as [WBXML1.2] inline strings."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R87"); // ActiveSyncClient encoded integer data as inline strings, so if response is successfully returned this requirement can be covered. // Verify MS-ASDTYPE requirement: MS-ASDTYPE_R87 Site.CaptureRequirement( "MS-ASDTYPE", 87, @"[In integer Data Type] Elements with an integer data type MUST be encoded and transmitted as WBXML inline strings, as specified in [WBXML1.2]."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R88"); // If the schema is verified successfully, this requirement can be covered. Site.CaptureRequirement( "MS-ASDTYPE", 88, @"[In string Data Type] A string is a chunk of Unicode text."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R90"); // If the schema is verified successfully, this requirement can be covered. Site.CaptureRequirement( "MS-ASDTYPE", 90, @"[In string Data Type] An element of this[string] type is declared as an element with a type attribute of ""string""."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R91"); // ActiveSyncClient encoded string data as inline strings, so if response is successfully returned this requirement can be covered. // Verify MS-ASDTYPE requirement: MS-ASDTYPE_R91 Site.CaptureRequirement( "MS-ASDTYPE", 91, @"[In string Data Type] Elements with a string data type MUST be encoded and transmitted as [WBXML1.2] inline strings."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R97"); // If the schema is verified successfully, this requirement can be covered. Site.CaptureRequirement( "MS-ASDTYPE", 97, @"[In Byte Array] The structure is comprised of a length, which is expressed as a multi-byte integer, as specified in [WBXML1.2], followed by that many bytes of data."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R98"); // ActiveSyncClient encoded byte array structure as opaque data, so if response is successfully returned this requirement can be covered. Site.CaptureRequirement( "MS-ASDTYPE", 98, @"[In Byte Array] Elements with a byte array structure MUST be encoded and transmitted as [WBXML1.2] opaque data."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R123"); // If the schema is verified successfully, this requirement can be covered. Site.CaptureRequirement( "MS-ASDTYPE", 123, @"[In unsignedByte Data Type] The unsignedByte data type is an integer value between 0 and 255, inclusive."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDTYPE_R125"); // If the schema is verified successfully, this requirement can be covered. Site.CaptureRequirement( "MS-ASDTYPE", 125, @"[In unsignedByte Data Type] Elements of this type[unsignedByte type] are declared with an element whose type attribute is set to ""unsignedByte""."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R5"); // If the schema is verified successfully, this requirement can be covered. Site.CaptureRequirement( 5, @"[In Message Syntax] The markup that is used by this protocol[MS-ASDOC] MUST be well-formed XML, as specified in [XML]."); } }
/// <summary> /// Check if all search results contain Body element /// </summary> /// <param name="searchResponse">The searchResponse</param> /// <returns>If all search result contains Body element return true, else return false</returns> private static bool FindBodyElementInSearchResponse(SearchResponse searchResponse) { // Check search result's properties contains Body element foreach (Response.SearchResponseStoreResult result in searchResponse.ResponseData.Response.Store.Result) { bool containBodyElement = false; for (int index = 0; index < result.Properties.ItemsElementName.Length; index++) { if (result.Properties.ItemsElementName[index] == Response.ItemsChoiceType6.Body && result.Properties.Items[index] != null) { containBodyElement = true; break; } } if (containBodyElement == false) { return false; } } return true; }
/// <summary> /// Call Search command to find email. /// </summary> /// <param name="collectionId">The CollectionId of the folder to search.</param> /// <param name="freeText">The key words to search.</param> /// <returns>The response of Search command.</returns> protected SearchResponse CallSearchCommand(string collectionId, string freeText) { // Create Search command request. Request.SearchStore[] searchStores = new Request.SearchStore[1]; searchStores[0] = new Request.SearchStore { Name = SearchName.Mailbox.ToString(), Query = new Request.queryType { ItemsElementName = new Request.ItemsChoiceType2[] { Request.ItemsChoiceType2.And }, Items = new Request.queryType[] { new Request.queryType() } } }; ((Request.queryType)searchStores[0].Query.Items[0]).ItemsElementName = new Request.ItemsChoiceType2[] { Request.ItemsChoiceType2.CollectionId, Request.ItemsChoiceType2.FreeText }; ((Request.queryType)searchStores[0].Query.Items[0]).Items = new object[] { collectionId, freeText }; searchStores[0].Options = new Request.Options1 { Items = new object[] { string.Empty, "0-9", string.Empty }, ItemsElementName = new Request.ItemsChoiceType6[] { Request.ItemsChoiceType6.RebuildResults, Request.ItemsChoiceType6.Range, Request.ItemsChoiceType6.DeepTraversal } }; SearchRequest searchRequest = Common.CreateSearchRequest(searchStores); // Call Search command by HTTP POST. string searchString = searchRequest.GetRequestDataSerializedXML(); SendStringResponse searchResponseString = this.HTTPAdapter.HTTPPOST(CommandName.Search, null, searchString); // Convert from SendStringResponse to SearchResponse. SearchResponse searchResponse = new SearchResponse { ResponseDataXML = searchResponseString.ResponseDataXML }; searchResponse.DeserializeResponseData(); return searchResponse; }