Microsoft.Protocols.TestSuites.MS_OXCMSG.S07_RopRecipient.MSOXCMSG_S07_TC03_ErrorCodesOfReadModifyRemoveAllRecipients C# (CSharp) Method

MSOXCMSG_S07_TC03_ErrorCodesOfReadModifyRemoveAllRecipients() private method

        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
        }