public void MSASHTTP_S03_TC02_SetUserAgentRequestHeader() { #region Call ConfigureRequestPrefixFields to add the User-Agent header. string folderSyncRequestBody = Common.CreateFolderSyncRequest("0").GetRequestDataSerializedXML(); Dictionary <HTTPPOSTRequestPrefixField, string> requestPrefixFields = new Dictionary <HTTPPOSTRequestPrefixField, string> { { HTTPPOSTRequestPrefixField.UserAgent, "ASOM" } }; this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefixFields); #endregion #region Call FolderSync command. SendStringResponse folderSyncResponse = HTTPAdapter.HTTPPOST(CommandName.FolderSync, null, folderSyncRequestBody); // Check the command is executed successfully. this.CheckResponseStatus(folderSyncResponse.ResponseDataXML); #endregion #region Reset the User-Agent header. requestPrefixFields[HTTPPOSTRequestPrefixField.UserAgent] = null; this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefixFields); #endregion }
public void MSASCMD_S01_TC03_ErrorCode_600() { Site.Assume.IsFalse(Common.GetSutVersion(this.Site) == SutVersion.ExchangeServer2007 && string.Equals(Common.GetConfigurationPropertyValue("TransportType", this.Site).ToUpper(CultureInfo.InvariantCulture), "HTTP"), "Autodiscover request should be passed only through HTTPS to Exchange Server 2007."); #region Calls Autodiscover command with two Request elements. AutodiscoverRequest request = new AutodiscoverRequest { RequestData = new Request.Autodiscover { Request = new Request.RequestType { AcceptableResponseSchema = Common.GetConfigurationPropertyValue("AcceptableResponseSchema", Site), EMailAddress = Common.GetMailAddress(this.User1Information.UserName, this.User1Information.UserDomain) } } }; string requestText = request.GetRequestDataSerializedXML(); int requestStartPosition = requestText.IndexOf("<Request>", StringComparison.OrdinalIgnoreCase); int requestEndPosition = requestText.IndexOf("</Autodiscover>", StringComparison.OrdinalIgnoreCase) - 1; string requestElementString = requestText.Substring(requestStartPosition, requestEndPosition - requestStartPosition + 1); requestText = requestText.Insert(requestEndPosition + 1, requestElementString); SendStringResponse response = this.CMDAdapter.SendStringRequest(CommandName.Autodiscover, null, requestText); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(response.ResponseDataXML); XmlElement xmlElement = (XmlElement)xmlDoc.DocumentElement; string errorCode = xmlElement.GetElementsByTagName("ErrorCode")[0].InnerText; // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R3799"); Site.CaptureRequirementIfAreEqual <string>( "600", errorCode, 3799, @"[In Request(Autodiscover)] When more than one Request elements are present in an Autodiscover command request, the server returns an ErrorCode (section 2.2.3.61) value of 600."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2286"); // Send more than one request means the schema doesn't match the one that AcceptableResponseSchema element provides, // So R2286 can be captured. Site.CaptureRequirementIfAreEqual <string>( "600", errorCode, 2286, @"[In ErrorCode] [If the provider cannot be found, or ]if the AcceptableResponseSchema element (section 2.2.3.1) value cannot be matched, then the ErrorCode element is included in the command response."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2287"); Site.CaptureRequirementIfAreEqual <string>( "600", errorCode, 2287, @"[In ErrorCode] A value of 600 means an invalid request was sent to the server."); #endregion }
/// <summary> /// Send a string request and get a response from server. /// </summary> /// <param name="stringRequest">A string request for a certain command.</param> /// <param name="commandName">Commands choices.</param> /// <returns>A string response returned from the server.</returns> public SendStringResponse SendStringRequest(string stringRequest, CommandName commandName) { SendStringResponse response = this.activeSyncClient.SendStringRequest(commandName, null, stringRequest); Site.Assert.IsNotNull(response, "The string response should be returned."); return(response); }
public void MSASHTTP_S03_TC03_SetPolicyKeyRequestHeader() { #region Change the query value type to PlainText. // Call ConfigureRequestPrefixFields to set the QueryValueType to PlainText. IDictionary <HTTPPOSTRequestPrefixField, string> requestPrefix = new Dictionary <HTTPPOSTRequestPrefixField, string>(); requestPrefix.Add(HTTPPOSTRequestPrefixField.QueryValueType, QueryValueType.PlainText.ToString()); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); #endregion #region Call Provision command without setting X-MS-PolicyKey header. SendStringResponse provisionResponse = this.CallProvisionCommand(string.Empty); // Get the policy key from the response of Provision command. string policyKey = TestSuiteHelper.GetPolicyKeyFromSendString(provisionResponse); #endregion #region Call Provision command with setting X-MS-PolicyKey header of the PlainText encoded query value type. // Set the X-MS-PolicyKey header. requestPrefix.Add(HTTPPOSTRequestPrefixField.PolicyKey, policyKey); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); this.CallProvisionCommand(policyKey); // Reset the X-MS-PolicyKey header. requestPrefix[HTTPPOSTRequestPrefixField.PolicyKey] = string.Empty; this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); #endregion #region Change the query value type to Base64. // Call ConfigureRequestPrefixFields to set the QueryValueType to Base64. requestPrefix[HTTPPOSTRequestPrefixField.QueryValueType] = QueryValueType.Base64.ToString(); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); #endregion #region Call Provision command without setting Policy key field. provisionResponse = this.CallProvisionCommand(string.Empty); // Get the policy key from the response of Provision command. policyKey = TestSuiteHelper.GetPolicyKeyFromSendString(provisionResponse); #endregion #region Call Provision command with setting Policy key field of the base64 encoded query value type. // Set the Policy key field. requestPrefix[HTTPPOSTRequestPrefixField.PolicyKey] = policyKey; this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); this.CallProvisionCommand(policyKey); // Reset the Policy key field. requestPrefix[HTTPPOSTRequestPrefixField.PolicyKey] = string.Empty; this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); #endregion #region Reset the query value type. requestPrefix[HTTPPOSTRequestPrefixField.QueryValueType] = Common.GetConfigurationPropertyValue("HeaderEncodingType", this.Site); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); #endregion }
public void MSASTASK_S03_TC02_RetrieveInvalidTaskItemWithSearch() { #region Call Sync command to create a task item Dictionary <Request.ItemsChoiceType8, object> taskItem = new Dictionary <Request.ItemsChoiceType8, object>(); string subject = Common.GenerateResourceName(Site, "subject"); taskItem.Add(Request.ItemsChoiceType8.Subject2, subject); #endregion #region Call Sync command to add the task to the server // add task SyncStore syncResponse = this.SyncAddTask(taskItem); Site.Assert.AreEqual <int>(1, int.Parse(syncResponse.AddResponses[0].Status), "Adding a task item to server should success."); SyncItem task = this.GetChangeItem(this.UserInformation.TasksCollectionId, subject); Site.Assert.IsNotNull(task.Task, "The task which subject is {0} should exist in server.", subject); ItemsNeedToDelete.Add(subject); #endregion #region Call Search command to search task on the server // Send a string create task item request without Type element contains in Recurrence. SendStringResponse sendStringResponse = this.TASKAdapter.SendStringRequest("<Search xmlns=\"Search\"><Store><Name>Mailbox</Name><Query><And><Class xmlns=\"AirSync\">Tasks</Class><CollectionId xmlns=\"AirSync\">" + this.UserInformation.TasksCollectionId + "</CollectionId><FreeText>FreeText</FreeText><Subject xmlns=\"Tasks\">user</Subject></And></Query><Options><DeepTraversal /></Options></Store></Search>", CommandName.Search); XmlDocument doc = new XmlDocument(); doc.LoadXml(sendStringResponse.ResponseDataXML); XmlNamespaceManager xnm = new XmlNamespaceManager(doc.NameTable); xnm.AddNamespace("e", "Search"); int retryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); int counter = 1; XmlNode searchStatus = doc.SelectSingleNode("/e:Search/e:Status", xnm); while (counter < retryCount && searchStatus != null && searchStatus.InnerXml.Equals("10")) { Thread.Sleep(waitTime); sendStringResponse = this.TASKAdapter.SendStringRequest("<Search xmlns=\"Search\"><Store><Name>Mailbox</Name><Query><And><Class xmlns=\"AirSync\">Tasks</Class><CollectionId xmlns=\"AirSync\">" + this.UserInformation.TasksCollectionId + "</CollectionId><FreeText>FreeText</FreeText><Subject xmlns=\"Tasks\">user</Subject></And></Query><Options><DeepTraversal /></Options></Store></Search>", CommandName.Search); doc.LoadXml(sendStringResponse.ResponseDataXML); xnm = new XmlNamespaceManager(doc.NameTable); xnm.AddNamespace("e", "Search"); searchStatus = doc.SelectSingleNode("/e:Search/e:Status", xnm); counter++; } #endregion // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASTASK_R364"); // Verify MS-ASTASK requirement: MS-ASTASK_R364 Site.CaptureRequirementIfAreEqual <string>( "2", Common.GetSearchStatusCode(sendStringResponse), 364, @"[In Search Command Response] If elements that belong to the Task class are included in a Search command request, the server MUST return a Status value of 2 in the Store element, as specified in [MS-ASCMD] section 2.2.3.162.12."); }
/// <summary> /// Sync data from the server with an invalid sync request which contains additional element. /// </summary> /// <param name="syncRequest">The request for sync operation.</param> /// <param name="addElement">Additional element insert into normal sync request.</param> /// <param name="insertTag">Insert tag shows where the additional element should inserted.</param> /// <returns>The sync result which is returned from server.</returns> public SendStringResponse InvalidSync(SyncRequest syncRequest, string addElement, string insertTag) { string syncXmlRequest = syncRequest.GetRequestDataSerializedXML(); string changedSyncXmlRequest = syncXmlRequest.Insert(syncXmlRequest.IndexOf(insertTag, StringComparison.CurrentCulture), addElement); SendStringResponse result = this.activeSyncClient.SendStringRequest(CommandName.Sync, null, changedSyncXmlRequest); this.VerifyTransport(); return(result); }
/// <summary> /// Send HTTP POST request to the server and get the response. /// </summary> /// <param name="commandName">The name of the command to send.</param> /// <param name="commandParameters">The command parameters.</param> /// <param name="requestBody">The plain text request.</param> /// <returns>The plain text response.</returns> public SendStringResponse HTTPPOST(CommandName commandName, IDictionary <CmdParameterName, object> commandParameters, string requestBody) { SendStringResponse postResponse = this.activeSyncClient.SendStringRequest(commandName, commandParameters, requestBody); Site.Assert.IsNotNull(postResponse, "The HTTP POST response returned from server should not be null."); this.VerifyHTTPPOSTResponse(postResponse); this.VerifyTransportType(); return(postResponse); }
public void MSASHTTP_S01_TC14_CommandCode_ValidateCert() { #region Call ValidateCert command. ValidateCertRequest validateCertRequest = Common.CreateValidateCertRequest(); SendStringResponse validateCertResponse = HTTPAdapter.HTTPPOST(CommandName.ValidateCert, null, validateCertRequest.GetRequestDataSerializedXML()); // Check the command is executed successfully. this.CheckResponseStatus(validateCertResponse.ResponseDataXML); #endregion }
/// <summary> /// Update email with more data /// </summary> /// <param name="collectionId">The collectionId of the folder which contains the item to be updated.</param> /// <param name="syncKey">The syncKey which is returned from server</param> /// <param name="read">The value is TRUE indicates the email has been read; a value of FALSE indicates the email has not been read</param> /// <param name="serverId">The server id of the email</param> /// <param name="flag">The flag instance</param> /// <param name="categories">The list of categories</param> /// <param name="additionalElement">Additional flag element</param> /// <param name="insertTag">Additional element will insert before this tag</param> /// <returns>Return update email result</returns> protected SendStringResponse UpdateEmailWithMoreData(string collectionId, string syncKey, bool read, string serverId, Request.Flag flag, Collection <object> categories, string additionalElement, string insertTag) { // Create normal sync request Request.SyncCollectionChange changeData = TestSuiteHelper.CreateSyncChangeData(read, serverId, flag, categories); SyncRequest syncRequest = TestSuiteHelper.CreateSyncChangeRequest(syncKey, collectionId, changeData); // Calls Sync command to update email with invalid sync request SendStringResponse result = this.EMAILAdapter.InvalidSync(syncRequest, additionalElement, insertTag); return(result); }
/// <summary> /// Search data on the server with an invalid Search request which contains an E-mail Class element. /// </summary> /// <param name="searchRequest">The request for search operation.</param> /// <param name="emailClassElement">The email class element.</param> /// <returns>The search response which is returned from server.</returns> public SendStringResponse InvalidSearch(SearchRequest searchRequest, string emailClassElement) { string searchXmlRequest = searchRequest.GetRequestDataSerializedXML(); // Insert email class element to search command request string changedSearchXmlRequest = searchXmlRequest.Insert(searchXmlRequest.LastIndexOf("</And>", StringComparison.CurrentCulture), emailClassElement); SendStringResponse result = this.activeSyncClient.SendStringRequest(CommandName.Search, null, changedSearchXmlRequest); this.VerifyTransport(); return(result); }
/// <summary> /// Send string request of Provision command to the server and get the Provision response. /// </summary> /// <param name="provisionRequest">The string request of Provision command.</param> /// <returns>The response of Provision command.</returns> public ProvisionResponse SendProvisionStringRequest(string provisionRequest) { SendStringResponse provisionStringResponse = this.activeSyncClient.SendStringRequest(CommandName.Provision, null, provisionRequest); Site.Assert.IsNotNull(provisionStringResponse, "The SendStringRequest response returned from server should not be null."); // Convert the SendStringResponse to ProvisionResponse. ProvisionResponse provisionResponse = new ProvisionResponse { ResponseDataXML = provisionStringResponse.ResponseDataXML }; provisionResponse.DeserializeResponseData(); return(provisionResponse); }
public void MSASHTTP_S01_TC04_CommandParameter_AttachmentName_PlainText() { Site.Assume.AreNotEqual <string>("14.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 14.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion."); Site.Assume.AreNotEqual <string>("14.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 14.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion."); Site.Assume.AreNotEqual <string>("16.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 16.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion."); Site.Assume.AreNotEqual <string>("16.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 16.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion."); SendStringResponse getAttachmentResponse = this.VerifyGetAttachmentsCommandParameter(QueryValueType.PlainText); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R115"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R115 // The GetAttachment command executes successfully when the AttachmentName command parameter is set, so this requirement can be captured. Site.CaptureRequirement( 115, @"[In Command-Specific URI Parameters] [Parameter] AttachmentName [is used by] GetAttachment."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R487"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R487 // The GetAttachment command executes successfully when the AttachmentName command parameter is set, so this requirement can be captured. Site.CaptureRequirement( 487, @"[In Command-Specific URI Parameters] [Parameter] AttachmentName [is described as] A string that specifies the name of the attachment file to be retrieved. "); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R230"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R230 // The GetAttachment command response has no xml body, so this requirement can be captured. Site.CaptureRequirementIfIsFalse( this.IsXml(getAttachmentResponse.ResponseDataXML), 230, @"[In Response Body] Three commands have no XML body in certain contexts: GetAttachment, [Sync, and Ping]."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R490"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R490 // The GetAttachment command was executed successfully, so this requirement can be captured. Site.CaptureRequirement( 490, @"[In Command Codes] [Command] GetAttachment retrieves an e-mail attachment from the server."); }
/// <summary> /// Get search response status which returned by the SendStringRequest operation. /// </summary> /// <param name="response">The SendStringResponse instance</param> /// <returns>The Status code</returns> public static string GetSearchStatusCode(SendStringResponse response) { string xmlResponse = response.ResponseDataXML; XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlResponse); XmlNamespaceManager xmlNameSpaceManager = new XmlNamespaceManager(doc.NameTable); xmlNameSpaceManager.AddNamespace("e", "Search"); XmlNode status = doc.SelectSingleNode("/e:Search/e:Response/e:Store/e:Status", xmlNameSpaceManager); if (status != null) { return status.InnerText; } else { return null; } }
/// <summary> /// Get the status code from the response. /// </summary> /// <param name="response">The string format response.</param> /// <param name="xpath">The XPath to get the status code.</param> /// <returns>Returns the status code</returns> private string GetStatusCodeFromXPath(SendStringResponse response, string xpath) { XmlDocument doc = new XmlDocument(); doc.LoadXml(response.ResponseDataXML); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("a", "AirSync"); nsmgr.AddNamespace("i", "ItemOperations"); nsmgr.AddNamespace("s", "Search"); XmlNode status = doc.SelectSingleNode(xpath, nsmgr); Site.Assert.IsNotNull(status, "The Status element should be returned in the response."); return(status.InnerText); }
public void MSASHTTP_S01_TC13_CommandCode_UserRelatedCommands() { #region Call ResolveRecipients command. object[] items = new object[] { Common.GetConfigurationPropertyValue("User1Name", Site) }; ResolveRecipientsRequest resolveRecipientsRequest = Common.CreateResolveRecipientsRequest(items); SendStringResponse resolveRecipientsResponse = HTTPAdapter.HTTPPOST(CommandName.ResolveRecipients, null, resolveRecipientsRequest.GetRequestDataSerializedXML()); // Check the command is executed successfully. this.CheckResponseStatus(resolveRecipientsResponse.ResponseDataXML); #endregion #region Call Settings command. SettingsRequest settingsRequest = Common.CreateSettingsRequest(); SendStringResponse settingsResponse = HTTPAdapter.HTTPPOST(CommandName.Settings, null, settingsRequest.GetRequestDataSerializedXML()); // Check the command is executed successfully. this.CheckResponseStatus(settingsResponse.ResponseDataXML); #endregion }
/// <summary> /// Update email with invalid data /// </summary> /// <param name="invalidElement">invalid element send to server</param> /// <returns>Update results status code</returns> private string UpdateVoiceEmailWithInvalidData(string invalidElement) { // Switch to user2 mailbox this.SwitchUser(this.User2Information, true); // Sync changes SyncStore initSyncResult = this.InitializeSync(this.User2Information.InboxCollectionId); SyncStore syncChangeResult = this.SyncChanges(initSyncResult.SyncKey, this.User2Information.InboxCollectionId, null); string syncKey = syncChangeResult.SyncKey; string serverId = this.User2Information.InboxCollectionId; // Create normal Sync change request Request.SyncCollectionChange changeData = TestSuiteHelper.CreateSyncChangeData(true, serverId, null, null); SyncRequest syncRequest = TestSuiteHelper.CreateSyncChangeRequest(syncKey, this.User2Information.InboxCollectionId, changeData); // Calls Sync command to update email with invalid sync request string insertTag = "</ApplicationData>"; SendStringResponse result = this.EMAILAdapter.InvalidSync(syncRequest, invalidElement, insertTag); // Get status code return(TestSuiteHelper.GetStatusCode(result.ResponseDataXML)); }
/// <summary> /// Extract Add elements from a Sync string response. /// </summary> /// <param name="sendStringResponse">The returned SendStringResponse object.</param> /// <returns>The extracted SyncStore object.</returns> protected SyncStore ExtractSyncStore(SendStringResponse sendStringResponse) { SyncStore response = new SyncStore(); XmlDocument doc = new XmlDocument(); doc.LoadXml(sendStringResponse.ResponseDataXML); XmlNodeList nodes = doc.DocumentElement.GetElementsByTagName("Collection"); foreach (XmlNode node in nodes) { foreach (XmlNode item in node.ChildNodes) { if (item.Name == "Responses") { foreach (XmlNode add in item) { if (add.Name == "Add") { Response.SyncCollectionsCollectionResponsesAdd responseData = new Response.SyncCollectionsCollectionResponsesAdd(); foreach (XmlNode addItem in add) { if (addItem.Name == "Status") { responseData.Status = addItem.InnerText; } } response.AddResponses.Add(responseData); } } } } } return(response); }
/// <summary> /// Verify requirements about HTTP POST response headers. /// </summary> /// <param name="postResponse">The HTTP POST response.</param> private void VerifyHTTPPOSTHeaders(SendStringResponse postResponse) { int contentLengthNumber; string responseHeaders = postResponse.Headers.ToString(); Site.Log.Add(LogEntryKind.Debug, "The response headers are: {0}.", responseHeaders); bool isContentLengthExist = responseHeaders.Contains("Content-Length"); bool isContentTypeExist = responseHeaders.Contains("Content-Type"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R199"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R199 // The Content-Length header exists in the HTTP POST response and can be parsed to int, so this requirement can be captured. bool isVerifiedR199 = isContentLengthExist && int.TryParse(postResponse.Headers["Content-Length"], out contentLengthNumber); Site.CaptureRequirementIfIsTrue( isVerifiedR199, 199, @"[In Response Headers] Required [header] Content-Length specifies the size of the response body in bytes, [whose example value is] 56."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R521"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R521 // The Content-Length header follows the specified format, so this requirement can be captured. bool isVerifiedR521 = responseHeaders.Contains("Content-Length: " + postResponse.Headers["Content-Length"]) && int.TryParse(postResponse.Headers["Content-Length"], out contentLengthNumber); Site.CaptureRequirementIfIsTrue( isVerifiedR521, 521, @"[In Content-Length] Content-Length = ""Content-Length"" "":"" 1*DIGIT"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R216"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R216 // The Content-Length header exists in the HTTP POST response, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( isContentLengthExist, 216, @"[In Content-Length] This [Content-Length] header is required."); bool hasContent = int.Parse(postResponse.Headers["Content-Length"]) > 0; bool isVerifiedR212; if (hasContent) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R201"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R201 // The Content-Type header exists in the HTTP POST response, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( isContentTypeExist, 201, @"[In Response Headers] Required [header] Content-Type specifies that the media-type of the response body is WBXML, [whose example value is] application/vnd.ms-sync.wbxml."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R218"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R218 // The Content-Type header exists in the HTTP POST response, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( isContentTypeExist, 218, @"[In Content-Type] This [Content-Type] header is required."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R522"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R522 // The Content-Type header follows the specified format, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( responseHeaders.Contains("Content-Type: " + postResponse.Headers["Content-Type"]), 522, @"[In Content-Type] Content-Type = ""Content-Type"" "":"" media-type"); isVerifiedR212 = isContentLengthExist && isContentTypeExist; } else { isVerifiedR212 = isContentLengthExist; } // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R212"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R212 Site.CaptureRequirementIfIsTrue( isVerifiedR212, 212, @"[In Response Headers] When these two conditions [the response is to an HTTP POST request and the response has HTTP status 200] are met, only the following headers are necessary in the response: Content-Length Content-Type, required only if Content-Length is greater than zero."); }
public void MSASHTTP_S01_TC12_CommandCode_ItemRelatedCommands() { #region Call ConfigureRequestPrefixFields to change the query value type to Base64. IDictionary <HTTPPOSTRequestPrefixField, string> requestPrefix = new Dictionary <HTTPPOSTRequestPrefixField, string>(); requestPrefix.Add(HTTPPOSTRequestPrefixField.QueryValueType, QueryValueType.Base64.ToString()); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); #endregion #region Call SendMail command to send email to User2. string sendMailSubject = Common.GenerateResourceName(Site, "SendMail"); string folderNameToCreate = Common.GenerateResourceName(Site, "CreatedFolder"); string userOneMailboxAddress = Common.GetMailAddress(this.UserOneInformation.UserName, this.UserOneInformation.UserDomain); string userTwoMailboxAddress = Common.GetMailAddress(this.UserTwoInformation.UserName, this.UserTwoInformation.UserDomain); // Call SendMail command to send email to User2. this.CallSendMailCommand(userOneMailboxAddress, userTwoMailboxAddress, sendMailSubject, null); #endregion #region Call Ping command for changes that would require the client to resynchronize. // Switch the user to User2 and synchronize the collection hierarchy. this.SwitchUser(this.UserTwoInformation, true); // Call FolderSync command to synchronize the collection hierarchy. FolderSyncResponse folderSyncResponse = this.CallFolderSyncCommand(); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R428"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R428 // The received email could not be got by FolderSync command, so this requirement can be captured. Site.CaptureRequirementIfIsFalse( folderSyncResponse.ResponseDataXML.Contains(sendMailSubject), 428, @"[In Command Codes] But [command] FolderSync does not synchronize the items in the folders."); // Call Ping command for changes of Inbox folder. PingResponse pingResponse = this.CallPingCommand(this.UserTwoInformation.InboxCollectionId); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R504"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R504 // The Status of the Ping command is 2 which means this folder needs to be synced, so this requirement can be captured. Site.CaptureRequirementIfAreEqual <string>( "2", pingResponse.ResponseData.Status.ToString(), 504, @"[In Command Codes] [Command] Ping requests that the server monitor specified folders for changes that would require the client to resynchronize."); #endregion #region Get the ServerId of the received email. // Call Sync command to get the ServerId of the received email. string receivedItemServerId = this.LoopToSyncItem(this.UserTwoInformation.InboxCollectionId, sendMailSubject, true); #endregion #region Call FolderCreate command to create a sub folder under Inbox folder. FolderCreateResponse folderCreateResponse = this.CallFolderCreateCommand(folderSyncResponse.ResponseData.SyncKey, folderNameToCreate, this.UserTwoInformation.InboxCollectionId); // Get the ServerId of the created folder. string createdFolder = folderCreateResponse.ResponseData.ServerId; #endregion #region Move the received email from Inbox folder to the created folder. this.CallMoveItemsCommand(receivedItemServerId, this.UserTwoInformation.InboxCollectionId, createdFolder); #endregion #region Get the moved email in the created folder. // Call Sync command to get the received email. receivedItemServerId = this.LoopToSyncItem(createdFolder, sendMailSubject, true); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R499"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R499 // The moved email could be got in the new created folder, so this requirement can be captured. Site.CaptureRequirementIfIsNotNull( receivedItemServerId, 499, @"[In Command Codes] [Command] MoveItems moves items from one folder to another."); #endregion #region Call ItemOperation command to fetch the email in Sent Items folder with AcceptMultiPart command parameter. SendStringResponse itemOperationResponse = this.CallItemOperationsCommand(createdFolder, receivedItemServerId, true); Site.Assert.IsNotNull(itemOperationResponse.Headers["Content-Type"], "The Content-Type header should not be null."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R94"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R94 // The content is in multipart, so this requirement can be captured. Site.CaptureRequirementIfAreEqual <string>( "application/vnd.ms-sync.multipart", itemOperationResponse.Headers["Content-Type"], 94, @"[In Command Parameters] [When flag] AcceptMultiPart [value is] 0x02, [the meaning is] setting this flag [AcceptMultiPart] to instruct the server to return the requested item in multipart format."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R95"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R95 // R94 can be captured, so this requirement can be captured directly. Site.CaptureRequirement( 95, @"[In Command Parameters] [When flag] AcceptMultiPart [value is] 0x02, [it is] valid for ItemOperations."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R534"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R534 // R94 can be captured, so this requirement can be captured directly. Site.CaptureRequirement( 534, @"[In Command Parameters] [Parameter] Options [ is used by] ItemOperations."); #endregion #region Call FolderDelete to delete a folder from the server. this.CallFolderDeleteCommand(folderCreateResponse.ResponseData.SyncKey, createdFolder); #endregion #region Reset the query value type and user credential. requestPrefix[HTTPPOSTRequestPrefixField.QueryValueType] = Common.GetConfigurationPropertyValue("HeaderEncodingType", this.Site); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); this.SwitchUser(this.UserOneInformation, false); #endregion }
/// <summary> /// Sends a plain text request. /// </summary> /// <param name="cmdName">The name of the command to send</param> /// <param name="parameters">The command parameters</param> /// <param name="request">The plain text request</param> /// <returns>The plain text response.</returns> public SendStringResponse SendStringRequest(CommandName cmdName, IDictionary <CmdParameterName, object> parameters, string request) { SendStringResponse response = this.activeSyncClient.SendStringRequest(cmdName, parameters, request); return(response); }
/// <summary> /// Verify requirements about HTTP POST response headers. /// </summary> /// <param name="postResponse">The HTTP POST response.</param> private void VerifyHTTPPOSTHeaders(SendStringResponse postResponse) { int contentLengthNumber; string responseHeaders = postResponse.Headers.ToString(); Site.Log.Add(LogEntryKind.Debug, "The response headers are: {0}.", responseHeaders); bool isContentLengthExist = responseHeaders.Contains("Content-Length"); bool isContentTypeExist = responseHeaders.Contains("Content-Type"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R199"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R199 // The Content-Length header exists in the HTTP POST response and can be parsed to int, so this requirement can be captured. bool isVerifiedR199 = isContentLengthExist && int.TryParse(postResponse.Headers["Content-Length"], out contentLengthNumber); Site.CaptureRequirementIfIsTrue( isVerifiedR199, 199, @"[In Response Headers] Required [header] Content-Length specifies the size of the response body in bytes, [whose example value is] 56."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R521"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R521 // The Content-Length header follows the specified format, so this requirement can be captured. bool isVerifiedR521 = responseHeaders.Contains("Content-Length: " + postResponse.Headers["Content-Length"]) && int.TryParse(postResponse.Headers["Content-Length"], out contentLengthNumber); Site.CaptureRequirementIfIsTrue( isVerifiedR521, 521, @"[In Content-Length] Content-Length = ""Content-Length"" "":"" 1*DIGIT"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R216"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R216 // The Content-Length header exists in the HTTP POST response, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( isContentLengthExist, 216, @"[In Content-Length] This [Content-Length] header is required."); bool hasContent = int.Parse(postResponse.Headers["Content-Length"]) > 0; bool isVerifiedR212; if (hasContent) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R201"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R201 // The Content-Type header exists in the HTTP POST response, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( isContentTypeExist, 201, @"[In Response Headers] Required [header] Content-Type specifies that the media-type of the response body is WBXML, [whose example value is] application/vnd.ms-sync.wbxml."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R218"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R218 // The Content-Type header exists in the HTTP POST response, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( isContentTypeExist, 218, @"[In Content-Type] This [Content-Type] header is required."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R522"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R522 // The Content-Type header follows the specified format, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( responseHeaders.Contains("Content-Type: " + postResponse.Headers["Content-Type"]), 522, @"[In Content-Type] Content-Type = ""Content-Type"" "":"" media-type"); isVerifiedR212 = isContentLengthExist && isContentTypeExist; } else { isVerifiedR212 = isContentLengthExist; } // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R212"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R212 Site.CaptureRequirementIfIsTrue( isVerifiedR212, 212, @"[In Response Headers] When these two conditions [the response is to an HTTP POST request and the response has HTTP status 200] are met, only the following headers are necessary in the response: Content-Length Content-Type, required only if Content-Length is greater than zero."); }
public void MSASHTTP_S03_TC04_LimitChangesToUserAgentHeader() { Site.Assume.IsTrue(Common.IsRequirementEnabled(456, this.Site), "Exchange server 2013 and above support using different values for the number of User-Agent changes or the time period."); Site.Assume.IsTrue(Common.IsRequirementEnabled(457, this.Site), "Exchange server 2013 and above support blocking clients for a different amount of time."); #region Call FolderSync command for the first time with User-Agent header. // Wait for 1 minute System.Threading.Thread.Sleep(new TimeSpan(0, 1, 0)); DateTime startTime = DateTime.Now; string folderSyncRequestBody = Common.CreateFolderSyncRequest("0").GetRequestDataSerializedXML(); Dictionary <HTTPPOSTRequestPrefixField, string> requestPrefixFields = new Dictionary <HTTPPOSTRequestPrefixField, string> { { HTTPPOSTRequestPrefixField.UserAgent, Common.GenerateResourceName(this.Site, "ASOM", 1) } }; this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefixFields); SendStringResponse folderSyncResponse = HTTPAdapter.HTTPPOST(CommandName.FolderSync, null, folderSyncRequestBody); // Check the command is executed successfully. this.CheckResponseStatus(folderSyncResponse.ResponseDataXML); #endregion #region Call FolderSync command for the second time with updated User-Agent header. requestPrefixFields[HTTPPOSTRequestPrefixField.UserAgent] = Common.GenerateResourceName(this.Site, "ASOM", 2); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefixFields); folderSyncResponse = HTTPAdapter.HTTPPOST(CommandName.FolderSync, null, folderSyncRequestBody); // Check the command is executed successfully. this.CheckResponseStatus(folderSyncResponse.ResponseDataXML); #endregion #region Call FolderSync command for third time with updated User-Agent header. requestPrefixFields[HTTPPOSTRequestPrefixField.UserAgent] = Common.GenerateResourceName(this.Site, "ASOM", 3); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefixFields); try { folderSyncResponse = HTTPAdapter.HTTPPOST(CommandName.FolderSync, null, folderSyncRequestBody); Site.Assert.Fail("HTTP error 503 should be returned if server blocks a client from changing its User-Agent header value."); } catch (System.Net.WebException exception) { int statusCode = ((System.Net.HttpWebResponse)exception.Response).StatusCode.GetHashCode(); if (Common.IsRequirementEnabled(456, this.Site)) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R456"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R456 // Server configures the number of changes and the time period, and expected HTTP error is returned, this requirement can be captured. Site.CaptureRequirementIfAreEqual <int>( 503, statusCode, 456, @"[In Appendix A: Product Behavior] Implementation can be configured to use different values for the allowed number of changes and the time period. (<9> Section 3.2.5.1.1: Exchange 2013 , Exchange 2016, and Exchange 2019 can be configured to use different values for the allowed number of changes and the time period.)"); } } #endregion #region Call FolderSync command after server blocks client from changing its User-Agent header value. requestPrefixFields[HTTPPOSTRequestPrefixField.UserAgent] = Common.GenerateResourceName(this.Site, "ASOM", 4); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefixFields); bool isCorrectBlocked = false; try { folderSyncResponse = HTTPAdapter.HTTPPOST(CommandName.FolderSync, null, folderSyncRequestBody); } catch (System.Net.WebException) { // HTTP error returns indicates server blocks client. isCorrectBlocked = true; } // Server sets blocking client for 1 minute, wait for 1 minute for un-blocking. System.Threading.Thread.Sleep(new TimeSpan(0, 1, 0)); requestPrefixFields[HTTPPOSTRequestPrefixField.UserAgent] = Common.GenerateResourceName(this.Site, "ASOM", 5); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefixFields); try { folderSyncResponse = HTTPAdapter.HTTPPOST(CommandName.FolderSync, null, folderSyncRequestBody); isCorrectBlocked = isCorrectBlocked && true; } catch (System.Net.WebException) { // HTTP error returns indicates server still blocks client. isCorrectBlocked = false; } if (Common.IsRequirementEnabled(457, this.Site)) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R457"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R457 // FolderSync command runs successfully after the blocking time period, and it runs with exception during the time period, // this requirement can be captured. Site.CaptureRequirementIfIsTrue( isCorrectBlocked, 457, @"[In Appendix A: Product Behavior] Implementation can be configured to block clients for an amount of time other than 14 hours. (<10> Section 3.2.5.1.1: Exchange 2013, Exchange 2016, and Exchange 2019 can be configured to block clients for an amount of time other than 14 hours.)"); } // Wait for 1 minute System.Threading.Thread.Sleep(new TimeSpan(0, 1, 0)); #endregion #region Reset the User-Agent header. requestPrefixFields[HTTPPOSTRequestPrefixField.UserAgent] = null; this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefixFields); #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 }
/// <summary> /// Get the status code from the response. /// </summary> /// <param name="response">The string format response.</param> /// <param name="xpath">The XPath to get the status code.</param> /// <returns>Returns the status code</returns> private string GetStatusCodeFromXPath(SendStringResponse response, string xpath) { XmlDocument doc = new XmlDocument(); doc.LoadXml(response.ResponseDataXML); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("a", "AirSync"); nsmgr.AddNamespace("i", "ItemOperations"); nsmgr.AddNamespace("s", "Search"); XmlNode status = doc.SelectSingleNode(xpath, nsmgr); Site.Assert.IsNotNull(status, "The Status element should be returned in the response."); return status.InnerText; }
/// <summary> /// Get the ASCMD Status from Response. /// </summary> /// <param name="response">ASCMD command responses.</param> /// <returns>status value</returns> public byte GetStatusFromResponses(object response) { byte statusValue = 0; if (null == response) { return(statusValue); } Type responsesType = response.GetType(); Type baseType = responsesType.BaseType; // Verify whether it is inherited from ActiveSyncDataStructure.ActiveSyncResponses<T>. if (null == baseType || 0 != baseType.FullName.IndexOf("ActiveSyncDataStructure.ActiveSyncResponses`1", StringComparison.OrdinalIgnoreCase)) { return(statusValue); } // Verify whether the responses is "SendStringResponses" if (0 == responsesType.FullName.IndexOf("ActiveSyncDataStructure.SendStringResponses", StringComparison.OrdinalIgnoreCase)) { SendStringResponse stringResponses = response as SendStringResponse; if (stringResponses != null) { return(PickUpRootStatusValueFromXMLString(stringResponses.ResponseDataXML)); } } // If it is not a SendStringResponses, get the status field under the Responses element. PropertyInfo lowLevelResponsesData = responsesType.GetProperty("ResponsesData"); if (null == lowLevelResponsesData) { return(statusValue); } object responsesDataInstance = lowLevelResponsesData.GetValue(response, null); if (null == responsesDataInstance) { return(statusValue); } // Get the ResponsesData type Type responsesDataType = responsesDataInstance.GetType(); PropertyInfo statusproperty = responsesDataType.GetProperty("Status", typeof(byte)); // If it doesn't contain the "status" in serialized data type, try to pick up from "ResponsesDataXML" if (null == statusproperty) { PropertyInfo responsesXMLProperty = responsesType.GetProperty("ResponsesDataXML"); if (responsesXMLProperty != null) { string responsesDataXMLTemp = responsesXMLProperty.GetValue(response, null) as string; return(PickUpRootStatusValueFromXMLString(responsesDataXMLTemp)); } return(statusValue); } try { statusValue = (byte)statusproperty.GetValue(responsesDataInstance, null); } catch (FormatException ex) { Site.Log.Add(LogEntryKind.TestError, "Could not parse the ResponsesData.Status to byte type\r\n{0}", ex.Message); } return(statusValue); }
/// <summary> /// A method that send out string command request that contains multiple CalendarType elements in Recurrence. /// </summary> /// <param name="type">value of Type element in Recurrence.</param> /// <returns>Command response of sending </returns> public SyncStore AddCalendarWithMultipleCalendarType(string type) { SyncStore initialSyncResponse = this.InitializeSync(this.CurrentUserInformation.CalendarCollectionId, null); SendStringResponse sendStringResponse = new SendStringResponse(); switch (type) { case "2": // [email protected] in string request is a sample email address of an attendee, nothing will be sent to this mailbox. sendStringResponse = this.CALAdapter.SendStringRequest("<?xml version=\"1.0\" encoding=\"utf-8\"?><Sync xmlns=\"AirSync\"><Collections><Collection><SyncKey>" + initialSyncResponse.SyncKey + "</SyncKey><CollectionId>1</CollectionId><WindowSize>512</WindowSize><Options><BodyPreference xmlns=\"AirSyncBase\"><Type>2</Type></BodyPreference></Options><Commands><Add><ClientId>54353</ClientId><ApplicationData><Subject xmlns=\"Calendar\">TestMail</Subject><MeetingStatus xmlns=\"Calendar\">1</MeetingStatus><UID xmlns=\"Calendar\">040000008200E00074C5B7101A82E00800000000B0CD1F52EBBDC901000000000000000010000000B05E442FCB2CA443BF3D99B51A729FE6</UID><Timezone xmlns=\"Calendar\">IP7//ygAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</Timezone><Attendees xmlns=\"Calendar\"><Attendee><Email>[email protected]</Email><Name>EAS_User02</Name><AttendeeStatus>3</AttendeeStatus><AttendeeType>1</AttendeeType></Attendee></Attendees><Recurrence xmlns=\"Calendar\"><Type>" + type + "</Type><Occurrences>3</Occurrences><Interval>0</Interval><DayOfMonth>1</DayOfMonth><CalendarType>1</CalendarType><CalendarType>2</CalendarType></Recurrence><ResponseRequested xmlns=\"Calendar\">1</ResponseRequested><Reminder xmlns=\"Calendar\">10</Reminder></ApplicationData></Add></Commands></Collection></Collections></Sync>"); break; case "3": // [email protected] in string request is a sample email address of an attendee, nothing will be sent to this mailbox. sendStringResponse = this.CALAdapter.SendStringRequest("<?xml version=\"1.0\" encoding=\"utf-8\"?><Sync xmlns=\"AirSync\"><Collections><Collection><SyncKey>" + initialSyncResponse.SyncKey + "</SyncKey><CollectionId>1</CollectionId><WindowSize>512</WindowSize><Options><BodyPreference xmlns=\"AirSyncBase\"><Type>2</Type></BodyPreference></Options><Commands><Add><ClientId>54353</ClientId><ApplicationData><Subject xmlns=\"Calendar\">TestMail</Subject><MeetingStatus xmlns=\"Calendar\">1</MeetingStatus><UID xmlns=\"Calendar\">040000008200E00074C5B7101A82E00800000000B0CD1F52EBBDC901000000000000000010000000B05E442FCB2CA443BF3D99B51A729FE6</UID><Timezone xmlns=\"Calendar\">IP7//ygAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</Timezone><Attendees xmlns=\"Calendar\"><Attendee><Email>[email protected]</Email><Name>EAS_User02</Name><AttendeeStatus>3</AttendeeStatus><AttendeeType>1</AttendeeType></Attendee></Attendees><Recurrence xmlns=\"Calendar\"><Type>" + type + "</Type><Occurrences>3</Occurrences><Interval>0</Interval><WeekOfMonth>1</WeekOfMonth><DayOfWeek>1</DayOfWeek><CalendarType>1</CalendarType><CalendarType>2</CalendarType></Recurrence><ResponseRequested xmlns=\"Calendar\">1</ResponseRequested><Reminder xmlns=\"Calendar\">10</Reminder></ApplicationData></Add></Commands></Collection></Collections></Sync>"); break; case "5": // [email protected] in string request is a sample email address of an attendee, nothing will be sent to this mailbox. sendStringResponse = this.CALAdapter.SendStringRequest("<?xml version=\"1.0\" encoding=\"utf-8\"?><Sync xmlns=\"AirSync\"><Collections><Collection><SyncKey>" + initialSyncResponse.SyncKey + "</SyncKey><CollectionId>1</CollectionId><WindowSize>512</WindowSize><Options><BodyPreference xmlns=\"AirSyncBase\"><Type>2</Type></BodyPreference></Options><Commands><Add><ClientId>54353</ClientId><ApplicationData><Subject xmlns=\"Calendar\">TestMail</Subject><MeetingStatus xmlns=\"Calendar\">1</MeetingStatus><UID xmlns=\"Calendar\">040000008200E00074C5B7101A82E00800000000B0CD1F52EBBDC901000000000000000010000000B05E442FCB2CA443BF3D99B51A729FE6</UID><Timezone xmlns=\"Calendar\">IP7//ygAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</Timezone><Attendees xmlns=\"Calendar\"><Attendee><Email>[email protected]</Email><Name>EAS_User02</Name><AttendeeStatus>3</AttendeeStatus><AttendeeType>1</AttendeeType></Attendee></Attendees><Recurrence xmlns=\"Calendar\"><Type>" + type + "</Type><Occurrences>3</Occurrences><Interval>0</Interval><DayOfMonth>1</DayOfMonth><MonthOfYear>1</MonthOfYear><CalendarType>1</CalendarType><CalendarType>2</CalendarType></Recurrence><ResponseRequested xmlns=\"Calendar\">1</ResponseRequested><Reminder xmlns=\"Calendar\">10</Reminder></ApplicationData></Add></Commands></Collection></Collections></Sync>"); break; case "6": // [email protected] in string request is a sample email address of an attendee, nothing will be sent to this mailbox. sendStringResponse = this.CALAdapter.SendStringRequest("<?xml version=\"1.0\" encoding=\"utf-8\"?><Sync xmlns=\"AirSync\"><Collections><Collection><SyncKey>" + initialSyncResponse.SyncKey + "</SyncKey><CollectionId>1</CollectionId><WindowSize>512</WindowSize><Options><BodyPreference xmlns=\"AirSyncBase\"><Type>2</Type></BodyPreference></Options><Commands><Add><ClientId>54353</ClientId><ApplicationData><Subject xmlns=\"Calendar\">TestMail</Subject><MeetingStatus xmlns=\"Calendar\">1</MeetingStatus><UID xmlns=\"Calendar\">040000008200E00074C5B7101A82E00800000000B0CD1F52EBBDC901000000000000000010000000B05E442FCB2CA443BF3D99B51A729FE6</UID><Timezone xmlns=\"Calendar\">IP7//ygAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</Timezone><Attendees xmlns=\"Calendar\"><Attendee><Email>[email protected]</Email><Name>EAS_User02</Name><AttendeeStatus>3</AttendeeStatus><AttendeeType>1</AttendeeType></Attendee></Attendees><Recurrence xmlns=\"Calendar\"><Type>" + type + "</Type><Occurrences>3</Occurrences><Interval>0</Interval><WeekOfMonth>1</WeekOfMonth><MonthOfYear>1</MonthOfYear><CalendarType>1</CalendarType><CalendarType>2</CalendarType></Recurrence><ResponseRequested xmlns=\"Calendar\">1</ResponseRequested><Reminder xmlns=\"Calendar\">10</Reminder></ApplicationData></Add></Commands></Collection></Collections></Sync>"); break; } SyncStore response = new SyncStore(); XmlDocument doc = new XmlDocument(); doc.LoadXml(sendStringResponse.ResponseDataXML); XmlNodeList nodes = doc.DocumentElement.GetElementsByTagName("Collection"); foreach (XmlNode node in nodes) { foreach (XmlNode item in node.ChildNodes) { if (item.Name == "SyncKey") { response.SyncKey = item.InnerText; } if (item.Name == "CollectionId") { response.CollectionId = item.InnerText; } if (item.Name == "Status") { response.CollectionStatus = byte.Parse(item.InnerText); } if (item.Name == "Responses") { foreach (XmlNode add in item) { if (add.Name == "Add") { Response.SyncCollectionsCollectionResponsesAdd res = new Response.SyncCollectionsCollectionResponsesAdd(); foreach (XmlNode additem in add) { if (additem.Name == "ClientId") { res.ClientId = additem.InnerText; } if (additem.Name == "ServerId") { res.ServerId = additem.InnerText; } if (additem.Name == "Status") { res.Status = additem.InnerText; } } response.AddResponses.Add(res); } } } } } return response; }
/// <summary> /// A method that send out string command request that contains multiple CalendarType elements in Recurrence. /// </summary> /// <param name="type">value of Type element in Recurrence.</param> /// <returns>Command response of sending </returns> public SyncStore AddCalendarWithMultipleCalendarType(string type) { SyncStore initialSyncResponse = this.InitializeSync(this.CurrentUserInformation.CalendarCollectionId, null); SendStringResponse sendStringResponse = new SendStringResponse(); switch (type) { case "2": // [email protected] in string request is a sample email address of an attendee, nothing will be sent to this mailbox. sendStringResponse = this.CALAdapter.SendStringRequest("<?xml version=\"1.0\" encoding=\"utf-8\"?><Sync xmlns=\"AirSync\"><Collections><Collection><SyncKey>" + initialSyncResponse.SyncKey + "</SyncKey><CollectionId>1</CollectionId><WindowSize>512</WindowSize><Options><BodyPreference xmlns=\"AirSyncBase\"><Type>2</Type></BodyPreference></Options><Commands><Add><ClientId>54353</ClientId><ApplicationData><Subject xmlns=\"Calendar\">TestMail</Subject><MeetingStatus xmlns=\"Calendar\">1</MeetingStatus><UID xmlns=\"Calendar\">040000008200E00074C5B7101A82E00800000000B0CD1F52EBBDC901000000000000000010000000B05E442FCB2CA443BF3D99B51A729FE6</UID><Timezone xmlns=\"Calendar\">IP7//ygAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</Timezone><Attendees xmlns=\"Calendar\"><Attendee><Email>[email protected]</Email><Name>EAS_User02</Name><AttendeeStatus>3</AttendeeStatus><AttendeeType>1</AttendeeType></Attendee></Attendees><Recurrence xmlns=\"Calendar\"><Type>" + type + "</Type><Occurrences>3</Occurrences><Interval>0</Interval><DayOfMonth>1</DayOfMonth><CalendarType>1</CalendarType><CalendarType>2</CalendarType></Recurrence><ResponseRequested xmlns=\"Calendar\">1</ResponseRequested><Reminder xmlns=\"Calendar\">10</Reminder></ApplicationData></Add></Commands></Collection></Collections></Sync>"); break; case "3": // [email protected] in string request is a sample email address of an attendee, nothing will be sent to this mailbox. sendStringResponse = this.CALAdapter.SendStringRequest("<?xml version=\"1.0\" encoding=\"utf-8\"?><Sync xmlns=\"AirSync\"><Collections><Collection><SyncKey>" + initialSyncResponse.SyncKey + "</SyncKey><CollectionId>1</CollectionId><WindowSize>512</WindowSize><Options><BodyPreference xmlns=\"AirSyncBase\"><Type>2</Type></BodyPreference></Options><Commands><Add><ClientId>54353</ClientId><ApplicationData><Subject xmlns=\"Calendar\">TestMail</Subject><MeetingStatus xmlns=\"Calendar\">1</MeetingStatus><UID xmlns=\"Calendar\">040000008200E00074C5B7101A82E00800000000B0CD1F52EBBDC901000000000000000010000000B05E442FCB2CA443BF3D99B51A729FE6</UID><Timezone xmlns=\"Calendar\">IP7//ygAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</Timezone><Attendees xmlns=\"Calendar\"><Attendee><Email>[email protected]</Email><Name>EAS_User02</Name><AttendeeStatus>3</AttendeeStatus><AttendeeType>1</AttendeeType></Attendee></Attendees><Recurrence xmlns=\"Calendar\"><Type>" + type + "</Type><Occurrences>3</Occurrences><Interval>0</Interval><WeekOfMonth>1</WeekOfMonth><DayOfWeek>1</DayOfWeek><CalendarType>1</CalendarType><CalendarType>2</CalendarType></Recurrence><ResponseRequested xmlns=\"Calendar\">1</ResponseRequested><Reminder xmlns=\"Calendar\">10</Reminder></ApplicationData></Add></Commands></Collection></Collections></Sync>"); break; case "5": // [email protected] in string request is a sample email address of an attendee, nothing will be sent to this mailbox. sendStringResponse = this.CALAdapter.SendStringRequest("<?xml version=\"1.0\" encoding=\"utf-8\"?><Sync xmlns=\"AirSync\"><Collections><Collection><SyncKey>" + initialSyncResponse.SyncKey + "</SyncKey><CollectionId>1</CollectionId><WindowSize>512</WindowSize><Options><BodyPreference xmlns=\"AirSyncBase\"><Type>2</Type></BodyPreference></Options><Commands><Add><ClientId>54353</ClientId><ApplicationData><Subject xmlns=\"Calendar\">TestMail</Subject><MeetingStatus xmlns=\"Calendar\">1</MeetingStatus><UID xmlns=\"Calendar\">040000008200E00074C5B7101A82E00800000000B0CD1F52EBBDC901000000000000000010000000B05E442FCB2CA443BF3D99B51A729FE6</UID><Timezone xmlns=\"Calendar\">IP7//ygAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</Timezone><Attendees xmlns=\"Calendar\"><Attendee><Email>[email protected]</Email><Name>EAS_User02</Name><AttendeeStatus>3</AttendeeStatus><AttendeeType>1</AttendeeType></Attendee></Attendees><Recurrence xmlns=\"Calendar\"><Type>" + type + "</Type><Occurrences>3</Occurrences><Interval>0</Interval><DayOfMonth>1</DayOfMonth><MonthOfYear>1</MonthOfYear><CalendarType>1</CalendarType><CalendarType>2</CalendarType></Recurrence><ResponseRequested xmlns=\"Calendar\">1</ResponseRequested><Reminder xmlns=\"Calendar\">10</Reminder></ApplicationData></Add></Commands></Collection></Collections></Sync>"); break; case "6": // [email protected] in string request is a sample email address of an attendee, nothing will be sent to this mailbox. sendStringResponse = this.CALAdapter.SendStringRequest("<?xml version=\"1.0\" encoding=\"utf-8\"?><Sync xmlns=\"AirSync\"><Collections><Collection><SyncKey>" + initialSyncResponse.SyncKey + "</SyncKey><CollectionId>1</CollectionId><WindowSize>512</WindowSize><Options><BodyPreference xmlns=\"AirSyncBase\"><Type>2</Type></BodyPreference></Options><Commands><Add><ClientId>54353</ClientId><ApplicationData><Subject xmlns=\"Calendar\">TestMail</Subject><MeetingStatus xmlns=\"Calendar\">1</MeetingStatus><UID xmlns=\"Calendar\">040000008200E00074C5B7101A82E00800000000B0CD1F52EBBDC901000000000000000010000000B05E442FCB2CA443BF3D99B51A729FE6</UID><Timezone xmlns=\"Calendar\">IP7//ygAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAVQBUAEMAKwAwADgAOgAwADAAKQAgAEIAZQBpAGoAaQBuAGcALAAgAEMAaABvAG4AZwBxAGkAbgBnACwAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</Timezone><Attendees xmlns=\"Calendar\"><Attendee><Email>[email protected]</Email><Name>EAS_User02</Name><AttendeeStatus>3</AttendeeStatus><AttendeeType>1</AttendeeType></Attendee></Attendees><Recurrence xmlns=\"Calendar\"><Type>" + type + "</Type><Occurrences>3</Occurrences><Interval>0</Interval><WeekOfMonth>1</WeekOfMonth><MonthOfYear>1</MonthOfYear><CalendarType>1</CalendarType><CalendarType>2</CalendarType></Recurrence><ResponseRequested xmlns=\"Calendar\">1</ResponseRequested><Reminder xmlns=\"Calendar\">10</Reminder></ApplicationData></Add></Commands></Collection></Collections></Sync>"); break; } SyncStore response = new SyncStore(); XmlDocument doc = new XmlDocument(); doc.LoadXml(sendStringResponse.ResponseDataXML); XmlNodeList nodes = doc.DocumentElement.GetElementsByTagName("Collection"); foreach (XmlNode node in nodes) { foreach (XmlNode item in node.ChildNodes) { if (item.Name == "SyncKey") { response.SyncKey = item.InnerText; } if (item.Name == "CollectionId") { response.CollectionId = item.InnerText; } if (item.Name == "Status") { response.CollectionStatus = byte.Parse(item.InnerText); } if (item.Name == "Responses") { foreach (XmlNode add in item) { if (add.Name == "Add") { Response.SyncCollectionsCollectionResponsesAdd res = new Response.SyncCollectionsCollectionResponsesAdd(); foreach (XmlNode additem in add) { if (additem.Name == "ClientId") { res.ClientId = additem.InnerText; } if (additem.Name == "ServerId") { res.ServerId = additem.InnerText; } if (additem.Name == "Status") { res.Status = additem.InnerText; } } response.AddResponses.Add(res); } } } } } return(response); }
public void MSASHTTP_S03_TC01_SetASAcceptMultiPartRequestHeader() { #region Call SendMail command to send email to User2. // Call ConfigureRequestPrefixFields to set the QueryValueType to PlainText. IDictionary <HTTPPOSTRequestPrefixField, string> requestPrefix = new Dictionary <HTTPPOSTRequestPrefixField, string>(); requestPrefix.Add(HTTPPOSTRequestPrefixField.QueryValueType, QueryValueType.PlainText.ToString()); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); // Call FolderSync command to synchronize the collection hierarchy. this.CallFolderSyncCommand(); string sendMailSubject = Common.GenerateResourceName(Site, "SendMail"); string userOneMailboxAddress = Common.GetMailAddress(this.UserOneInformation.UserName, this.UserOneInformation.UserDomain); string userTwoMailboxAddress = Common.GetMailAddress(this.UserTwoInformation.UserName, this.UserTwoInformation.UserDomain); // Call SendMail command. this.CallSendMailCommand(userOneMailboxAddress, userTwoMailboxAddress, sendMailSubject, null); #endregion #region Get the received email. // Call ConfigureRequestPrefixFields to switch the credential to User2 and synchronize the collection hierarchy. this.SwitchUser(this.UserTwoInformation, true); this.AddCreatedItemToCollection("User2", this.UserTwoInformation.InboxCollectionId, sendMailSubject); // Call Sync command to get the received email. string itemServerId = this.LoopToSyncItem(this.UserTwoInformation.InboxCollectionId, sendMailSubject, true); #endregion #region Call ItemOperation command with setting MS-ASAcceptMultiPart header to "T". // Call ConfigureRequestPrefixFields to set MS-ASAcceptMultiPart header to "T". requestPrefix.Add(HTTPPOSTRequestPrefixField.AcceptMultiPart, "T"); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); // Call ItemOperation command to fetch the received email. SendStringResponse itemOperationResponse = this.CallItemOperationsCommand(this.UserTwoInformation.InboxCollectionId, itemServerId, false); Site.Assert.IsNotNull(itemOperationResponse.Headers["Content-Type"], "The Content-Type header should not be null."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R154"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R154 // The content is in multipart, so this requirement can be captured. Site.CaptureRequirementIfAreEqual <string>( "application/vnd.ms-sync.multipart", itemOperationResponse.Headers["Content-Type"], 154, @"[In MS-ASAcceptMultiPart] If this [MS-ASAcceptMultiPart] header is present and the value is 'T', the client is requesting that the server return content in multipart format."); #endregion #region Call ItemOperation command with setting MS-ASAcceptMultiPart header to "F". // Call ConfigureRequestPrefixFields to change the MS-ASAcceptMultiPart header to "F". requestPrefix[HTTPPOSTRequestPrefixField.AcceptMultiPart] = "F"; this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); // Call ItemOperation command to fetch the received email. itemOperationResponse = this.CallItemOperationsCommand(this.UserTwoInformation.InboxCollectionId, itemServerId, false); Site.Assert.IsNotNull(itemOperationResponse.Headers["Content-Type"], "The Content-Type header should not be null."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R440"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R440 // The content is not in multipart, so this requirement can be captured. Site.CaptureRequirementIfAreNotEqual <string>( "application/vnd.ms-sync.multipart", itemOperationResponse.Headers["Content-Type"], 440, @"[In MS-ASAcceptMultiPart] If the [MS-ASAcceptMultiPart] header [is not present, or] is present and set to 'F', the client is requesting that the server return content in inline format."); #endregion #region Call ItemOperation command with setting MS-ASAcceptMultiPart header to null. // Call ConfigureRequestPrefixFields to change the MS-ASAcceptMultiPart header to null. requestPrefix[HTTPPOSTRequestPrefixField.AcceptMultiPart] = null; this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); // Call ItemOperation command to fetch the received email. itemOperationResponse = this.CallItemOperationsCommand(this.UserTwoInformation.InboxCollectionId, itemServerId, false); Site.Assert.IsNotNull(itemOperationResponse.Headers["Content-Type"], "The Content-Type header should not be null."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R155"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R155 // The content is not in multipart, so this requirement can be captured. Site.CaptureRequirementIfAreNotEqual <string>( "application/vnd.ms-sync.multipart", itemOperationResponse.Headers["Content-Type"], 155, @"[In MS-ASAcceptMultiPart] If the [MS-ASAcceptMultiPart] header is not present [, or is present and set to 'F'], the client is requesting that the server return content in inline format."); #endregion #region Reset the query value type and credential. requestPrefix[HTTPPOSTRequestPrefixField.QueryValueType] = Common.GetConfigurationPropertyValue("HeaderEncodingType", this.Site); this.HTTPAdapter.ConfigureRequestPrefixFields(requestPrefix); this.SwitchUser(this.UserOneInformation, false); #endregion }
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 }
/// <summary> /// Verify requirements about HTTP POST response. /// </summary> /// <param name="postResponse">The HTTP POST response.</param> private void VerifyHTTPPOSTResponse(SendStringResponse postResponse) { // Verify MS-ASHTTP requirement: MS-ASHTTP_R175 Site.CaptureRequirementIfAreEqual <HttpStatusCode>( HttpStatusCode.OK, postResponse.StatusCode, 175, @"[In Status Line] [Status code] 200 OK [is described as] the command succeeded."); if (Common.IsRequirementEnabled(476, Site)) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R476"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R476 // The response is returned successfully and the StatusCode is OK, so this requirement can be captured. Site.CaptureRequirement( 476, @"[In Appendix A: Product Behavior] Implementation does format a response to the request as specified in section 2.2.2 with an appropriate HTTP status code as specified in section 2.2.2.1.1. (Exchange 2007 SP1 and above follow this behavior.)"); } this.VerifyHTTPResponse(); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R1"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R1 // The HTTP POST command executes successfully, so this requirement can be captured. Site.CaptureRequirement( 1, @"[In Transport] Messages are transported by using HTTP POST, as specified in [RFC2616]."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R167"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R167 // The HTTP POST command executes successfully and the HTTP POST response is not null, so this requirement can be captured. Site.CaptureRequirement( 167, @"[In HTTP POST Response] After receiving and interpreting a request, a server responds with an HTTP response that contains data returned from the server."); // GetAttachment command response doesn't contain xml format data, so GetAttachment command response is excluded from this capture. if (!string.IsNullOrEmpty(postResponse.ResponseDataXML) && !postResponse.ResponseDataXML.Contains("PNG")) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R169"); Site.Log.Add(LogEntryKind.Debug, "The ResponseDataXML of HTTP POST command is {0}.", postResponse.ResponseDataXML); // Verify MS-ASHTTP requirement: MS-ASHTTP_R169 // The HTTP POST command execute successfully, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( postResponse.ResponseDataXML.Contains("utf-8"), 169, @"[In Response Format] Note that these [HTTP POST] responses are UTF-8 encoded."); } // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R170"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R170 // The HTTP POST command executes successfully and raw http response is converted successfully, so this requirement can be captured. Site.CaptureRequirement( 170, @"[In Response Format] As specified by [RFC2616], the format [of the command response] is the same as for the following requests. Status-line Response-headers CR/LF Message Body"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R172"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R172 // The HTTP POST command executes successfully and raw http response is converted successfully, so this requirement can be captured. Site.CaptureRequirement( 172, @"[In Status Line] The status line consists of the HTTP version and a status code."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R228"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R228 // The HTTP POST command executes successfully and raw http response is converted successfully, so this requirement can be captured. Site.CaptureRequirement( 228, @"[In Response Body] The response body contains data returned from the server."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R281"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R281 // The HTTP POST command executes successfully, so this requirement can be captured. Site.CaptureRequirement( 281, @"[In Message Processing Events and Sequencing Rules] The server can receive HTTP POST requests (section 2.2.1) [or HTTP OPTIONS requests (section 2.2.3)] from the client."); this.VerifyHTTPPOSTHeaders(postResponse); }
/// <summary> /// Extract Add elements from a Sync string response. /// </summary> /// <param name="sendStringResponse">The returned SendStringResponse object.</param> /// <returns>The extracted SyncStore object.</returns> protected SyncStore ExtractSyncStore(SendStringResponse sendStringResponse) { SyncStore response = new SyncStore(); XmlDocument doc = new XmlDocument(); doc.LoadXml(sendStringResponse.ResponseDataXML); XmlNodeList nodes = doc.DocumentElement.GetElementsByTagName("Collection"); foreach (XmlNode node in nodes) { foreach (XmlNode item in node.ChildNodes) { if (item.Name == "Responses") { foreach (XmlNode add in item) { if (add.Name == "Add") { Response.SyncCollectionsCollectionResponsesAdd responseData = new Response.SyncCollectionsCollectionResponsesAdd(); foreach (XmlNode addItem in add) { if (addItem.Name == "Status") { responseData.Status = addItem.InnerText; } } response.AddResponses.Add(responseData); } } } } } return response; }
/// <summary> /// Send a Sync command string request and get Sync response from server. /// </summary> /// <param name="stringRequest">The request for Sync command</param> /// <returns>The Sync response which is returned from server</returns> public SendStringResponse SendStringRequest(string stringRequest) { SendStringResponse response = this.activeSyncClient.SendStringRequest(CommandName.Sync, null, stringRequest); return(response); }
/// <summary> /// Verify requirements about HTTP POST response. /// </summary> /// <param name="postResponse">The HTTP POST response.</param> private void VerifyHTTPPOSTResponse(SendStringResponse postResponse) { // Verify MS-ASHTTP requirement: MS-ASHTTP_R175 Site.CaptureRequirementIfAreEqual<HttpStatusCode>( HttpStatusCode.OK, postResponse.StatusCode, 175, @"[In Status Line] [Status code] 200 OK [is described as] the command succeeded."); if (Common.IsRequirementEnabled(476, Site)) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R476"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R476 // The response is returned successfully and the StatusCode is OK, so this requirement can be captured. Site.CaptureRequirement( 476, @"[In Appendix A: Product Behavior] Implementation does format a response to the request as specified in section 2.2.2 with an appropriate HTTP status code as specified in section 2.2.2.1.1. (Exchange 2007 SP1 and above follow this behavior.)"); } this.VerifyHTTPResponse(); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R1"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R1 // The HTTP POST command executes successfully, so this requirement can be captured. Site.CaptureRequirement( 1, @"[In Transport] Messages are transported by using HTTP POST, as specified in [RFC2616]."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R167"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R167 // The HTTP POST command executes successfully and the HTTP POST response is not null, so this requirement can be captured. Site.CaptureRequirement( 167, @"[In HTTP POST Response] After receiving and interpreting a request, a server responds with an HTTP response that contains data returned from the server."); // GetAttachment command response doesn't contain xml format data, so GetAttachment command response is excluded from this capture. if (!string.IsNullOrEmpty(postResponse.ResponseDataXML) && !postResponse.ResponseDataXML.Contains("PNG")) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R169"); Site.Log.Add(LogEntryKind.Debug, "The ResponseDataXML of HTTP POST command is {0}.", postResponse.ResponseDataXML); // Verify MS-ASHTTP requirement: MS-ASHTTP_R169 // The HTTP POST command execute successfully, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( postResponse.ResponseDataXML.Contains("utf-8"), 169, @"[In Response Format] Note that these [HTTP POST] responses are UTF-8 encoded."); } // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R170"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R170 // The HTTP POST command executes successfully and raw http response is converted successfully, so this requirement can be captured. Site.CaptureRequirement( 170, @"[In Response Format] As specified by [RFC2616], the format [of the command response] is the same as for the following requests. Status-line Response-headers CR/LF Message Body"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R172"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R172 // The HTTP POST command executes successfully and raw http response is converted successfully, so this requirement can be captured. Site.CaptureRequirement( 172, @"[In Status Line] The status line consists of the HTTP version and a status code."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R228"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R228 // The HTTP POST command executes successfully and raw http response is converted successfully, so this requirement can be captured. Site.CaptureRequirement( 228, @"[In Response Body] The response body contains data returned from the server."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASHTTP_R281"); // Verify MS-ASHTTP requirement: MS-ASHTTP_R281 // The HTTP POST command executes successfully, so this requirement can be captured. Site.CaptureRequirement( 281, @"[In Message Processing Events and Sequencing Rules] The server can receive HTTP POST requests (section 2.2.1) [or HTTP OPTIONS requests (section 2.2.3)] from the client."); this.VerifyHTTPPOSTHeaders(postResponse); }
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 }