public void MSASCMD_S21_TC13_CommonStatusCode_150()
        {
            Site.Assume.AreNotEqual <string>("12.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "This test case is not supported when the MS-ASProtocolVersion header is set to 12.1.. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");

            #region Call SendMail command to send plain text email messages to user2.
            string emailSubject = Common.GenerateResourceName(Site, "subject");
            this.SendPlainTextEmail(null, emailSubject, this.User1Information.UserName, this.User2Information.UserName, null);
            #endregion

            #region Call Sync command to sync user2 mailbox changes
            this.SwitchUser(this.User2Information);
            SyncResponse syncChangeResponse = this.GetMailItem(this.User2Information.InboxCollectionId, emailSubject);
            string       originalServerID   = TestSuiteBase.FindServerId(syncChangeResponse, "Subject", emailSubject);
            string       originalContent    = TestSuiteBase.GetDataFromResponseBodyElement(syncChangeResponse, originalServerID);
            #endregion

            #region Record user name, folder collectionId and item subject that are used in this case
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject);
            #endregion

            #region Call Sync command to delete the email in user2's mailbox.
            SyncRequest syncRequest = TestSuiteBase.CreateSyncDeleteRequest(this.LastSyncKey, this.User2Information.InboxCollectionId, originalServerID);
            syncRequest.RequestData.Collections[0].DeletesAsMoves          = false;
            syncRequest.RequestData.Collections[0].DeletesAsMovesSpecified = true;
            this.Sync(syncRequest);
            #endregion

            #region Call SmartForward command to forward messages without retrieving the full, original message from the server.
            string forwardSubject  = string.Format("FW:{0}", emailSubject);
            string forwardFromUser = Common.GetMailAddress(this.User2Information.UserName, this.User2Information.UserDomain);
            string forwardToUser   = Common.GetMailAddress(this.User3Information.UserName, this.User3Information.UserDomain);
            string forwardContent  = Common.GenerateResourceName(Site, "forward:body");

            SmartForwardRequest  smartForwardRequest  = this.CreateSmartForwardRequest(this.User2Information.InboxCollectionId, originalServerID, forwardFromUser, forwardToUser, string.Empty, string.Empty, forwardSubject, forwardContent);
            SmartForwardResponse smartForwardResponse = this.CMDAdapter.SmartForward(smartForwardRequest);
            #endregion

            this.Site.CaptureRequirementIfAreEqual <int>(
                150,
                int.Parse(smartForwardResponse.ResponseData.Status),
                4930,
                @"[In Common Status Codes] When the protocol version is 14.0, 14.1 or 16.0,  [The meaning of the status value 150 is] The value of either the ItemId element (section 2.2.3.88) or the InstanceId element (section 2.2.3.87.2) specified in the SmartReply (section 2.2.2.19) or the SmartForward (section 2.2.2.18) command request could not be found in the mailbox.");
        }
        public void MSASCMD_S06_TC02_GetAttachment_Status500()
        {
            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.");

            // Send a mail with normal attachment
            string subject = Common.GenerateResourceName(Site, "NormalAttachment_Subject");
            string body    = Common.GenerateResourceName(Site, "NormalAttachment_Body");

            this.SendEmailWithAttachment(subject, body);

            this.SwitchUser(this.User2Information);
            SyncResponse syncResponse = this.CheckEmail(this.User2Information.InboxCollectionId, subject, null);

            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, subject);

            Response.AttachmentsAttachment[] attachments = this.GetEmailAttachments(syncResponse, subject);
            Site.Assert.IsTrue(attachments != null && attachments.Length == 1, "The email should contain a single attachment.");

            GetAttachmentRequest getAttachmentRequest = new GetAttachmentRequest();

            getAttachmentRequest.SetCommandParameters(new Dictionary <CmdParameterName, object>
            {
                {
                    CmdParameterName.AttachmentName, attachments[0].FileReference
                }
            });

            GetAttachmentResponse getAttachmentResponse = this.CMDAdapter.GetAttachment(getAttachmentRequest);

            Site.Assert.AreEqual <string>("OK", getAttachmentResponse.StatusDescription, "The attachment should be retrieved successfully.");

            // Delete the email in the Inbox folder.
            syncResponse = this.SyncChanges(this.User2Information.InboxCollectionId);

            string      serverId    = TestSuiteBase.FindServerId(syncResponse, "Subject", subject);
            SyncRequest syncRequest = TestSuiteBase.CreateSyncDeleteRequest(this.LastSyncKey, this.User2Information.InboxCollectionId, serverId);

            this.Sync(syncRequest);

            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", subject), "The email should be deleted.");
            TestSuiteBase.RemoveRecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, subject);

            syncResponse = this.SyncChanges(this.User2Information.DeletedItemsCollectionId);
            Site.Assert.IsNotNull(TestSuiteBase.FindServerId(syncResponse, "Subject", subject), "The deleted email should be in the DeletedItems folder.");
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.DeletedItemsCollectionId, subject);

            try
            {
                // Call GetAttachment command again to fetch the deleted attachment.
                this.CMDAdapter.GetAttachment(getAttachmentRequest);
                Site.Assert.Fail("If the GetAttachment command is used to retrieve an attachment that has been deleted on the server, a 500 status code should be returned in the HTTP POST response.");
            }
            catch (System.Net.WebException exception)
            {
                int statusCode = ((System.Net.HttpWebResponse)exception.Response).StatusCode.GetHashCode();

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

                // Verify MS-ASCMD requirement: MS-ASCMD_R166
                Site.CaptureRequirementIfAreEqual <int>(
                    500,
                    statusCode,
                    166,
                    @"[In GetAttachment] If the GetAttachment command is used to retrieve an attachment that has been deleted on the server, a 500 status code is returned in the HTTP POST response.");
            }
        }