Microsoft.Protocols.TestSuites.MS_OXORULE.S03_ProcessOutOfOfficeRule.MSOXORULE_S03_TC05_OOFBehaviorsForOP_OOF_REPLY C# (CSharp) Method

MSOXORULE_S03_TC05_OOFBehaviorsForOP_OOF_REPLY() private method

private MSOXORULE_S03_TC05_OOFBehaviorsForOP_OOF_REPLY ( ) : void
return void
        public void MSOXORULE_S03_TC05_OOFBehaviorsForOP_OOF_REPLY()
        {
            this.CheckMAPIHTTPTransportSupported();

            #region Prepare value for ruleProperties variable.
            RuleProperties ruleProperties = AdapterHelper.GenerateRuleProperties(this.Site, Constants.RuleNameOOFReply);
            #endregion

            #region Create one reply template for OP_OOF_REPLY action Type in TestUser1's Inbox folder.
            ulong replyTemplateMessageID;
            uint replyTemplateMessageHandle;
            TaggedPropertyValue[] addReplyBody = new TaggedPropertyValue[1];
            addReplyBody[0] = new TaggedPropertyValue();
            PropertyTag addReplyBodyPropertyTag = new PropertyTag
            {
                PropertyId = (ushort)PropertyId.PidTagBody,
                PropertyType = (ushort)PropertyType.PtypString
            };
            addReplyBody[0].PropertyTag = addReplyBodyPropertyTag;
            string replyMessageBody = Common.GenerateResourceName(this.Site, Constants.MessageOfOOFReply);
            addReplyBody[0].Value = Encoding.Unicode.GetBytes(replyMessageBody + "\0");
            string replyTemplateSubject = Common.GenerateResourceName(this.Site, Constants.ReplyTemplateSubject);
            byte[] replyTemplateGUID = this.OxoruleAdapter.CreateReplyTemplate(this.InboxFolderHandle, this.InboxFolderID, true, replyTemplateSubject, addReplyBody, out replyTemplateMessageID, out replyTemplateMessageHandle);
            #endregion

            #region TestUser1 adds OP_OOF_REPLY rule with PidTagRuleState set to ST_ENABLED.
            ReplyActionData replyRuleActionData = new ReplyActionData
            {
                ReplyTemplateGUID = replyTemplateGUID,
                ReplyTemplateFID = this.InboxFolderID,
                ReplyTemplateMID = replyTemplateMessageID
            };

            RuleData ruleDataForReplyRule = AdapterHelper.GenerateValidRuleDataWithFlavor(ActionType.OP_OOF_REPLY, 1, RuleState.ST_ENABLED, replyRuleActionData, 0x00000000, ruleProperties);
            RopModifyRulesResponse ropModifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleDataForReplyRule });
            Site.Assert.AreEqual<uint>(0, ropModifyRulesResponse.ReturnValue, "Adding reply rule should succeed.");
            #endregion

            #region TestUser2 delivers a message to TestUser1 to trigger these rules.
            // Sleep enough time to wait for the rule to take effect.
            Thread.Sleep(this.WaitForTheRuleToTakeEffect);
            string mailSubject = Common.GenerateResourceName(this.Site, ruleProperties.ConditionSubjectName + "Title");
            this.SUTAdapter.SendMailToRecipient(this.User2Name, this.User2Password, this.User1Name, mailSubject);

            // Sleep enough time to wait for the rule to be executed on the delivered message.
            Thread.Sleep(this.WaitForTheRuleToTakeEffect);
            #endregion

            #region TestUser2 verifies whether can receive the OOF replied message.
            // Let Testuser2 logon to the server
            this.LogonMailbox(TestUser.TestUser2);

            PropertyTag[] propertyTagList = new PropertyTag[4];
            propertyTagList[0].PropertyId = (ushort)PropertyId.PidTagAutoForwarded;
            propertyTagList[0].PropertyType = (ushort)PropertyType.PtypBoolean;
            propertyTagList[1].PropertyId = (ushort)PropertyId.PidTagBody;
            propertyTagList[1].PropertyType = (ushort)PropertyType.PtypString;
            propertyTagList[2].PropertyId = (ushort)PropertyId.PidTagSubject;
            propertyTagList[2].PropertyType = (ushort)PropertyType.PtypString;
            propertyTagList[3].PropertyId = (ushort)PropertyId.PidTagMessageClass;
            propertyTagList[3].PropertyType = (ushort)PropertyType.PtypString;

            uint contentsTableHandle = 0;
            int expectedMessageIndex = 0;
            RopQueryRowsResponse ropQueryRowsResponse = this.GetExpectedMessage(this.InboxFolderHandle, ref contentsTableHandle, propertyTagList, ref expectedMessageIndex, mailSubject);

            string mailBodyTestUser2 = AdapterHelper.PropertyValueConvertToString(ropQueryRowsResponse.RowData.PropertyRows[expectedMessageIndex].PropertyValues[1].Value);
            string subject = AdapterHelper.PropertyValueConvertToString(ropQueryRowsResponse.RowData.PropertyRows[expectedMessageIndex].PropertyValues[2].Value);
            bool isBodyContainsReplyTemplateBody = mailBodyTestUser2.Contains(replyMessageBody);
            Site.Assert.IsTrue(isBodyContainsReplyTemplateBody, "Message should contain the template body!");

            #region Capture Code
            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R255: the replied message count is {0}, and whether the message body contains the reply template body is {1}", ropQueryRowsResponse.RowCount, isBodyContainsReplyTemplateBody);

            // Verify MS-OXORULE requirement: MS-OXORULE_R255
            // Testuser2 sent message to Testuser1,Testuser2 can receive a reply means the server send the reply
            bool isVerifyR255 = ropQueryRowsResponse.RowCount > 0 && isBodyContainsReplyTemplateBody;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR255,
                255,
                @"[In ActionBlock Structure] The meaning of action type OP_OOF_REPLY: Sends an OOF reply to the message.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R922: the replied message count is {0}, and whether the message body contains the reply template body is {1}", ropQueryRowsResponse.RowCount, isBodyContainsReplyTemplateBody);

            // Verify MS-OXORULE requirement: MS-OXORULE_R922
            // Testuser2 sent message to Testuser1,Testuser2 can receive a reply means the server send the reply
            bool isVerifyR922 = ropQueryRowsResponse.RowCount > 0 && isBodyContainsReplyTemplateBody;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR922,
                922,
                @"[In Processing Incoming Messages to a Folder] [Following is a description of what the server does when it executes each action (2) type, as specified in section 2.2.5.1.1, for an incoming message:] ""OP_OOF_REPLY"": The server MUST behave as specified for the ""OP_REPLY"" action (2). [The server MUST use properties from the reply template and from the original message to create a reply to the message and then send the reply.]");

            // Add the debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R953: the replied message count is {0}, and whether the message body contains the reply template body is {1}", ropQueryRowsResponse.RowCount, isBodyContainsReplyTemplateBody);

            bool isVerifyR953 = ropQueryRowsResponse.RowCount > 0 && isBodyContainsReplyTemplateBody;

            // Verify MS-OXORULE requirement: MS-OXORULE_R953.
            // The ActionFlavor is set to zero in the OP_REPLY rule, so if the messages template is the same with the reply template, means this reply is not use server-defined text in the reply message, and it's a standard reply. 
            Site.CaptureRequirementIfIsTrue(
                isVerifyR953,
                953,
                @"[In Action Flavors] [If the ActionType field value is ""OP_OOF_REPLY"", the ActionFlavor field MUST have one of the values specified in the following table [XXXXXX (ST) (NS) XXXXXXXXXXXXXXXXXXXXXXXX] or zero (0x00000000)] A value of zero (0x00000000) indicates standard reply behavior, as specified in section 3.1.4.2.5.");

            string propertyValue = AdapterHelper.PropertyValueConvertToString(ropQueryRowsResponse.RowData.PropertyRows[expectedMessageIndex].PropertyValues[3].Value);
            if (Common.IsRequirementEnabled(906, this.Site))
            {
                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R906: whether the message body contains the reply template body is {0}, and the PidTagMessageClass is {1}", isBodyContainsReplyTemplateBody, propertyValue);

                // Verify MS-OXORULE requirement: MS-OXORULE_R906
                // The value of PidTagMessageClass is a prefix, and the client can append a client-specific value at the end of this property,
                // so if propertyValue is start with "IPM.Note.rules.OOFTemplate", R906 can be verified.
                string prefixOfPidTagMessageClass = "IPM.Note.rules.OOFTemplate";
                bool isVerifyR906 = isBodyContainsReplyTemplateBody && propertyValue.ToUpperInvariant().StartsWith(prefixOfPidTagMessageClass.ToUpperInvariant());

                Site.CaptureRequirementIfIsTrue(
                    isVerifyR906,
                    906,
                    @"[In Processing Incoming Messages to a Folder] [Following is a description of what the server does when it executes each action (2) type, as specified in section 2.2.5.1.1, for an incoming message] ""OP_OOF_REPLY"": The implementation does set the value of the PidTagMessageClass property ([MS-OXCMSG] section 2.2.1.3) on the reply message to ""IPM.Note.rules.OOFTemplate"" in addition. (Exchange 2003 and above follow this behavior.)");
            }
            #endregion
            #endregion
        }