public void MSOXCMSG_S07_TC03_ErrorCodesOfReadModifyRemoveAllRecipients()
        {
            this.CheckMapiHttpIsSupported();
            this.ConnectToServer(ConnectionType.PrivateMailboxServer);

            #region Call RopLogon to log on a mailbox.
            RopLogonResponse logonResponse = this.Logon(LogonType.Mailbox, out this.insideObjHandle);
            #endregion

            #region Call RopCreateMessage to create a message
            uint targetMessageHandle = this.CreatedMessage(logonResponse.FolderIds[4], this.insideObjHandle);
            #endregion

            #region Call RopModifyRecipient to modify the recipient and expect error code 0x000004B9 is returned.
            // Initialize TestUser1 
            PropertyTag[] propertyTag = this.CreateRecipientColumns();
            List<ModifyRecipientRow> modifyRecipientRow = new List<ModifyRecipientRow>
            {
                this.CreateModifyRecipientRow(TestUser1, 0)
            };

            RopModifyRecipientsResponse modifyRecipientsResponse;

            RopModifyRecipientsRequest modifyRecipientsRequest = new RopModifyRecipientsRequest
            {
                RopId = (byte)RopId.RopModifyRecipients,
                LogonId = CommonLogonId,
                InputHandleIndex = CommonInputHandleIndex,
                ColumnCount = Convert.ToUInt16(propertyTag.Length),
                RowCount = Convert.ToUInt16(modifyRecipientRow.Count),
                RecipientColumns = propertyTag,
                RecipientRows = modifyRecipientRow.ToArray()
            };

            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(modifyRecipientsRequest, TestSuiteBase.InvalidInputHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            modifyRecipientsResponse = (RopModifyRecipientsResponse)this.response;

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R1982");
        
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R1982
            this.Site.CaptureRequirementIfAreEqual<uint>(
                0x000004B9,
                modifyRecipientsResponse.ReturnValue,
                1982,
                @"[In Receiving a RopModifyRecipients ROP Request] [ecNullObject (0x000004B9)] The value of the InputHandleIndex field on which this ROP was called does not refer to a Message object.");
            #endregion

            #region Call RopModifyRecipient to modify the recipient.
            // Initialize TestUser1 
            modifyRecipientRow.Add(this.CreateModifyRecipientRow(TestSuiteBase.TestUser1, 0));
            this.AddRecipients(modifyRecipientRow, targetMessageHandle, propertyTag, out modifyRecipientsResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, modifyRecipientsResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopSaveChangesMessage to save the message
            RopSaveChangesMessageResponse saveChangesMessageResponse;
            saveChangesMessageResponse = this.SaveMessage(targetMessageHandle, (byte)SaveFlags.ForceSave);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, saveChangesMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopOpenMessage to open the message.
            RopOpenMessageResponse openMessageResponse;
            uint openedMessageHandle = this.OpenSpecificMessage(logonResponse.FolderIds[4], saveChangesMessageResponse.MessageId, this.insideObjHandle, MessageOpenModeFlags.ReadWrite, out openMessageResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, openMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopReadRecipients with InputHandleIndex set to 0x01 (which does not refer to a Message object) to read the recipient of the created message and expect the error code 0x000004B9 (ecNullObject) is returned.
            RopReadRecipientsRequest readRecipientsRequest = new RopReadRecipientsRequest()
            {
                RopId = (byte)RopId.RopReadRecipients,
                LogonId = CommonLogonId, // The logonId 0x00 is associated with RopReadRecipients.
                InputHandleIndex = CommonInputHandleIndex, // This index specifies the location 0x00 in the Server Object Handle Table where the handle for the input Server Object is stored. 
                RowId = 0x00000000, // Starting index for the recipients to be retrieved
                Reserved = 0x0000 // Reserved value set to 0x0000 as indicated in MS-OXCMSG. 
            };
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(readRecipientsRequest, TestSuiteBase.InvalidInputHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            RopReadRecipientsResponse readRecipientsResponse = (RopReadRecipientsResponse)this.response;

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R1057");
        
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R1057
            this.Site.CaptureRequirementIfAreEqual<uint>(
                0x000004B9,
                readRecipientsResponse.ReturnValue,
                1057,
                @"[In Receiving a RopReadRecipients ROP Request] [ecNullObject (0x000004B9)] The InputHandleIndex on which this ROP [RopReadRecipients] was called does not refer to a Message object.");
            #endregion

            #region Call RopModifyRecipients and set ModifyRecipientRow.RecipientRowSize to 0x0000 and set RowId to an existing value.
            List<ModifyRecipientRow> modifyRecipientRowNew = new List<ModifyRecipientRow>
            {
                this.ChangeRecipientRowSize(TestUser1, 0, RecipientType.PrimaryRecipient, 0x0000)
            };

            this.AddRecipients(modifyRecipientRowNew, targetMessageHandle, propertyTag, out modifyRecipientsResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, modifyRecipientsResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopReadRecipients to read the recipient of the opened message.
            readRecipientsRequest.InputHandleIndex = 0x00; // This index specifies the location 0x00 in the Server Object Handle Table where the handle for the input Server Object is stored. 
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(readRecipientsRequest, targetMessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            readRecipientsResponse = (RopReadRecipientsResponse)this.response;
            Site.Assert.AreNotEqual<uint>(TestSuiteBase.Success, readRecipientsResponse.ReturnValue, "Can't find any recipient of the message");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R393");
        
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R393
            // The RowId field and associated data are not returned as part of subsequent handling of ROPs for the opened Message handle if RecipientRows is null, and then MS-OXCMSG_R393 can be verified.
            this.Site.CaptureRequirementIfIsNull(
                readRecipientsResponse.RecipientRows,
                393,
                @"[In Receiving a RopModifyRecipients ROP Request] 1. If a recipient (2) was deleted, its RowId field and associated data MUST NOT be returned as part of any subsequent handling of ROPs for the opened Message object.");
            #endregion

            #region Call RopSaveChangesMessage to save the message
            saveChangesMessageResponse = this.SaveMessage(targetMessageHandle, (byte)SaveFlags.ForceSave);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, saveChangesMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopOpenMessage to open the message
            RopOpenMessageResponse openMessageResponseNew;
            openedMessageHandle = this.OpenSpecificMessage(logonResponse.FolderIds[4], saveChangesMessageResponse.MessageId, this.insideObjHandle, MessageOpenModeFlags.ReadWrite, out openMessageResponseNew);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, openMessageResponseNew.ReturnValue, TestSuiteBase.ROPSucceedMsg);

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R391. The recipient number after adding one recipient is {0}, the recipient number after adding recipient with RecipientRowSize set to 0x0000 is {1}.", openMessageResponse.RowCount, openMessageResponseNew.RowCount);

            // MS-OXCMSG_R391 can be verified if the recipient number after adding one recipient is 1 and the recipient number after adding recipient with RecipientRowSize set to 0x0000 is 0.
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R391
            bool isVerifiedR391 = openMessageResponse.RowCount == 1 && openMessageResponseNew.RowCount == 0;
            
            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR391,
                391,
                @"[In Receiving a RopModifyRecipients ROP Request] If the value of the RecipientRowSize field in the ModifyRecipientRow structure within the RecipientRows field of the request buffer is 0x0000 then the server deletes the recipient (2) from the Message object.");
            #endregion

            #region Call RopRemoveAllRecipients with InputHandleIndex set to a nonexisting one and expect error code 0x000004B9 is returned.
            RopRemoveAllRecipientsRequest removeAllRecipientsRequest = new RopRemoveAllRecipientsRequest()
            {
                RopId = (byte)RopId.RopRemoveAllRecipients,
                LogonId = CommonLogonId, // The logonId 0x00 is associated with RopRemoveAllRecipients.
                InputHandleIndex = CommonInputHandleIndex, // This index specifies the location 0x00 in the Server Object Handle Table where the handle for the input Server Object is stored. 
                Reserved = 0x00000000
            };
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(removeAllRecipientsRequest, TestSuiteBase.InvalidInputHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            RopRemoveAllRecipientsResponse removeAllRecipientsResponse = (RopRemoveAllRecipientsResponse)this.response;

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R1493");
        
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R1493
            this.Site.CaptureRequirementIfAreEqual<uint>(
                0x000004B9,
                removeAllRecipientsResponse.ReturnValue,
                1493,
                @"[In Receiving a RopRemoveAllRecipients ROP Request] [ecNullObject (0x000004B9)] The value of the InputHandleIndex field on which this ROP [RopRemoveAllRecipients] was called does not refer to a Message object.");
            #endregion

            #region Call RopModifyRecipient to modify the recipient.
            // Initialize TestUser1 TestUser2 TestUser5 TestUser4 TestUser3
            modifyRecipientRow.Add(this.CreateModifyRecipientRow(TestSuiteBase.TestUser1, 0, RecipientType.PrimaryRecipient));
            modifyRecipientRow.Add(this.CreateModifyRecipientRow(TestUser2, 1, RecipientType.CcRecipient));
            modifyRecipientRow.Add(this.CreateModifyRecipientRow(TestUser5, 2, RecipientType.BccRecipient));
            modifyRecipientRow.Add(this.CreateModifyRecipientRow(TestUser4, 3));
            modifyRecipientRow.Add(this.CreateModifyRecipientRow(TestUser3, 4));

            this.AddRecipients(modifyRecipientRow, openedMessageHandle, propertyTag, out modifyRecipientsResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, modifyRecipientsResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopRemoveAllRecipients to remove all recipients of the opened message
            removeAllRecipientsRequest.InputHandleIndex = 0x0; // This index specifies the location 0x00 in the Server Object Handle Table where the handle for the input Server Object is stored. 
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(removeAllRecipientsRequest, openedMessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            removeAllRecipientsResponse = (RopRemoveAllRecipientsResponse)this.response;
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, removeAllRecipientsResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopReadRecipients to read the recipient of the opened message.
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(readRecipientsRequest, openedMessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            readRecipientsResponse = (RopReadRecipientsResponse)this.response;
            Site.Assert.AreNotEqual<uint>(TestSuiteBase.Success, readRecipientsResponse.ReturnValue, "Can't find any recipient of the message");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R729");
        
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R729
            // All recipients added above have been removed if RecipientRows is null, and then MS-OXCMSG_R729 can be verified.
            this.Site.CaptureRequirementIfIsNull(
                readRecipientsResponse.RecipientRows,
                729,
                @"[In RopRemoveAllRecipients ROP] The client sends the RopRemoveAllRecipients ROP request ([MS-OXCROPS] section 2.2.6.4) to delete all recipients (2) from a message.");
            #endregion

            #region Call RopRelease to release the created message.
            this.ReleaseRop(targetMessageHandle);
            #endregion
        }
        public void MSOXCMSG_S07_TC04_Transaction()
        {
            this.CheckMapiHttpIsSupported();
            this.ConnectToServer(ConnectionType.PrivateMailboxServer);

            #region Call RopLogon to log on a mailbox.
            RopLogonResponse logonResponse = this.Logon(LogonType.Mailbox, out this.insideObjHandle);
            #endregion

            #region Call RopCreateMessage to create a message
            uint targetMessageHandle = this.CreatedMessage(logonResponse.FolderIds[4], this.insideObjHandle);
            #endregion

            #region Call RopSaveChangesMessage to save the message
            RopSaveChangesMessageResponse saveChangesMessageResponse;
            saveChangesMessageResponse = this.SaveMessage(targetMessageHandle, (byte)SaveFlags.ForceSave);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, saveChangesMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopOpenMessage to open the message for the first time.
            RopOpenMessageResponse openMessageResponse;
            uint openedMessageHandle1 = this.OpenSpecificMessage(logonResponse.FolderIds[4], saveChangesMessageResponse.MessageId, this.insideObjHandle, MessageOpenModeFlags.ReadWrite, out openMessageResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, openMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopOpenMessage to open the message for the second time.
            uint openedMessageHandle2 = this.OpenSpecificMessage(logonResponse.FolderIds[4], saveChangesMessageResponse.MessageId, this.insideObjHandle, MessageOpenModeFlags.ReadWrite, out openMessageResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, openMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopModifyRecipient to modify the recipient.
            // Initialize TestUser1 TestUser2 TestUser5 TestUser4 TestUser3
            PropertyTag[] propertyTag = this.CreateRecipientColumns();
            List<ModifyRecipientRow> modifyRecipientRow = new List<ModifyRecipientRow>
            {
                this.CreateModifyRecipientRow(TestUser1, 0),
                this.CreateModifyRecipientRow(TestUser2, 1),
                this.CreateModifyRecipientRow(TestUser5, 2),
                this.CreateModifyRecipientRow(TestUser4, 3),
                this.CreateModifyRecipientRow(TestUser3, 4)
            };

            RopModifyRecipientsResponse modifyRecipientsResponse;
            this.AddRecipients(modifyRecipientRow, openedMessageHandle1, propertyTag, out modifyRecipientsResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, modifyRecipientsResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopReadRecipients to read the recipient of the created message and expect the error code 0x8004010F (ecNotFound) is returned.
            RopReadRecipientsRequest readRecipientsRequest = new RopReadRecipientsRequest()
            {
                RopId = (byte)RopId.RopReadRecipients,
                LogonId = CommonLogonId, // The logonId 0x00 is associated with RopReadRecipients.
                InputHandleIndex = CommonInputHandleIndex, // This index specifies the location 0x00 in the Server Object Handle Table where the handle for the input Server Object is stored. 
                RowId = 0x00000000, // Starting index for the recipients to be retrieved
                Reserved = 0x0000 // Set the Reserved value to 0x0000 as indicated in Open Specification. 
            };
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(readRecipientsRequest, openedMessageHandle2, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            RopReadRecipientsResponse readRecipientsResponse1 = (RopReadRecipientsResponse)this.response;
            Site.Assert.AreNotEqual<uint>(TestSuiteBase.Success, readRecipientsResponse1.ReturnValue, "Can't find any recipients of the message.");
            #endregion

            #region Call RopSaveChangesMessage to save the message
            saveChangesMessageResponse = this.SaveMessage(openedMessageHandle1, (byte)SaveFlags.ForceSave);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, saveChangesMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopOpenMessage to open the message for the third time.
            uint openedMessageHandle3 = this.OpenSpecificMessage(logonResponse.FolderIds[4], saveChangesMessageResponse.MessageId, this.insideObjHandle, MessageOpenModeFlags.ReadWrite, out openMessageResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, openMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopReadRecipients to read the recipient of the created message again and expect a successful response
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(readRecipientsRequest, openedMessageHandle3, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            RopReadRecipientsResponse readRecipientsResponse2 = (RopReadRecipientsResponse)this.response;
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, readRecipientsResponse2.ReturnValue, TestSuiteBase.ROPSucceedMsg);

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R395, readRecipientsResponse1.ReturnValue is {0}, readRecipientsResponse2.ReturnValue is {1}.", readRecipientsResponse1.ReturnValue, readRecipientsResponse2.ReturnValue);
        
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R395
            bool isVerifiedR395 = readRecipientsResponse1.ReturnValue != 0x00000000 && readRecipientsResponse2.ReturnValue == 0x00000000;
            
            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR395,
                395,
                @"[In Receiving a RopModifyRecipients ROP Request] 3. The changes made to the recipients (2) MUST NOT be included in the response buffer returned for ROP requests that apply to recipients (2) on different Message object handles.");
            #endregion

            #region Call RopOpenMessage to open the message for the fourth time
            uint openedMessageHandle4 = this.OpenSpecificMessage(logonResponse.FolderIds[4], saveChangesMessageResponse.MessageId, this.insideObjHandle, MessageOpenModeFlags.ReadWrite, out openMessageResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, openMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopRemoveAllRecipients to remove all recipients of the newly created message in step 2, and expected to get the successful response.
            RopRemoveAllRecipientsRequest removeAllRecipientsRequest = new RopRemoveAllRecipientsRequest()
            {
                RopId = (byte)RopId.RopRemoveAllRecipients,
                LogonId = CommonLogonId, // The logonId 0x00 is associated with RopRemoveAllRecipients.
                InputHandleIndex = CommonInputHandleIndex, // This index specifies the location 0x00 in the Server Object Handle Table where the handle for the input Server Object is stored. 
                Reserved = 0x00000000
            };
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(removeAllRecipientsRequest, openedMessageHandle3, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            RopRemoveAllRecipientsResponse removeAllRecipientsResponse = (RopRemoveAllRecipientsResponse)this.response;
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, removeAllRecipientsResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Use the message handle 4 to call RopReadRecipients to get all recipients of the message created in step 2.
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(readRecipientsRequest, openedMessageHandle4, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            RopReadRecipientsResponse readRecipientsResponse3 = (RopReadRecipientsResponse)this.response;
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, readRecipientsResponse3.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopSaveChangesMessage to save the message
            saveChangesMessageResponse = this.SaveMessage(openedMessageHandle3, (byte)SaveFlags.ForceSave);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, saveChangesMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopOpenMessage to open the message for the fifth time
            uint openedMessageHandle5 = this.OpenSpecificMessage(logonResponse.FolderIds[4], saveChangesMessageResponse.MessageId, this.insideObjHandle, MessageOpenModeFlags.ReadWrite, out openMessageResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, openMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Use the message handle 5 to call RopReadRecipients to get all recipients of the message created in step 2.
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(readRecipientsRequest, openedMessageHandle5, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            RopReadRecipientsResponse readRecipientsResponse4 = (RopReadRecipientsResponse)this.response;
            Site.Assert.AreNotEqual<uint>(TestSuiteBase.Success, readRecipientsResponse4.ReturnValue, "Can't find any recipients of the message.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R382. readRecipientsResponse3.ReturnValue is {0}, readRecipientsResponse3.ReturnValue is {1}.", readRecipientsResponse3.ReturnValue, readRecipientsResponse4.ReturnValue);
        
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R382
            bool isVerifiedR382 = readRecipientsResponse3.ReturnValue == 0x00000000 && readRecipientsResponse4.ReturnValue != 0x00000000;
            
            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR382,
                382,
                @"[In Receiving a RopRemoveAllRecipients ROP Request] [Until the server receives a RopSaveChangesMessage ROP request ([MS-OXCROPS] section 2.2.6.3) from the client, the server adheres to the following:] The changes made to the recipients (2) MUST NOT be included in the response buffer returned for ROP requests that apply to recipients (2) on different Message object handles.");
            #endregion

            #region Call RopRelease to release the created message.
            this.ReleaseRop(targetMessageHandle);
            #endregion
        }
        public void MSOXCMSG_S07_TC02_RecipientRowSize()
        {
            this.CheckMapiHttpIsSupported();
            this.ConnectToServer(ConnectionType.PrivateMailboxServer);

            #region Call RopLogon to log on a mailbox.
            RopLogonResponse logonResponse = this.Logon(LogonType.Mailbox, out this.insideObjHandle);
            #endregion

            #region Call RopCreateMessage to create a message.
            this.MessageHandle = this.CreatedMessage(logonResponse.FolderIds[4], this.insideObjHandle);
            #endregion

            #region Call RopReadRecipients to read the recipient of the created message and expect the error code 0x8004010F (ecNotFound) is returned.
            RopReadRecipientsRequest readRecipientsRequest = new RopReadRecipientsRequest()
            {
                RopId = (byte)RopId.RopReadRecipients,
                LogonId = CommonLogonId, // The logonId 0x00 is associated with RopReadRecipients.
                InputHandleIndex = CommonInputHandleIndex, // This index specifies the location 0x00 in the Server Object Handle Table where the handle for the input Server Object is stored. 
                RowId = 0x00000000, // Starting index for the recipients to be retrieved
                Reserved = 0x0000 // Set the Reserved value to 0x0000 as specified in Open Specification. 
            };
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(readRecipientsRequest, this.MessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            RopReadRecipientsResponse readRecipientsResponse = (RopReadRecipientsResponse)this.response;

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

            // Verify MS-OXCMSG requirement: MS-OXCMSG_R403
            this.Site.CaptureRequirementIfAreEqual<uint>(
                0x8004010f,
                readRecipientsResponse.ReturnValue,
                403,
                @"[In Receiving a RopReadRecipients ROP Request] If the message does not have recipients (2), the server returns the error ecNotFound.");
            #endregion

            #region Call RopModifyRecipient to modify the recipient.
            // Initialize TestUser1 TestUser2 TestUser5 TestUser4 TestUser3
            PropertyTag[] propertyTag = this.CreateRecipientColumns();
            List<ModifyRecipientRow> modifyRecipientRow = new List<ModifyRecipientRow>
            {
                this.CreateModifyRecipientRow(TestUser1, 0, RecipientType.PrimaryRecipient),
                this.CreateModifyRecipientRow(TestUser2, 1, RecipientType.CcRecipient),
                this.CreateModifyRecipientRow(TestUser5, 2, RecipientType.BccRecipient),
                this.CreateModifyRecipientRow(TestUser4, 3),
                this.CreateModifyRecipientRow(TestUser3, 4)
            };

            RopModifyRecipientsResponse modifyRecipientsResponse;
            this.AddRecipients(modifyRecipientRow, this.MessageHandle, propertyTag, out modifyRecipientsResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, modifyRecipientsResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopReadRecipient to read the recipient of the created message.
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(readRecipientsRequest, this.MessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            readRecipientsResponse = (RopReadRecipientsResponse)this.response;

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

            // Verify MS-OXCMSG requirement: MS-OXCMSG_R737
            this.Site.CaptureRequirementIfAreEqual<uint>(
                TestSuiteBase.Success,
                readRecipientsResponse.ReturnValue,
                737,
                @"[In RopModifyRecipients ROP] The RopModifyRecipients ROP ([MS-OXCROPS] section 2.2.6.5) modifies recipients (2) associated with the Message object.");

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

            // Verify MS-OXCMSG requirement: MS-OXCMSG_R753
            this.Site.CaptureRequirementIfAreEqual<uint>(
                TestSuiteBase.Success,
                readRecipientsResponse.ReturnValue,
                753,
                @"[In RopReadRecipients ROP] The RopReadRecipients ROP ([MS-OXCROPS] section 2.2.6.6) retrieves the recipients (2) associated with the Message object.");

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

            // Five recipients have been added in the above step, so MS-OXCMSG_R394 can be verified if the RowCount == 5.
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R394
            this.Site.CaptureRequirementIfAreEqual<byte>(
                5,
                readRecipientsResponse.RowCount,
                394,
                @"[In Receiving a RopModifyRecipients ROP Request] 2. Any changes made to the recipients (2) MUST be included in the response buffer for any subsequent ROP requests that apply to recipients (2) for the same Message object handle.");
            #endregion

            #region Call RopSaveChangesMessage to save the message
            RopSaveChangesMessageResponse saveChangesMessageResponse;
            saveChangesMessageResponse = this.SaveMessage(this.MessageHandle, (byte)SaveFlags.ForceSave);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, saveChangesMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopOpenMessage to open the message
            RopOpenMessageResponse openMessageResponse;
            uint openedMessageHandle = this.OpenSpecificMessage(logonResponse.FolderIds[4], saveChangesMessageResponse.MessageId, this.insideObjHandle, MessageOpenModeFlags.ReadWrite, out openMessageResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, openMessageResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);

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

            // Verify MS-OXCMSG requirement: MS-OXCMSG_R679
            // 5 recipients have been added above, so MS-OXCMSG_R679 can be verified if recipient count is 5.
            this.Site.CaptureRequirementIfAreEqual<ushort>(
                5,
                openMessageResponse.RecipientCount,
                679,
                @"[In RopOpenMessage ROP Response Buffer] RecipientCount: A 2-byte unsigned integer containing the number of recipients (2) associated with the Message object.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R977");
        
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R977
            this.Site.CaptureRequirementIfAreEqual<byte>(
                0x01,
                openMessageResponse.RecipientRows[0].RecipientType,
                977,
                @"[In RopOpenMessage ROP Response Buffer] [RecipientRows] The value 0x01 means Primary recipient.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R978");
        
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R978
            this.Site.CaptureRequirementIfAreEqual<byte>(
                0x02,
                openMessageResponse.RecipientRows[1].RecipientType,
                978,
                @"[In RopOpenMessage ROP Response Buffer] [RecipientRows] The value 0x02 means Carbon copy (Cc) recipient.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R979");
        
            // Verify MS-OXCMSG requirement: MS-OXCMSG_R979
            this.Site.CaptureRequirementIfAreEqual<byte>(
                0x03,
                openMessageResponse.RecipientRows[2].RecipientType,
                979,
                @"[In RopOpenMessage ROP Response Buffer] [RecipientRows] The value 0x03 means Blind carbon copy (Bcc) recipient.");

            int rowIdFir = Convert.ToInt32(readRecipientsResponse.RecipientRows[0].RowId);
            int rowIdSec = Convert.ToInt32(readRecipientsResponse.RecipientRows[1].RowId);
            int rowIdThr = Convert.ToInt32(readRecipientsResponse.RecipientRows[2].RowId);

            bool isAscOrder = false;
            bool isDecOrder = false;
            bool isVerifyR328 = false;

            // Ascending order
            if (rowIdFir > rowIdSec)
            {
                if (rowIdSec > rowIdThr)
                {
                    isAscOrder = true;
                }
            }

            // Descending order
            if (rowIdFir < rowIdSec)
            {
                if (rowIdSec < rowIdThr)
                {
                    isDecOrder = true;
                }
            }

            if (isAscOrder || isDecOrder)
            {
                isVerifyR328 = true;
            }

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

            // Verify MS-OXCMSG requirement: MS-OXCMSG_R328
            Site.CaptureRequirementIfIsTrue(
                isVerifyR328,
                328,
                @"[In Receiving a RopOpenMessage ROP Request] In addition, the server returns data for as many recipients (2) as will fit in the response buffer, in the order of the value of the RowId field.");
            #endregion

            #region Call RopReadRecipients with RowId set to an un-existing one and expect the error code 0x8004010F (ecNotFound) is returned.
            readRecipientsRequest.RowId = 0x0000000F; // Set RowId to an un-existing one.
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(readRecipientsRequest, openedMessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            readRecipientsResponse = (RopReadRecipientsResponse)this.response;

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

            // Verify MS-OXCMSG requirement: MS-OXCMSG_R1055
            Site.CaptureRequirementIfAreEqual<uint>(
                0x8004010F,
                readRecipientsResponse.ReturnValue,
                1055,
                @"[In Receiving a RopReadRecipients ROP Request] [ecNotFound (0x8004010F)] Recipient row RowId does not exist on the message.");
            #endregion

            #region Call RopModifyRecipient to modify the recipient of the message.
            modifyRecipientRow = new List<ModifyRecipientRow>
            {
                this.CreateModifyRecipientRow(TestUser5, 0),
                this.CreateModifyRecipientRow(TestUser4, 1),
                this.CreateModifyRecipientRow(TestUser3, 2),
                this.CreateModifyRecipientRow(TestUser1, 3),
                this.CreateModifyRecipientRow(TestUser2, 4),
                this.CreateModifyRecipientRow(TestUser6, 5),
                this.CreateModifyRecipientRow(TestUser9, 6),
                this.CreateModifyRecipientRow(TestUser7, 7),
                this.CreateModifyRecipientRow(TestUser8, 8)
            };

            this.AddRecipients(modifyRecipientRow, this.MessageHandle, propertyTag, out modifyRecipientsResponse);
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, modifyRecipientsResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            #endregion

            #region Call RopReadRecipients to read recipients and expect a successful response.
            readRecipientsRequest.RowId = 0x00000000; // Starting index for the recipients to be retrieved
            this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(readRecipientsRequest, this.MessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
            readRecipientsResponse = (RopReadRecipientsResponse)this.response;
            Site.Assert.AreEqual<uint>(TestSuiteBase.Success, readRecipientsResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);
            ReadRecipientRow[] recipientRowsNew = readRecipientsResponse.RecipientRows;

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R389, the length of RecipientRows is {0}.", recipientRowsNew.Length);

            // Verify MS-OXCMSG requirement: MS-OXCMSG_R389
            bool isVerifiedR389 = recipientRowsNew.Length > 5;

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR389,
                389,
                @"[In Receiving a RopModifyRecipients ROP Request] If the recipient (2) indicated by the value of the RowId field does not exist, the server creates a new recipient (2) with that RowId field value and applies the data from the request.");

            // Add the debug information
            this.Site.Log.Add(
                LogEntryKind.Debug,
                "Verify MS-OXCMSG_R390, the recipients are {0}, {1}, {2}, {3}, {4}.",
                Encoding.Unicode.GetString(recipientRowsNew[0].RecipientRow.DisplayName).TrimEnd(TestSuiteBase.NullTerminatorString.ToCharArray()),
                Encoding.Unicode.GetString(recipientRowsNew[1].RecipientRow.DisplayName).TrimEnd(TestSuiteBase.NullTerminatorString.ToCharArray()),
                Encoding.Unicode.GetString(recipientRowsNew[2].RecipientRow.DisplayName).TrimEnd(TestSuiteBase.NullTerminatorString.ToCharArray()),
                Encoding.Unicode.GetString(recipientRowsNew[3].RecipientRow.DisplayName).TrimEnd(TestSuiteBase.NullTerminatorString.ToCharArray()),
                Encoding.Unicode.GetString(recipientRowsNew[4].RecipientRow.DisplayName).TrimEnd(TestSuiteBase.NullTerminatorString.ToCharArray()));

            // Verify MS-OXCMSG requirement: MS-OXCMSG_R390
            bool isVerifiedR390 = Encoding.Unicode.GetString(recipientRowsNew[0].RecipientRow.DisplayName).TrimEnd(TestSuiteBase.NullTerminatorString.ToCharArray()) == TestUser5
                                && Encoding.Unicode.GetString(recipientRowsNew[1].RecipientRow.DisplayName).TrimEnd(TestSuiteBase.NullTerminatorString.ToCharArray()) == TestUser4
                                && Encoding.Unicode.GetString(recipientRowsNew[2].RecipientRow.DisplayName).TrimEnd(TestSuiteBase.NullTerminatorString.ToCharArray()) == TestUser3
                                && Encoding.Unicode.GetString(recipientRowsNew[3].RecipientRow.DisplayName).TrimEnd(TestSuiteBase.NullTerminatorString.ToCharArray()) == TestUser1
                                && Encoding.Unicode.GetString(recipientRowsNew[4].RecipientRow.DisplayName).TrimEnd(TestSuiteBase.NullTerminatorString.ToCharArray()) == TestUser2;

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR390,
                390,
                @"[In Receiving a RopModifyRecipients ROP Request] If the recipient (2) currently exists on the Message object and the value of RecipientRowSize field in the request buffer is nonzero, the server replaces all existing properties of the recipient (2) with the property values supplied in the request.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R1495, the count of recipients is {0}.", readRecipientsResponse.RowCount);

            // Verify MS-OXCMSG requirement: MS-OXCMSG_R1495
            // 9 recipients have been added in the above steps, so MS-OXCMSG_R1495 can be verified if readRecipientsResponse.RowCount == 9.
            this.Site.CaptureRequirementIfAreEqual<byte>(
                9,
                readRecipientsResponse.RowCount,
                1495,
                @"[In Receiving a RopReadRecipients ROP Request] When the value of the RowId field is 0x00000000, the server returns all recipients (2) for the message, beginning with the first recipient (2) and filling the response buffer with as many RecipientRow structures ([MS-OXCDATA] section 2.8.3) as will fit.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMSG_R400, the count of recipients is {0}.", readRecipientsResponse.RowCount);

            // Verify MS-OXCMSG requirement: MS-OXCMSG_R400
            // 9 recipients have been added in the above steps, so MS-OXCMSG_R400 can be verified if readRecipientsResponse.RowCount == 9.
            this.Site.CaptureRequirementIfAreEqual<byte>(
                9,
                readRecipientsResponse.RowCount,
                400,
                @"[In Receiving a RopReadRecipients ROP Request] The RopReadRecipients ROP ([MS-OXCROPS] section 2.2.6.6) is used to obtain information for all recipients (2) in the Message object, regardless of the number of recipients (2) on the message.");

            // Test requirements gathered from MS-OXCDATA.
            this.TestMSOXCDATARequirements(recipientRowsNew);
            #endregion

            #region Call RopRelease to release the created message.
            this.ReleaseRop(openedMessageHandle);
            #endregion
        }