/// <summary>
        /// Create message each one loop In InBox
        /// </summary>
        /// <param name="logonResponse">the logon response be used to create message</param>
        /// <param name="tableHandle">The tableHanlder of the new folder</param>
        /// <param name="count">The count of created messages</param>
        /// <param name="createMessageRequest">The ROP CreateMessageRequest</param>
        /// <param name="saveChangesMessageRequest">The ROP SaveChangesMessageRequest</param>
        /// <param name="releaseRequest">The ROP ReleaseRequest</param>
        protected void CreateSingleProcessEachLoop(ref RopLogonResponse logonResponse, out uint tableHandle, int count, RopCreateMessageRequest createMessageRequest, RopSaveChangesMessageRequest saveChangesMessageRequest, RopReleaseRequest releaseRequest)
        {
            RopCreateMessageResponse createMessageResponse = new RopCreateMessageResponse();
            RopSaveChangesMessageResponse saveChangesMessageResponse = new RopSaveChangesMessageResponse();
            #region Preparing the table: CreateFolder

            // Open a folder first
            RopOpenFolderRequest openFolderRequest;
            RopOpenFolderResponse openFolderResponse;

            openFolderRequest.RopId = (byte)RopId.RopOpenFolder;

            openFolderRequest.LogonId = TestSuiteBase.LogonId;
            openFolderRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;
            openFolderRequest.OutputHandleIndex = TestSuiteBase.OutputHandleIndex1;
            openFolderRequest.FolderId = logonResponse.FolderIds[4];
            openFolderRequest.OpenModeFlags = (byte)FolderOpenModeFlags.None;

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 2: Begin to send the RopOpenFolder request.");

            this.responseSOHs = this.cropsAdapter.ProcessSingleRop(
                openFolderRequest,
                this.inputObjHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            openFolderResponse = (RopOpenFolderResponse)this.response;
            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                openFolderResponse.ReturnValue,
                "if ROP succeeds, the ReturnValue of its response is 0(success)");
            uint openedFolderHandle = this.responseSOHs[0][openFolderResponse.OutputHandleIndex];

            // Create a new subfolder in the opened folder
            // The new subfolder will be used as target folder
            RopCreateFolderRequest createFolderRequest;
            RopCreateFolderResponse createFolderResponse;

            createFolderRequest.RopId = (byte)RopId.RopCreateFolder;
            createFolderRequest.LogonId = TestSuiteBase.LogonId;
            createFolderRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;
            createFolderRequest.OutputHandleIndex = TestSuiteBase.OutputHandleIndex1;
            createFolderRequest.FolderType = (byte)FolderType.Genericfolder;
            createFolderRequest.UseUnicodeStrings = Convert.ToByte(TestSuiteBase.Zero);
            createFolderRequest.OpenExisting = TestSuiteBase.NonZero;
            createFolderRequest.Reserved = TestSuiteBase.Reserved;
            createFolderRequest.DisplayName = Encoding.ASCII.GetBytes(TestSuiteBase.DisplayNameAndCommentForNonSearchFolder + "\0");
            createFolderRequest.Comment = Encoding.ASCII.GetBytes(TestSuiteBase.DisplayNameAndCommentForNonSearchFolder + "\0");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 2: Begin to send the RopCreateFolder request.");

            this.responseSOHs = this.cropsAdapter.ProcessSingleRop(
                createFolderRequest,
                openedFolderHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            createFolderResponse = (RopCreateFolderResponse)this.response;
            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                createFolderResponse.ReturnValue,
                "if ROP succeeds, the ReturnValue of its response is 0(success)");
            uint targetFolderHandle = this.responseSOHs[0][openFolderResponse.OutputHandleIndex];
            tableHandle = this.GetContentsTableHandle(targetFolderHandle);
            ulong folderId = createFolderResponse.FolderId;

            #endregion

            #region Preparing the table: RopCreateAndSaveMessages

            int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site));
            int maxRetryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site));
            int retryCount;
            uint returnValue = 0;
            for (int i = 1; i < count; i++)
            {
                // If the RPC report error code reported by the following three ROP methods is 1726 (The remote procedure call failed), 
                // re-do the common steps of this case.
                if (returnValue == 1726)
                {
                    #region The common steps
                    // Add the debug information
                    Site.Log.Add(LogEntryKind.Debug, "If RPC error code is 1726, re-connect to server.");
                    this.cropsAdapter.RpcConnect(
                        Common.GetConfigurationPropertyValue("SutComputerName", this.Site),
                        ConnectionType.PrivateMailboxServer,
                        Common.GetConfigurationPropertyValue("UserEssdn", this.Site),
                        Common.GetConfigurationPropertyValue("Domain", this.Site),
                        Common.GetConfigurationPropertyValue("AdminUserName", this.Site),
                        Common.GetConfigurationPropertyValue("PassWord", this.Site));
                    logonResponse = this.Logon(LogonType.Mailbox, this.userDN, out this.inputObjHandle);

                    // Add the debug information
                    Site.Log.Add(LogEntryKind.Debug, "Step 2:Begin to send the RopOpenFolder request.");

                    this.responseSOHs = this.cropsAdapter.ProcessSingleRop(
                        openFolderRequest,
                        this.inputObjHandle,
                        ref this.response,
                        ref this.rawData,
                        RopResponseType.SuccessResponse);
                    openFolderResponse = (RopOpenFolderResponse)this.response;

                    Site.Assert.AreEqual<uint>(
                        TestSuiteBase.SuccessReturnValue,
                        openFolderResponse.ReturnValue,
                        "if ROP succeeds, the ReturnValue of its response is 0(success)");
                    openedFolderHandle = this.responseSOHs[0][openFolderResponse.OutputHandleIndex];

                    // Add the debug information
                    Site.Log.Add(LogEntryKind.Debug, "Step 2:Begin to send the RopCreateFolder request.");

                    this.responseSOHs = this.cropsAdapter.ProcessSingleRop(
                        createFolderRequest,
                        openedFolderHandle,
                        ref this.response,
                        ref this.rawData,
                        RopResponseType.SuccessResponse);
                    createFolderResponse = (RopCreateFolderResponse)this.response;
                    Site.Assert.AreEqual<uint>(
                        TestSuiteBase.SuccessReturnValue,
                        createFolderResponse.ReturnValue,
                        "if ROP succeeds, the ReturnValue of its response is 0(success)");
                    targetFolderHandle = this.responseSOHs[0][openFolderResponse.OutputHandleIndex];
                    tableHandle = this.GetContentsTableHandle(targetFolderHandle);
                    folderId = createFolderResponse.FolderId;
                    #endregion
                }

                #region Create message
                createMessageRequest.FolderId = folderId;

                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Step 2:Begin to send the RopCreateMessage request:loop counter i={0}", i);
                retryCount = maxRetryCount;

                do
                {
                    // Send the RopCreateMessage to create message.
                    this.responseSOHs = this.cropsAdapter.ProcessSingleRopWithReturnValue(
                        createMessageRequest,
                        this.inputObjHandle,
                        ref this.response,
                        ref this.rawData,
                        RopResponseType.SuccessResponse,
                        out returnValue);
                    System.Threading.Thread.Sleep(waitTime);
                    retryCount--;
                }
                while (this.response is RopBackoffResponse && retryCount >= 0);

                Site.Assert.IsTrue(retryCount >= 0, "The case {0} failed since server is busy and always returns RopBackoff in the response, reduce your server load and try again.", this.TestContext.TestName);

                // If the error code is 1726, continue this loop.
                if (returnValue == 1726)
                {
                    continue;
                }

                createMessageResponse = (RopCreateMessageResponse)this.response;
                Site.Assert.AreEqual<uint>(
                    TestSuiteBase.SuccessReturnValue,
                    createMessageResponse.ReturnValue,
                "if ROP succeeds, the ReturnValue of its response is 0(success)");
                uint targetMessageHandle = this.responseSOHs[0][createMessageResponse.OutputHandleIndex];
                #endregion

                #region Save message
                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Step 2:Begin to send the RopSaveChangesMessage request:loop counter i={0}", i);

                retryCount = maxRetryCount;

                // Do the loop when response is RopBackoffResponse or saveChangesMessageResponse is 0x80040401 (ecTimeout).
                do
                {
                    // Send the RopSaveChangesMessage request to save the created message.
                    this.responseSOHs = this.cropsAdapter.ProcessSingleRopWithReturnValue(
                        saveChangesMessageRequest,
                        targetMessageHandle,
                        ref this.response,
                        ref this.rawData,
                        RopResponseType.SuccessResponse,
                        out returnValue);

                    if (this.response is RopSaveChangesMessageResponse)
                    {
                        saveChangesMessageResponse = (RopSaveChangesMessageResponse)this.response;
                    }

                    System.Threading.Thread.Sleep(waitTime);
                    retryCount--;
                }
                while ((this.response is RopBackoffResponse || saveChangesMessageResponse.ReturnValue == 0x80040401) && retryCount >= 0);

                Site.Assert.IsTrue(retryCount >= 0, "The case {0} failed since server is busy and always returns RopBackoff in the response, reduce your server load and try again.", this.TestContext.TestName);

                // If the error code is 1726, continue this loop.
                if (returnValue == 1726)
                {
                    continue;
                }

                saveChangesMessageResponse = (RopSaveChangesMessageResponse)this.response;
                Site.Assert.AreEqual<uint>(
                    TestSuiteBase.SuccessReturnValue,
                    saveChangesMessageResponse.ReturnValue,
                "if ROP succeeds, the ReturnValue of its response is 0(success)");
                #endregion

                #region Release all resources
                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Step 2:Begin to send the RopRelease request.");

                retryCount = maxRetryCount;

                do
                {
                    this.responseSOHs = this.cropsAdapter.ProcessSingleRopWithReturnValue(
                        releaseRequest,
                        targetMessageHandle,
                        ref this.response,
                        ref this.rawData,
                        RopResponseType.SuccessResponse,
                        out returnValue);
                    System.Threading.Thread.Sleep(waitTime);
                    retryCount--;
                }
                while (this.response is RopBackoffResponse && retryCount >= 0);

                Site.Assert.IsTrue(retryCount >= 0, "The case {0} failed since server is busy and always returns RopBackoff in the response, reduce your server load and try again.", this.TestContext.TestName);

                // If the error code is 1726, continue this loop.
                if (returnValue == 1726)
                {
                    continue;
                }
                #endregion
            }

            // If the error code 1726 occurs on the last time of the above "for" loop, re-do the common steps.
            if (returnValue == 1726)
            {
                #region The common steps
                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "If RPC error code is 1726, re-connect to server.");
                this.cropsAdapter.RpcConnect(
                    Common.GetConfigurationPropertyValue("SutComputerName", this.Site),
                    ConnectionType.PrivateMailboxServer,
                    Common.GetConfigurationPropertyValue("UserEssdn", this.Site),
                    Common.GetConfigurationPropertyValue("Domain", this.Site),
                    Common.GetConfigurationPropertyValue("AdminUserName", this.Site),
                    Common.GetConfigurationPropertyValue("PassWord", this.Site));
                logonResponse = this.Logon(LogonType.Mailbox, this.userDN, out this.inputObjHandle);

                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Step 2:Begin to send the RopOpenFolder request.");

                this.responseSOHs = this.cropsAdapter.ProcessSingleRop(
                    openFolderRequest,
                    this.inputObjHandle,
                    ref this.response,
                    ref this.rawData,
                    RopResponseType.SuccessResponse);
                openFolderResponse = (RopOpenFolderResponse)this.response;

                Site.Assert.AreEqual<uint>(
                    TestSuiteBase.SuccessReturnValue,
                    openFolderResponse.ReturnValue,
                    "if ROP succeeds, the ReturnValue of its response is 0(success)");
                openedFolderHandle = this.responseSOHs[0][openFolderResponse.OutputHandleIndex];

                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Step 2:Begin to send the RopCreateFolder request.");

                this.responseSOHs = this.cropsAdapter.ProcessSingleRop(
                    createFolderRequest,
                    openedFolderHandle,
                    ref this.response,
                    ref this.rawData,
                    RopResponseType.SuccessResponse);
                createFolderResponse = (RopCreateFolderResponse)this.response;
                Site.Assert.AreEqual<uint>(
                    TestSuiteBase.SuccessReturnValue,
                    createFolderResponse.ReturnValue,
                    "if ROP succeeds, the ReturnValue of its response is 0(success)");
                targetFolderHandle = this.responseSOHs[0][openFolderResponse.OutputHandleIndex];
                tableHandle = this.GetContentsTableHandle(targetFolderHandle);
                folderId = createFolderResponse.FolderId;
                #endregion
            }

            #endregion
        }
        /// <summary>
        /// Create and save message.
        /// </summary>
        /// <param name="folderHandle">Folder Handle </param>
        /// <param name="folderId">Folder Id  which messages will be create in.</param>
        /// <param name="associatedFlag">Specifies whether the message is a Folder Associated Information message.</param>
        /// <param name="messageId"> Message Id which will be returned by server.</param>
        /// <param name="messageHandle">Message Handle which will be returned by server.</param>
        protected void CreateSaveMessage(uint folderHandle, ulong folderId, byte associatedFlag, ref ulong messageId, ref uint messageHandle)
        {
            // Create a Message.
            RopCreateMessageRequest createMessageRequest = new RopCreateMessageRequest();
            RopCreateMessageResponse createMessageResponse = new RopCreateMessageResponse();
            object ropResponse = null;
            createMessageRequest.RopId = (byte)RopId.RopCreateMessage;
            createMessageRequest.LogonId = Constants.CommonLogonId;
            createMessageRequest.InputHandleIndex = Constants.CommonInputHandleIndex;
            createMessageRequest.OutputHandleIndex = Constants.CommonOutputHandleIndex;
            createMessageRequest.CodePageId = 0x0FFF;
            createMessageRequest.FolderId = folderId;
            createMessageRequest.AssociatedFlag = associatedFlag;
            this.Adapter.DoRopCall(createMessageRequest, folderHandle, ref ropResponse, ref this.responseHandles);

            createMessageResponse = (RopCreateMessageResponse)ropResponse;
            Site.Assert.AreEqual<uint>(0, createMessageResponse.ReturnValue, "Creating Message should succeed");
            messageHandle = this.responseHandles[0][createMessageResponse.OutputHandleIndex];

            // Save a Message.
            RopSaveChangesMessageRequest saveChangesMessageRequest = new RopSaveChangesMessageRequest();
            RopSaveChangesMessageResponse saveChangesMessageResponse = new RopSaveChangesMessageResponse();
            saveChangesMessageRequest.RopId = (byte)RopId.RopSaveChangesMessage;
            saveChangesMessageRequest.LogonId = Constants.CommonLogonId;
            saveChangesMessageRequest.InputHandleIndex = Constants.CommonInputHandleIndex;
            saveChangesMessageRequest.ResponseHandleIndex = 0x01;
            saveChangesMessageRequest.SaveFlags = 0x0C;
            this.Adapter.DoRopCall(saveChangesMessageRequest, messageHandle, ref ropResponse, ref this.responseHandles);

            saveChangesMessageResponse = (RopSaveChangesMessageResponse)ropResponse;
            Site.Assert.AreEqual<uint>(
                0,
                createMessageResponse.ReturnValue,
                "Save Messages Success.");
            messageId = saveChangesMessageResponse.MessageId;
        }
        /// <summary>
        /// This ROP creates a Message object in a mailbox. 
        /// </summary>
        /// <param name="handle">The handle to operate.</param>
        /// <param name="folderId">This value identifies the parent folder.</param>
        /// <param name="associatedFlag">This flag specifies whether the message is a folder associated information (FAI) message.</param>
        /// <param name="createMessageResponse">The response of this ROP.</param>
        /// <param name="needVerify">Whether need to verify the response</param>
        /// <returns>The handle of the created message.</returns>
        private uint RopCreateMessage(uint handle, ulong folderId, byte associatedFlag, out RopCreateMessageResponse createMessageResponse, bool needVerify)
        {
            this.rawDataValue = null;
            this.responseValue = null;
            this.responseSOHsValue = null;

            RopCreateMessageRequest createMessageRequest = new RopCreateMessageRequest()
            {
                RopId = (byte)RopId.RopCreateMessage,
                LogonId = LogonId,
                InputHandleIndex = (byte)HandleIndex.FirstIndex,
                OutputHandleIndex = (byte)HandleIndex.SecondIndex,
                CodePageId = (ushort)CodePageId.SameAsLogonObject,
                FolderId = folderId,
                AssociatedFlag = associatedFlag
            };

            this.responseSOHsValue = this.ProcessSingleRop(createMessageRequest, handle, ref this.responseValue, ref this.rawDataValue, RopResponseType.SuccessResponse);
            createMessageResponse = (RopCreateMessageResponse)this.responseValue;
            if (needVerify)
            {
                this.Site.Assert.AreEqual((uint)RopResponseType.SuccessResponse, createMessageResponse.ReturnValue, string.Format("RopCreateMessageResponse Failed! Error: 0x{0:X8}", createMessageResponse.ReturnValue));
            }

            return this.responseSOHsValue[0][createMessageResponse.OutputHandleIndex];
        }
        /// <summary>
        /// Create a message and return the message handle created.
        /// </summary>
        /// <param name="serverId">A 32-bit signed integer represent the Identity of server.</param>
        /// <param name="folderHandleIndex">The folder handle index for creating message.</param>
        /// <param name="folderIdIndex">The folder Id index.</param>
        /// <param name="associatedFlag">The message is FAI or not.</param>
        /// <param name="messageHandleIndex">The created message handle index.</param>
        /// <returns>Indicate the result of this ROP operation.</returns>
        public RopResult CreateMessage(int serverId, int folderHandleIndex, int folderIdIndex, bool associatedFlag, out int messageHandleIndex)
        {
            // Initialize operation values.
            RopCreateMessageRequest createMessageRequest = new RopCreateMessageRequest();
            RopCreateMessageResponse createMessageResponse = new RopCreateMessageResponse();
            messageHandleIndex = -1;
            uint folderHandle = this.handleContainer[folderHandleIndex];
            ulong folderId = this.objectIdContainer[folderIdIndex];
            RopResult result = RopResult.InvalidParameter;

            // Construct the RopCreateMessage request.
            createMessageRequest.RopId = 0x06;
            createMessageRequest.LogonId = 0x00;
            createMessageRequest.InputHandleIndex = 0x00;
            createMessageRequest.OutputHandleIndex = 0x01;

            // Set CodePageId to 0x0FFF, which specified the code page of Logon object will be used
            createMessageRequest.CodePageId = 0x0FFF;
            createMessageRequest.FolderId = folderId;

            // If the message is a FAImessage.
            createMessageRequest.AssociatedFlag = associatedFlag ? (byte)0x01 : (byte)0x00;

            // Send request and get ROP response.
            createMessageResponse = (RopCreateMessageResponse)this.Process(serverId, createMessageRequest, folderHandle);
            result = (RopResult)createMessageResponse.ReturnValue;

            if (result == RopResult.Success)
            {
                messageHandleIndex = AdapterHelper.GetHandleIndex();
                this.handleContainer.Add(messageHandleIndex, this.responseSOHs[createMessageResponse.OutputHandleIndex]);

                this.AddRecipient(serverId, this.responseSOHs[createMessageResponse.OutputHandleIndex]);

                // Verify server Accept PidTagIdsetGivenPtypBinary
                this.VerifyServerAcceptPidTagIdsetGivenPtypBinary(serverId, folderHandleIndex);
            }

            return result;
        }
        /// <summary>
        /// Verify RopCreateMessage Failure Response
        /// </summary>
        /// <param name="ropCreateMessageResponse">The response of RopCreateMessage request</param>
        /// <param name="outputHandleIndex">The field of OutputHandleIndex in RopCreateMessage request</param>
        private void VerifyRopCreateMessageFailureResponse(RopCreateMessageResponse ropCreateMessageResponse, byte outputHandleIndex)
        {
            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCROPS_R1781");

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1781
            Site.CaptureRequirementIfAreEqual<Type>(
                typeof(byte),
                ropCreateMessageResponse.RopId.GetType(),
                1781,
                @"[In RopCreateMessage ROP Failure Response Buffer]RopId (1 byte): An unsigned integer.");

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

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1783
            Site.CaptureRequirementIfAreEqual<byte>(
                (byte)RopId.RopCreateMessage,
                ropCreateMessageResponse.RopId,
                1783,
                @"[In RopCreateMessage ROP Failure Response Buffer,RopId (1 byte)] For this[RopCreateMessage] operation, this field is set to 0x06.");

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

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1784
            Site.CaptureRequirementIfAreEqual<Type>(
                typeof(byte),
                ropCreateMessageResponse.OutputHandleIndex.GetType(),
                1784,
                @"[In RopCreateMessage ROP Failure Response Buffer]OutputHandleIndex (1 byte): An unsigned integer.");

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

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1785
            Site.CaptureRequirementIfAreEqual<byte>(
                outputHandleIndex,
                ropCreateMessageResponse.OutputHandleIndex,
                1785,
                @"[In RopCreateMessage ROP Failure Response Buffer,OutputHandleIndex (1 byte)]This index MUST be set to the value specified in the OutputHandleIndex field in the request.");

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

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1787
            Site.CaptureRequirementIfAreEqual<Type>(
                typeof(uint),
                ropCreateMessageResponse.ReturnValue.GetType(),
                1787,
                @"[In RopCreateMessage ROP Failure Response Buffer]ReturnValue (4 bytes): An unsigned integer.");

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

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1789
            Site.CaptureRequirementIfAreNotEqual<uint>(
                SuccessReturnValue,
                ropCreateMessageResponse.ReturnValue,
                1789,
                @"[In RopCreateMessage ROP Failure Response Buffer,ReturnValue (4 bytes)]For this[Failure Response] response, this field is set to a value other than 0x00000000.");
        }
        /// <summary>
        /// Verify RopCreateMessage Success Response
        /// </summary>
        /// <param name="ropCreateMessageResponse">The response of RopCreateMessage request</param>
        /// <param name="outputHandleIndex">The field of OutputHandleIndex in RopCreateMessage request</param>
        private void VerifyRopCreateMessageSuccessResponse(RopCreateMessageResponse ropCreateMessageResponse, byte outputHandleIndex)
        {
            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCROPS_R1764");

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1764
            Site.CaptureRequirementIfAreEqual<Type>(
                typeof(byte),
                ropCreateMessageResponse.RopId.GetType(),
                1764,
                @"[In RopCreateMessage ROP Success Response Buffer]RopId (1 byte): An unsigned integer.");

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

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1766
            Site.CaptureRequirementIfAreEqual<byte>(
                (byte)RopId.RopCreateMessage,
                ropCreateMessageResponse.RopId,
                1766,
                @"[In RopCreateMessage ROP Success Response Buffer,RopId (1 byte)]For this[RopCreateMessage] operation, this field is set to 0x06.");

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

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1767
            Site.CaptureRequirementIfAreEqual<Type>(
                typeof(byte),
                ropCreateMessageResponse.OutputHandleIndex.GetType(),
                1767,
                @"[In RopCreateMessage ROP Success Response Buffer]OutputHandleIndex (1 byte): An unsigned integer.");

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

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1768
            Site.CaptureRequirementIfAreEqual<byte>(
                outputHandleIndex,
                ropCreateMessageResponse.OutputHandleIndex,
                1768,
                @"[In RopCreateMessage ROP Success Response Buffer,OutputHandleIndex (1 byte)]This index MUST be set to the value specified in the OutputHandleIndex specified in field the request.");

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

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1770
            Site.CaptureRequirementIfAreEqual<Type>(
                typeof(uint),
                ropCreateMessageResponse.ReturnValue.GetType(),
                1770,
                @"[In RopCreateMessage ROP Success Response Buffer]ReturnValue (4 bytes): An unsigned integer.");

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

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1772
            Site.CaptureRequirementIfAreEqual<uint>(
                SuccessReturnValue,
                ropCreateMessageResponse.ReturnValue,
                1772,
                @"[In RopCreateMessage ROP Success Response Buffer,ReturnValue (4 bytes)]For this[Success Response] response, this field is set to 0x00000000.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCROPS_R1773,HasMessageId:{0}", ropCreateMessageResponse.HasMessageId);

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R1773
            // If HasMessageId is byte type and can be boolean type representation, then verify R1773
            bool isVerifyR1773 = (typeof(byte) == ropCreateMessageResponse.HasMessageId.GetType()) &&
                                 ((Convert.ToBoolean(ropCreateMessageResponse.HasMessageId) == true) ||
                                 (Convert.ToBoolean(ropCreateMessageResponse.HasMessageId) == false));

            Site.CaptureRequirementIfIsTrue(
                isVerifyR1773,
                1773,
                @"[In RopCreateMessage ROP Success Response Buffer]HasMessageId (1 byte): A Boolean.");

            if (ropCreateMessageResponse.HasMessageId != 0)
            {
                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCROPS_R1775");

                // Verify MS-OXCROPS requirement: MS-OXCROPS_R1775
                Site.CaptureRequirementIfAreEqual<int>(
                    8,
                    Marshal.SizeOf(ropCreateMessageResponse.MessageId),
                    1775,
                    @"[In RopCreateMessage ROP Success Response Buffer]MessageId (8 bytes): An identifier.");
            }
        }
        /// <summary>
        /// Get Created Message Handle
        /// </summary>
        /// <param name="folderId">The folder Id be used to create message</param>
        /// <param name="logonHandle">The RopLogon object handle</param>
        /// <param name="createMessageResponse">The response of calling RopCreateMessage</param>
        /// <returns>Return created Message Handle</returns>
        protected uint CreatedMessage(ulong folderId, uint logonHandle, out RopCreateMessageResponse createMessageResponse)
        {
            // Create a message object first
            RopCreateMessageRequest createMessageRequest = new RopCreateMessageRequest
            {
                RopId = (byte)RopId.RopCreateMessage,
                LogonId = CommonLogonId,
                InputHandleIndex = CommonInputHandleIndex,
                OutputHandleIndex = CommonOutputHandleIndex,
                CodePageId = 0x0FFF,
                FolderId = folderId,
                AssociatedFlag = 0x00
            };

            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(createMessageRequest, logonHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            createMessageResponse = (RopCreateMessageResponse)this.response;
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, createMessageResponse.ReturnValue, "Call RopCreateMessage should success.");

            // Get handle of message object, it will be used as input handle in next ROP
            uint messageHandle = this.ResponseSOHs[0][createMessageResponse.OutputHandleIndex];
            return messageHandle;
        }
        /// <summary>
        /// Create Reply Template use settings in Util.cs file.
        /// It will be used by create Rule of ActioType: OP_REPLY
        /// </summary>
        /// <param name="inboxFolderHandle">The inbox folder's handle.</param>
        /// <param name="inboxFolderID">The inbox folder's ID.</param>
        /// <param name="isOOFReplyTemplate">Indicate whether the template to be created is a template for OP_REPLY or OP_OOF_REPLY .</param>
        /// <param name="templateSubject">The name of the template.</param>
        /// <param name="addedProperties">The properties that need to add to the reply template.</param>
        /// <param name="messageId">Message id of reply template message.</param>
        /// <param name="messageHandler">The reply message Handler.</param>
        /// <returns>Return the value of ReplyTemplateGUID.</returns>
        public byte[] CreateReplyTemplate(uint inboxFolderHandle, ulong inboxFolderID, bool isOOFReplyTemplate, string templateSubject, TaggedPropertyValue[] addedProperties, out ulong messageId, out uint messageHandler)
        {
            // Create a new FAI message in the inbox folder
            RopCreateMessageResponse ropCreateMessageResponse = new RopCreateMessageResponse();
            messageHandler = this.RopCreateMessage(inboxFolderHandle, inboxFolderID, Convert.ToByte(true), out ropCreateMessageResponse);

            #region Set the new created message's properties
            TaggedPropertyValue[] replyTemplateProperties = new TaggedPropertyValue[3];

            // PidTagMessageClass
            replyTemplateProperties[0] = new TaggedPropertyValue();
            PropertyTag replyTemplatePropertiesPropertyTag = new PropertyTag
            {
                PropertyType = (ushort)PropertyType.PtypString,
                PropertyId = (ushort)PropertyId.PidTagMessageClass
            };
            replyTemplateProperties[0].PropertyTag = replyTemplatePropertiesPropertyTag;
            if (isOOFReplyTemplate == true)
            {
                replyTemplateProperties[0].Value = Encoding.Unicode.GetBytes(Constants.OOFReplyTemplate + "\0");
            }
            else
            {
                replyTemplateProperties[0].Value = Encoding.Unicode.GetBytes(Constants.ReplyTemplate + "\0");
            }

            // PidTagReplyTemplateId
            replyTemplateProperties[1] = new TaggedPropertyValue();
            PropertyTag pidTagReplyTemplateIdPropertyTag = new PropertyTag
            {
                PropertyId = (ushort)PropertyId.PidTagReplyTemplateId,
                PropertyType = (ushort)PropertyType.PtypBinary
            };
            replyTemplateProperties[1].PropertyTag = pidTagReplyTemplateIdPropertyTag;
            Guid newGuid = System.Guid.NewGuid();
            replyTemplateProperties[1].Value = Common.AddInt16LengthBeforeBinaryArray(newGuid.ToByteArray());

            // PidTagSubject
            replyTemplateProperties[2] = new TaggedPropertyValue();
            PropertyTag pidTagSubjectPropertyTag = new PropertyTag
            {
                PropertyId = (ushort)PropertyId.PidTagSubject,
                PropertyType = (ushort)PropertyType.PtypString
            };
            replyTemplateProperties[2].PropertyTag = pidTagSubjectPropertyTag;
            replyTemplateProperties[2].Value = Encoding.Unicode.GetBytes(templateSubject + "\0");

            this.RopSetProperties(messageHandler, replyTemplateProperties);
            this.RopSetProperties(messageHandler, addedProperties);
            #endregion

            // Save changes of the message
            RopSaveChangesMessageResponse ropSaveChangesMessagResponse = this.RopSaveChangesMessage(messageHandler);
            messageId = ropSaveChangesMessagResponse.MessageId;
            return newGuid.ToByteArray();
        }
        /// <summary>
        /// This ROP creates a Message object in a mailbox. 
        /// </summary>
        /// <param name="handle">Handle to operate.</param>
        /// <param name="folderId">This value identifies the parent folder.</param>
        /// <param name="isFAIMessage">8-bit Boolean. This value specifies whether the message is a folder associated information (FAI) message.</param>
        /// <param name="createMessageResponse">Response of this ROP.</param>
        /// <returns>Handle of the create message.</returns>
        public uint RopCreateMessage(uint handle, ulong folderId, byte isFAIMessage, out RopCreateMessageResponse createMessageResponse)
        {
            this.rawData = null;
            this.response = null;
            this.responseSOHs = null;

            RopCreateMessageRequest req;
            req.RopId = 0x06;
            req.LogonId = 0;
            req.InputHandleIndex = 0;
            req.OutputHandleIndex = 1;
            req.CodePageId = 0x0fff;
            req.FolderId = folderId;
            req.AssociatedFlag = isFAIMessage;

            this.responseSOHs = this.DoRPCCall(req, handle, ref this.response, ref this.rawData);
            createMessageResponse = (RopCreateMessageResponse)this.response;

            return this.responseSOHs[0][createMessageResponse.OutputHandleIndex];
        }