Action Data buffer format for ActionType: OP_MOVE, OP_COPY
Inheritance: IActionData
        public void MSOXORULE_S01_TC06_AddMoveCopyAndBounceDeferredrules()
        {
            this.CheckMAPIHTTPTransportSupported();

            #region TestUser1 prepares value for ruleProperties variable.
            RuleProperties ruleProperties = AdapterHelper.GenerateRuleProperties(this.Site, Constants.RuleNameBounce);
            #endregion

            #region TestUser1 adds Bounce rule.
            BounceActionData bounceActionData = new BounceActionData
            {
                Bounce = BounceCode.CanNotDisplay
            };

            RuleData ruleBounce = AdapterHelper.GenerateValidRuleData(ActionType.OP_BOUNCE, TestRuleDataType.ForAdd, 0, RuleState.ST_ENABLED, bounceActionData, ruleProperties, null);
            RopModifyRulesResponse ropModifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleBounce });
            Site.Assert.AreEqual<uint>(0, ropModifyRulesResponse.ReturnValue, "Adding Bounce rule should succeed.");
            #endregion

            #region TestUser1 adds Deferred Action rule.
            ruleProperties.Name = Common.GenerateResourceName(this.Site, Constants.RuleNameDeferredAction);
            DeferredActionData deferredActionData = new DeferredActionData
            {
                Data = Common.GetBytesFromBinaryHexString(Constants.DeferredActionBufferData)
            };
            RuleData deferredActionRuleData = AdapterHelper.GenerateValidRuleData(ActionType.OP_DEFER_ACTION, TestRuleDataType.ForAdd, 1, RuleState.ST_ENABLED, deferredActionData, ruleProperties, null);

            RopModifyRulesResponse modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_OnExisting, new RuleData[] { deferredActionRuleData });
            Site.Assert.AreEqual<uint>(0, modifyRulesResponse.ReturnValue, "Adding deferred action rule to public folder should succeed.");
            #endregion

            if (Common.IsRequirementEnabled(294, this.Site))
            {
                #region TestUser1 creates a folder in server store.
                RopCreateFolderResponse createFolderResponse;
                string user1FolderName = Common.GenerateResourceName(this.Site, "User1Folder");
                uint folderHandle = this.OxoruleAdapter.RopCreateFolder(this.InboxFolderHandle, user1FolderName, "TestForOP_COPY", out createFolderResponse);
                ulong folderId = createFolderResponse.FolderId;
                Site.Assert.AreEqual<uint>(0, createFolderResponse.ReturnValue, "Creating folder operation should succeed.");
                #endregion

                #region TestUser1 prepares rules' data.
                MoveCopyActionData moveCopyActionData = new MoveCopyActionData();

                // Get the created folder entry ID.
                byte[] folderEId = this.OxoruleAdapter.GetFolderEntryId(StoreObjectType.Mailbox, folderHandle, folderId);

                // Get the store object's entry ID.
                byte[] storeEId = this.GetStoreObjectEntryID(StoreObjectType.Mailbox, this.Server, this.User1ESSDN);
                moveCopyActionData.FolderEID = folderEId;
                moveCopyActionData.StoreEID = storeEId;
                moveCopyActionData.FolderEIDSize = (ushort)folderEId.Length;
                moveCopyActionData.StoreEIDSize = (ushort)storeEId.Length;
                #endregion

                #region TestUSer1 generates test RuleData.
                ruleProperties.Name = Common.GenerateResourceName(this.Site, Constants.RuleNameCopy);
                RuleData ruleForCopy = AdapterHelper.GenerateValidRuleData(ActionType.OP_COPY, TestRuleDataType.ForAdd, 2, RuleState.ST_ENABLED, moveCopyActionData, ruleProperties, null);

                // Add rule for move with rule Provider Data.
                ruleProperties.ProviderData = Constants.PidTagRuleProviderData;
                ruleProperties.Name = Common.GenerateResourceName(this.Site, Constants.RuleNameMoveOne);
                RuleData ruleForMove = AdapterHelper.GenerateValidRuleData(ActionType.OP_MOVE, TestRuleDataType.ForAdd, 3, RuleState.ST_ENABLED, moveCopyActionData, ruleProperties, null);
                #endregion

                #region TestUser1 adds OP_MOVE and OP_COPY rules to the Inbox folder.
                modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_OnExisting, new RuleData[] { ruleForMove, ruleForCopy });

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

                // Verify MS-OXORULE requirement: MS-OXORULE_R680.
                // If the return value of the RopModifyRules response is 0x00, it means operation is successfully.
                Site.CaptureRequirementIfAreEqual<uint>(
                    0x00000000,
                    modifyRulesResponse.ReturnValue,
                    680,
                    @"[In RopModifyRules ROP Response Buffer] ReturnValue: To indicate success, the server returns 0x00000000.");

                // Wait for the mail to be received and the rule to take effect.
                Thread.Sleep(this.WaitForTheRuleToTakeEffect);
                #endregion

                RopDeleteFolderResponse deleteFolder = this.OxoruleAdapter.RopDeleteFolder(this.InboxFolderHandle, folderId);
                Site.Assert.AreEqual<uint>(0, deleteFolder.ReturnValue, "Deleting folder should succeed.");
            }

            #region TestUser1 gets rows from the rule table.
            RopGetRulesTableResponse ropGetRulesTableResponse;
            uint ruleTableHandle = this.OxoruleAdapter.RopGetRulesTable(this.InboxFolderHandle, TableFlags.Normal, out ropGetRulesTableResponse);
            Site.Assert.AreEqual<uint>(0, ropGetRulesTableResponse.ReturnValue, "RopGetRulesTable operation should succeed.");

            PropertyTag[] propertyListTag = new PropertyTag[4];

            // PidTagRuleActions property.
            propertyListTag[0].PropertyId = (ushort)PropertyId.PidTagRuleActions;
            propertyListTag[0].PropertyType = (ushort)PropertyType.PtypRuleAction;
            propertyListTag[1].PropertyId = (ushort)PropertyId.PidTagRuleName;
            propertyListTag[1].PropertyType = (ushort)PropertyType.PtypString;
            propertyListTag[2].PropertyId = (ushort)PropertyId.PidTagRuleProvider;
            propertyListTag[2].PropertyType = (ushort)PropertyType.PtypString;
            propertyListTag[3].PropertyId = (ushort)PropertyId.PidTagRuleProviderData;
            propertyListTag[3].PropertyType = (ushort)PropertyType.PtypBinary;

            // Set the query target to standardardRules.
            this.OxoruleAdapter.TargetOfRop = TargetOfRop.ForStandardRules;

            RopQueryRowsResponse getAllActionsResponse = this.OxoruleAdapter.QueryPropertiesInTable(ruleTableHandle, propertyListTag);
            Site.Assert.AreEqual<uint>(0, getAllActionsResponse.ReturnValue, "Getting rule properties should succeed.");

            // When R294 is enabled, there should be 4 rules exist on Inbox folder, otherwise only 2 rules exist.
            // If the rule table is got successfully and the rule count is correct, it means that the server is returning a table with the rule added by the test suite.
            if (Common.IsRequirementEnabled(294, this.Site))
            {
                Site.Assert.AreEqual(4, getAllActionsResponse.RowCount, @"There should be 4 rules returned, actual returned row count is {0}.", getAllActionsResponse.RowCount);
            }
            else
            {
                Site.Assert.AreEqual(2, getAllActionsResponse.RowCount, @"There should be 2 rules returned, actual returned row count is {0}.", getAllActionsResponse.RowCount);
            }

            this.VerifyRuleTable();

            // Clear the status of the adapter.
            this.OxoruleAdapter.TargetOfRop = TargetOfRop.OtherTarget;
            #endregion
        }
Exemple #2
0
        public void MSOXORULE_S04_TC04_AddNotSupportedRule_OnPublicFolder()
        {
            this.CheckMAPIHTTPTransportSupported();

            #region TestUser2 logs on to the public folder.
            RopOpenFolderResponse openFolderResponse;
            RopLogonResponse      logonResponse;
            bool ret = this.OxoruleAdapter.Connect(ConnectionType.PublicFolderServer, this.User2Name, this.User2ESSDN, this.User2Password);
            Site.Assert.IsTrue(ret, "connect to public folder server should be successful");
            uint publicFolderLogonHandler = this.OxoruleAdapter.RopLogon(LogonType.PublicFolder, this.User2ESSDN, out logonResponse);

            // Assert the client to log on to the public folder successfully.
            Site.Assert.AreEqual <uint>(0, logonResponse.ReturnValue, "Logon the public folder should be successful.");

            // Folder index 1 is the Interpersonal Messages subtree, and this is defined in MS-OXCSTOR.
            uint  publicfolderHandler = this.OxoruleAdapter.RopOpenFolder(publicFolderLogonHandler, logonResponse.FolderIds[1], out openFolderResponse);
            ulong publicFolderID      = logonResponse.FolderIds[1];
            #endregion

            #region TestUser2 tests the unsupported rules in public folder.
            #region TestUser2 prepares value for ruleProperties variable.
            RuleProperties ruleProperties = AdapterHelper.GenerateRuleProperties(this.Site, Constants.RuleNameDeferredAction);
            #endregion

            #region TestUser2 adds a Rule set Action Type to OP_DEFER_ACTION.
            DeferredActionData deferredActionData = new DeferredActionData
            {
                Data = Common.GetBytesFromBinaryHexString(Constants.DeferredActionBufferData)
            };
            RuleData deferredActionRuleData = AdapterHelper.GenerateValidRuleData(ActionType.OP_DEFER_ACTION, TestRuleDataType.ForAdd, 5, RuleState.ST_ENABLED, deferredActionData, ruleProperties, null);
            RopModifyRulesResponse ropModifyRulesResponse = this.OxoruleAdapter.RopModifyRules(publicfolderHandler, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { deferredActionRuleData });
            #endregion

            // Add the debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R258: server returned value is {0}", ropModifyRulesResponse.ReturnValue);

            // Verify MS-OXORULE requirement: MS-OXORULE_R258.
            // If the ReturnValue is not 0x00000000, it means the server failed to add a public folder rule with this OP_DEFER_ACTION Type action.
            // So it is not used in a public folder rule.
            bool isVerifyR258 = ropModifyRulesResponse.ReturnValue != 0x00000000;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR258,
                258,
                @"[In ActionBlock Structure] The meaning of action type OP_DEFER_ACTION: MUST NOT be used in a public folder rule (4).");

            #region TestUser2 prepares rules' data.
            MoveCopyActionData moveCopyActionData = new MoveCopyActionData();

            // Get the Inbox folder entry ID.
            byte[] folderEId = this.OxoruleAdapter.GetFolderEntryId(StoreObjectType.PublicFolder, publicfolderHandler, publicFolderID);

            // Get the store object's entry ID.
            byte[] storeEId = this.GetStoreObjectEntryID(StoreObjectType.PublicFolder, this.Server, this.User1ESSDN);
            moveCopyActionData.FolderEID     = folderEId;
            moveCopyActionData.StoreEID      = storeEId;
            moveCopyActionData.FolderEIDSize = (ushort)folderEId.Length;
            moveCopyActionData.StoreEIDSize  = (ushort)storeEId.Length;
            #endregion

            #region TestUser2 prepares value for ruleProperties variable.
            ruleProperties = AdapterHelper.GenerateRuleProperties(this.Site, Constants.RuleNameMoveOne);
            #endregion

            #region TestUser2 adds OP_MOVE rule to the public folder.
            ruleProperties.Name = Common.GenerateResourceName(this.Site, Constants.RuleNameMoveOne);
            RuleData ruleForMove = AdapterHelper.GenerateValidRuleData(ActionType.OP_MOVE, TestRuleDataType.ForAdd, 0, RuleState.ST_ENABLED, moveCopyActionData, ruleProperties, null);
            RopModifyRulesResponse modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(publicfolderHandler, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForMove });
            #endregion

            // Add the debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R839: server returned value is {0}", modifyRulesResponse.ReturnValue);

            // Verify MS-OXORULE requirement: MS-OXORULE_R839.
            // If the returnValue is not 0x00000000, it means this OP_MOVE Type used in a public folder rule is failed,
            // so it is not used in a public folder rule.
            bool isVerifyR839 = modifyRulesResponse.ReturnValue != 0x00000000;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR839,
                839,
                @"[In ActionBlock Structure] The meaning of action type OP_MOVE: MUST NOT be used in a public folder rule (4).");

            #region TestUser2 adds OP_COPY rule to the public folder.
            ruleProperties.Name = Common.GenerateResourceName(this.Site, Constants.RuleNameMoveTwo);
            RuleData ruleForCopy = AdapterHelper.GenerateValidRuleData(ActionType.OP_COPY, TestRuleDataType.ForAdd, 1, RuleState.ST_ENABLED, moveCopyActionData, ruleProperties, null);
            modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(publicfolderHandler, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForCopy });
            #endregion

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R840: server returned value is {0}", modifyRulesResponse.ReturnValue);

            // Verify MS-OXORULE requirement: MS-OXORULE_R840.
            // If the ReturnValue is not 0x00000000, it means this OP_COPY Type used in a public folder rule is failed,
            // so it is not used in a public folder rule.
            bool isVerifyR840 = modifyRulesResponse.ReturnValue != 0x00000000;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR840,
                840,
                @"[In ActionBlock Structure] The meaning of action type OP_COPY: MUST NOT be used in a public folder rule (4).");
            #endregion
        }
        public void MSOXORULE_S02_TC18_ServerExecuteRule_Action_MultipleOP_MOVE()
        {
            this.CheckMAPIHTTPTransportSupported();
            Site.Assume.IsTrue(Common.IsRequirementEnabled(929, this.Site), "This case runs only when the server supports OP_MOVE action when FolderInThisStore is set to 0.");
            Site.Assume.IsTrue(Common.IsRequirementEnabled(904, this.Site), "This case runs only when the server supports creating multiple copies of the message for OP_MOVE action.");

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

            #region TestUser1 creates folder1 in server store.
            RopCreateFolderResponse createFolderResponse;
            uint newFolderHandle = this.OxoruleAdapter.RopCreateFolder(this.InboxFolderHandle, Common.GenerateResourceName(this.Site, "User1Folder01"), "TestForOP_MOVE", out createFolderResponse);
            ulong newFolderId = createFolderResponse.FolderId;
            Site.Assert.AreEqual<uint>(0, createFolderResponse.ReturnValue, "Creating folder operation should succeed.");
            #endregion

            #region TestUser1 creates folder2 in server store.
            RopCreateFolderResponse createFolder2Response;
            uint newFolder2Handle = this.OxoruleAdapter.RopCreateFolder(this.InboxFolderHandle, Common.GenerateResourceName(this.Site, "User1Folder02"), "TestForOP_MOVE", out createFolder2Response);
            ulong newFolder2Id = createFolder2Response.FolderId;
            Site.Assert.AreEqual<uint>(0, createFolder2Response.ReturnValue, "Creating folder operation should succeed.");
            #endregion

            #region Prepare rules' data
            MoveCopyActionData moveCopyActionData1 = new MoveCopyActionData();

            // Get the created folder1 entry id.
            byte[] folder1EId = this.OxoruleAdapter.GetFolderEntryId(StoreObjectType.Mailbox, newFolderHandle, newFolderId);

            // Get the store object's entry id
            byte[] storeEId = this.GetStoreObjectEntryID(StoreObjectType.Mailbox, this.Server, this.User1ESSDN);
            moveCopyActionData1.FolderInThisStore = 0;
            moveCopyActionData1.FolderEID = folder1EId;
            moveCopyActionData1.StoreEID = storeEId;
            moveCopyActionData1.FolderEIDSize = (ushort)folder1EId.Length;
            moveCopyActionData1.StoreEIDSize = (ushort)storeEId.Length;
            MoveCopyActionData moveCopyActionData2 = new MoveCopyActionData();

            // Get the created folder2 entry ID.
            byte[] folder2EId = this.OxoruleAdapter.GetFolderEntryId(StoreObjectType.Mailbox, newFolder2Handle, newFolder2Id);
            moveCopyActionData2.FolderInThisStore = 0;
            moveCopyActionData2.FolderEID = folder2EId;
            moveCopyActionData2.StoreEID = storeEId;
            moveCopyActionData2.FolderEIDSize = (ushort)folder2EId.Length;
            moveCopyActionData2.StoreEIDSize = (ushort)storeEId.Length;
            IActionData[] moveCopyActionData = { moveCopyActionData1, moveCopyActionData2 };
            #endregion

            #region Generate test RuleData.
            // Add rule for move without rule Provider Data.
            ruleProperties.ProviderData = string.Empty;
            RuleData ruleForMoveFolder = AdapterHelper.GenerateValidRuleDataWithFlavor(new ActionType[] { ActionType.OP_MOVE, ActionType.OP_MOVE }, 0, RuleState.ST_ENABLED, moveCopyActionData, new uint[] { 0, 0 }, ruleProperties);

            #endregion

            #region TestUser1 adds OP_MOVE rule to the Inbox folder.
            RopModifyRulesResponse modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForMoveFolder });
            Site.Assert.AreEqual<uint>(0, modifyRulesResponse.ReturnValue, "Adding Move rule should succeed.");
            #endregion

            #region TestUser2 delivers a message to TestUser1 to trigger these rules.

            // TestUser2 deliver a message to trigger these rules.
            string mailSubject = Common.GenerateResourceName(this.Site, ruleProperties.ConditionSubjectName + "Title");
            this.SUTAdapter.SendMailToRecipient(this.User2Name, this.User2Password, this.User1Name, mailSubject);

            // Wait for the mail to be received and the rule to take effect.
            Thread.Sleep(this.WaitForTheRuleToTakeEffect);
            #endregion

            #region TestUser1 gets the message content to verify the rule evaluation.
            uint inboxFolderContentsTableHandle = 0;
            PropertyTag[] propertyTagList = new PropertyTag[1];
            propertyTagList[0].PropertyId = (ushort)PropertyId.PidTagSubject;
            propertyTagList[0].PropertyType = (ushort)PropertyType.PtypString;

            bool doesOriginalMessageExist = this.CheckUnexpectedMessageExist(this.InboxFolderHandle, ref inboxFolderContentsTableHandle, propertyTagList, mailSubject);
            uint newFolder1ContentsTableHandle = 0;
            uint rowCount = 0;
            RopQueryRowsResponse getNewFolder1MailMessageContent = this.GetExpectedMessage(newFolderHandle, ref newFolder1ContentsTableHandle, propertyTagList, ref rowCount, 1, mailSubject);
            Site.Assert.AreEqual<uint>(0, getNewFolder1MailMessageContent.ReturnValue, "Getting message on the first folder should succeed.");
            uint newFolder2ContentsTableHandle = 0;
            rowCount = 0;
            RopQueryRowsResponse getNewFolder2MailMessageContent = this.GetExpectedMessage(newFolder2Handle, ref newFolder2ContentsTableHandle, propertyTagList, ref rowCount, 1, mailSubject);
            Site.Assert.AreEqual<uint>(0, getNewFolder2MailMessageContent.ReturnValue, "Getting message on the second folder should succeed.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R904: the message count in NewFolder1 and NewFolder2 are {0} and {1}", getNewFolder1MailMessageContent.RowCount, getNewFolder2MailMessageContent.RowCount);

            // Verify MS-OXORULE requirement: MS-OXORULE_R904
            bool isVerifyR904 = getNewFolder1MailMessageContent.RowCount == 1 && getNewFolder2MailMessageContent.RowCount == 1 && !doesOriginalMessageExist;

            Site.CaptureRequirementIfIsTrue(
                  isVerifyR904,
                  904,
                  @"[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_MOVE"": The implementation does create multiple copies of the message and then delete the original message, if multiple ""OP_MOVE"" operations apply to the same message. (Exchange 2003 and above follow this behavior.)");
            #endregion

            #region Delete the folders created in step2 and step3.
            RopDeleteFolderResponse deleteFolder = this.OxoruleAdapter.RopDeleteFolder(this.InboxFolderHandle, newFolderId);
            Site.Assert.AreEqual<uint>(0, deleteFolder.ReturnValue, "Deleting folder should succeed.");
            deleteFolder = this.OxoruleAdapter.RopDeleteFolder(this.InboxFolderHandle, newFolder2Id);
            Site.Assert.AreEqual<uint>(0, deleteFolder.ReturnValue, "Deleting folder should succeed.");
            #endregion
        }
        public void MSOXORULE_S02_TC05_ServerExecuteRule_Action_OP_DELETE()
        {
            this.CheckMAPIHTTPTransportSupported();

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

            #region TestUser1 creates a new folder in server store.
            RopCreateFolderResponse createFolderResponse;
            uint newFolderHandle = this.OxoruleAdapter.RopCreateFolder(this.InboxFolderHandle, Common.GenerateResourceName(this.Site, "User1Folder"), "TestForOP_COPY", out createFolderResponse);
            ulong newFolderId = createFolderResponse.FolderId;
            Site.Assert.AreEqual<uint>(0, createFolderResponse.ReturnValue, "Creating folder operation should succeed.");
            #endregion

            #region Prepare rules' data.
            MoveCopyActionData moveCopyActionData = new MoveCopyActionData();

            // Get the created folder entry ID.
            ServerEID serverEID = new ServerEID(BitConverter.GetBytes(newFolderId));
            byte[] folderEId = serverEID.Serialize();

            // Get the store object's entry ID.
            byte[] storeEId = this.GetStoreObjectEntryID(StoreObjectType.Mailbox, this.Server, this.User1ESSDN);
            moveCopyActionData.FolderInThisStore = 1;
            moveCopyActionData.FolderEID = folderEId;
            moveCopyActionData.StoreEID = storeEId;
            moveCopyActionData.FolderEIDSize = (ushort)folderEId.Length;
            moveCopyActionData.StoreEIDSize = (ushort)storeEId.Length;
            RuleData ruleForCopy = AdapterHelper.GenerateValidRuleData(ActionType.OP_COPY, TestRuleDataType.ForAdd, 1, RuleState.ST_ENABLED, moveCopyActionData, ruleProperties, null);
            #endregion

            #region TestUser1 adds OP_COPY rule to the Inbox folder.
            RopModifyRulesResponse modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForCopy });
            Site.Assert.AreEqual<uint>(0, modifyRulesResponse.ReturnValue, "Adding Copy rule should succeed.");
            #endregion

            #region TestUser1 adds OP_DELETE rule for Inbox folder with rule Sequence set to 2.
            ruleProperties.Name = Common.GenerateResourceName(this.Site, Constants.RuleNameDelete);
            RuleData ruleForDelete = AdapterHelper.GenerateValidRuleData(ActionType.OP_DELETE, TestRuleDataType.ForAdd, 2, RuleState.ST_ENABLED, new DeleteMarkReadActionData(), ruleProperties, null);
            RopModifyRulesResponse ropModifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_OnExisting, new RuleData[] { ruleForDelete });
            Site.Assert.AreEqual<uint>(0, ropModifyRulesResponse.ReturnValue, "Adding the delete rule should succeed.");
            #endregion

            #region TestUser1 adds OP_FORWARD rule with rule sequence set to 3.
            ruleProperties.Name = Common.GenerateResourceName(this.Site, Constants.RuleNameForward);
            ForwardDelegateActionData forwardActionData = new ForwardDelegateActionData
            {
                RecipientCount = (ushort)0x01
            };
            RecipientBlock recipientBlock = new RecipientBlock
            {
                Reserved = 0x01,
                NoOfProperties = (ushort)0x04u
            };

            #region Prepare the recipient Block.
            TaggedPropertyValue[] recipientProperties = AdapterHelper.GenerateRecipientPropertiesBlock(this.User2Name, this.User2ESSDN);

            recipientBlock.PropertiesData = recipientProperties;
            #endregion

            forwardActionData.RecipientsData = new RecipientBlock[1] { recipientBlock };
            RuleData ruleForward = AdapterHelper.GenerateValidRuleData(ActionType.OP_FORWARD, TestRuleDataType.ForAdd, 3, RuleState.ST_ENABLED, forwardActionData, ruleProperties, null);
            ropModifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_OnExisting, new RuleData[] { ruleForward });
            Site.Assert.AreEqual<uint>(0, ropModifyRulesResponse.ReturnValue, "Adding Forward rule should succeed");
            #endregion

            #region Get the rule properties in the Inbox of TestUser1.
            RopGetRulesTableResponse ropGetRulesTableResponse = new RopGetRulesTableResponse();
            uint ruleTableHandler = this.OxoruleAdapter.RopGetRulesTable(this.InboxFolderHandle, TableFlags.Normal, out ropGetRulesTableResponse);
            Site.Assert.AreEqual<uint>(0, ropGetRulesTableResponse.ReturnValue, "Getting rule table operation should succeed.");

            PropertyTag[] propertyTags = new PropertyTag[2];

            // PidTagRuleFolderEntryId
            propertyTags[0].PropertyId = (ushort)PropertyId.PidTagRuleFolderEntryId;
            propertyTags[0].PropertyType = (ushort)PropertyType.PtypBinary;

            // PidTagRuleLevel
            propertyTags[1].PropertyId = (ushort)PropertyId.PidTagRuleLevel;
            propertyTags[1].PropertyType = (ushort)PropertyType.PtypInteger32;

            RopQueryRowsResponse ropQueryRowsResponse = this.OxoruleAdapter.QueryPropertiesInTable(ruleTableHandler, propertyTags);
            Site.Assert.AreEqual<uint>(0, ropQueryRowsResponse.ReturnValue, "Query rows operation should succeed.");

            // Three rules have been added to the Inbox folder, so the row count in the rule table should be 3.
            Site.Assert.AreEqual<uint>(3, ropQueryRowsResponse.RowCount, "The rule number in the rule table is {0}", ropQueryRowsResponse.RowCount);
            this.VerifyRuleTable();
            #endregion

            #region TestUser2 deliver a message to TestUser1 to trigger these rules
            // Wait for the mail to be received and 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);

            // Wait for the mail to be received and the rule to take effect.
            Thread.Sleep(this.WaitForTheRuleToTakeEffect);
            #endregion

            #region TestUser1 checks whether the origin message is deleted.
            // Set PidTagSubject and PidTagMessageFlags visible.
            PropertyTag[] propertyTag = new PropertyTag[2];
            propertyTag[0].PropertyId = (ushort)PropertyId.PidTagSubject;
            propertyTag[0].PropertyType = (ushort)PropertyType.PtypString;
            propertyTag[1].PropertyId = (ushort)PropertyId.PidTagMessageFlags;
            propertyTag[1].PropertyType = (ushort)PropertyType.PtypInteger32;

            // Get mail message content.
            uint contentsTableHandle = 0;
            bool doesUnexpectedMessageExist = this.CheckUnexpectedMessageExist(this.InboxFolderHandle, ref contentsTableHandle, propertyTag, mailSubject);

            #region Capture Code
            // Add the debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R931");

            // Verify MS-OXORULE requirement: MS-OXORULE_R931.
            // In this test case, the server-side rule is OP_DELETE, and the actions specified in the PidTagRuleActions property associated with this rule is to delete the incoming message. 
            // TestUser2 has sent a message to TestUser1. If the message doesn't appear in TestUser1's mailbox, it means the server has deleted the incoming message. This requirement can be verified.
            Site.CaptureRequirementIfIsFalse(
                doesUnexpectedMessageExist,
                931,
                @"[In Processing Incoming Messages to a Folder] When executing a rule (2) whose condition evaluates to ""TRUE"" as per the restriction (2) in the PidTagRuleCondition property (section 2.2.1.3.1.9), then the server MUST perform the actions (2) specified in the PidTagRuleActions property (section 2.2.1.3.1.10) associated with that rule (2) in the case of a server-side rule.");

            if (Common.IsRequirementEnabled(898, this.Site))
            {
                // Add the debug information.
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R898");

                Site.CaptureRequirementIfIsFalse(
                    doesUnexpectedMessageExist,
                    898,
                    @"[In OP_DELETE or OP_MARK_AS_READ Data Buffer Format] For the OP_DELETE action type, the implementation does delete the incoming messages according to the ActionType itself. (Windows Exchange 2003 and above follow this behavior)");
            }

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

            // Verify MS-OXORULE requirement: MS-OXORULE_R549.
            // TestUser2 has sent a message to TestUser1. If the message doesn't appear in TestUser1's mailbox, it means the server has deleted the incoming message. This requirement can be verified.
            Site.CaptureRequirementIfIsFalse(
                doesUnexpectedMessageExist,
                549,
                @"[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_DELETE"": The server MUST delete the message.");

            #endregion
            #endregion

            #region TestUser2 checks whether a forward message is received.
            this.LogonMailbox(TestUser.TestUser2);
            bool doesUnexpectedMessageExist2 = this.CheckUnexpectedMessageExist(this.InboxFolderHandle, ref contentsTableHandle, propertyTag, mailSubject);

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

            // Verify MS-OXORULE requirement: MS-OXORULE_R550.
            // In this test case, if the forward message doesn't appear in TestUser2's mailbox, it means the subsequent OP_FORWARD rule, which is not an Out of Office rule, is not executed.
            Site.CaptureRequirementIfIsFalse(
                doesUnexpectedMessageExist2,
                550,
                @"[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_DELETE"": The server MUST stop evaluating subsequent rules (2) on the message except for Out of Office rules.");
            #endregion

            #region Delete the newly created folder.
            this.LogonMailbox(TestUser.TestUser1);
            RopDeleteFolderResponse deleteFolder = this.OxoruleAdapter.RopDeleteFolder(this.InboxFolderHandle, newFolderId);
            Site.Assert.AreEqual<uint>(0, deleteFolder.ReturnValue, "Deleting folder should succeed.");
            #endregion
        }
        public void MSOXORULE_S02_TC14_ServerExecuteRule_Action_OP_COPY_FolderInThisStore()
        {
            this.CheckMAPIHTTPTransportSupported();

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

            #region TestUser1 creates folder1 in server store.
            RopCreateFolderResponse createFolderResponse;
            uint newFolderHandle = this.OxoruleAdapter.RopCreateFolder(this.InboxFolderHandle, Common.GenerateResourceName(this.Site, "User1Folder01"), "TestForOP_COPY", out createFolderResponse);
            ulong newFolderId = createFolderResponse.FolderId;
            Site.Assert.AreEqual<uint>(0, createFolderResponse.ReturnValue, "Creating folder operation should succeed.");
            #endregion

            #region Prepare rules' data
            MoveCopyActionData moveCopyActionData = new MoveCopyActionData();

            // Get the created folder1 entry id.
            ServerEID serverEID = new ServerEID(BitConverter.GetBytes(newFolderId));
            byte[] folder1EId = serverEID.Serialize();

            // Get the store object's entry id
            byte[] storeEId = this.GetStoreObjectEntryID(StoreObjectType.Mailbox, this.Server, this.User1ESSDN);
            moveCopyActionData.FolderInThisStore = 1;
            moveCopyActionData.FolderEID = folder1EId;
            moveCopyActionData.StoreEID = storeEId;
            moveCopyActionData.FolderEIDSize = (ushort)folder1EId.Length;
            moveCopyActionData.StoreEIDSize = (ushort)storeEId.Length;
            IActionData[] moveCopyAction = { moveCopyActionData };
            #endregion

            #region Generate test RuleData.
            // Add rule for OP_COPY without rule Provider Data.
            ruleProperties.ProviderData = string.Empty;
            RuleData ruleForMoveFolder = AdapterHelper.GenerateValidRuleDataWithFlavor(new ActionType[] { ActionType.OP_COPY }, 0, RuleState.ST_ENABLED, moveCopyAction, new uint[] { 0 }, ruleProperties);

            #endregion

            #region TestUser1 adds OP_COPY rule to the Inbox folder.
            RopModifyRulesResponse modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForMoveFolder });
            Site.Assert.AreEqual<uint>(0, modifyRulesResponse.ReturnValue, "Adding Copy rule should succeed.");
            #endregion

            #region TestUser2 delivers a message to TestUser1 to trigger the rule.

            // TestUser2 deliver a message to trigger the rule.
            string mailSubject = Common.GenerateResourceName(this.Site, ruleProperties.ConditionSubjectName + "Title");
            this.SUTAdapter.SendMailToRecipient(this.User2Name, this.User2Password, this.User1Name, mailSubject);

            // Wait for the mail to be received and the rule to take effect.
            Thread.Sleep(this.WaitForTheRuleToTakeEffect);
            #endregion

            #region TestUser1 gets the message content to verify the rule evaluation.

            uint inboxFolderContentsTableHandle = 0;
            PropertyTag[] propertyTagList = new PropertyTag[1];
            propertyTagList[0].PropertyId = (ushort)PropertyId.PidTagSubject;
            propertyTagList[0].PropertyType = (ushort)PropertyType.PtypString;
            uint rowCount = 0;
            RopQueryRowsResponse getInboxMailMessageContent = this.GetExpectedMessage(this.InboxFolderHandle, ref inboxFolderContentsTableHandle, propertyTagList, ref rowCount, 1, mailSubject);
            uint newFolder1ContentsTableHandle = 0;
            rowCount = 0;
            RopQueryRowsResponse getNewFolder1MailMessageContent = this.GetExpectedMessage(newFolderHandle, ref newFolder1ContentsTableHandle, propertyTagList, ref rowCount, 1, mailSubject);
            Site.Assert.AreEqual<uint>(0, getNewFolder1MailMessageContent.ReturnValue, "Getting message on the newly created folder should succeed.");

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

            bool isVerifiedR957 = getInboxMailMessageContent.RowCount != 0 && getNewFolder1MailMessageContent.RowCount != 0;

            // Verify MS-OXORULE requirement: MS-OXORULE_R957
            // Since the destination folder is created in the user's mailbox, if the Emails can be found in the destination folder and Inbox folder, MS-OXORULE_R957 can be verified. 
            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR957,
                957,
                @"[In OP_MOVE and OP_COPY ActionData Structure] [Buffer Format for Standard Rules] The destination folder for a Copy action in a standard rule can be in the user's mailbox.");
            #endregion

            #region Delete the newly created folder.
            RopDeleteFolderResponse deleteFolder = this.OxoruleAdapter.RopDeleteFolder(this.InboxFolderHandle, newFolderId);
            Site.Assert.AreEqual<uint>(0, deleteFolder.ReturnValue, "Deleting folder should succeed.");
            #endregion
        }
        public void MSOXORULE_S02_TC13_ServerExecuteRule_Action_OP_MOVE_FolderInThisStore()
        {
            this.CheckMAPIHTTPTransportSupported();

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

            #region TestUser1 creates folder1 in server store.
            RopCreateFolderResponse createFolderResponse;
            uint newFolderHandle = this.OxoruleAdapter.RopCreateFolder(this.InboxFolderHandle, Common.GenerateResourceName(this.Site, "User1Folder01"), "TestForOP_MOVE", out createFolderResponse);
            ulong newFolderId = createFolderResponse.FolderId;
            Site.Assert.AreEqual<uint>(0, createFolderResponse.ReturnValue, "Creating folder operation should succeed.");
            #endregion

            #region Prepare rules' data
            MoveCopyActionData moveCopyActionData = new MoveCopyActionData();

            // Get the created folder1 entry id.
            ServerEID serverEID = new ServerEID(BitConverter.GetBytes(newFolderId));
            byte[] folder1EId = serverEID.Serialize();

            // Get the store object's entry id
            byte[] storeEId = this.GetStoreObjectEntryID(StoreObjectType.Mailbox, this.Server, this.User1ESSDN);
            moveCopyActionData.FolderInThisStore = 1;
            moveCopyActionData.FolderEID = folder1EId;
            moveCopyActionData.StoreEID = storeEId;
            moveCopyActionData.FolderEIDSize = (ushort)folder1EId.Length;
            moveCopyActionData.StoreEIDSize = (ushort)storeEId.Length;
            IActionData[] moveCopyAction = { moveCopyActionData };
            #endregion

            #region Generate test RuleData.
            // Add rule for move without rule Provider Data.
            ruleProperties.ProviderData = string.Empty;
            RuleData ruleForMoveFolder = AdapterHelper.GenerateValidRuleDataWithFlavor(new ActionType[] { ActionType.OP_MOVE }, 0, RuleState.ST_ENABLED, moveCopyAction, new uint[] { 0 }, ruleProperties);

            #endregion

            #region TestUser1 adds OP_MOVE rule to the Inbox folder.
            RopModifyRulesResponse modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForMoveFolder });
            Site.Assert.AreEqual<uint>(0, modifyRulesResponse.ReturnValue, "Adding Move rule should succeed.");
            #endregion

            #region TestUser2 delivers a message to TestUser1 to trigger the rule.

            // TestUser2 deliver a message to trigger the rule.
            string mailSubject = Common.GenerateResourceName(this.Site, ruleProperties.ConditionSubjectName + "Title");
            this.SUTAdapter.SendMailToRecipient(this.User2Name, this.User2Password, this.User1Name, mailSubject);

            // Wait for the mail to be received and the rule to take effect.
            Thread.Sleep(this.WaitForTheRuleToTakeEffect);
            #endregion

            #region TestUser1 gets the message content to verify the rule evaluation.
            uint inboxFolderContentsTableHandle = 0;
            PropertyTag[] propertyTagList = new PropertyTag[1];
            propertyTagList[0].PropertyId = (ushort)PropertyId.PidTagSubject;
            propertyTagList[0].PropertyType = (ushort)PropertyType.PtypString;

            bool doesOriginalMessageExist = this.CheckUnexpectedMessageExist(this.InboxFolderHandle, ref inboxFolderContentsTableHandle, propertyTagList, mailSubject);
            uint newFolder1ContentsTableHandle = 0;
            uint rowCount = 0;
            RopQueryRowsResponse getNewFolder1MailMessageContent = this.GetExpectedMessage(newFolderHandle, ref newFolder1ContentsTableHandle, propertyTagList, ref rowCount, 1, mailSubject);
            Site.Assert.IsFalse(doesOriginalMessageExist, "The original message shouldn't exist anymore.");
            Site.Assert.AreEqual<uint>(0, getNewFolder1MailMessageContent.ReturnValue, "getNewFolder1MailMessageContent should succeed.");

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

            // Verify MS-OXORULE requirement: MS-OXORULE_R956
            // Since the destination folder is created in the user's mailbox, if the Email can be found in the destination folder, MS-OXORULE_R956 can be verified.
            this.Site.CaptureRequirementIfAreNotEqual<uint>(
                0,
                getNewFolder1MailMessageContent.RowCount,
                956,
                @"[In OP_MOVE and OP_COPY ActionData Structure] [Buffer Format for Standard Rules] The destination folder for a Move action in a standard rule can be in the user's mailbox.");
            #endregion

            if (Common.IsRequirementEnabled(294, this.Site))
            {
                #region TestUser1 gets a rule table.

                RopGetRulesTableResponse ropGetRulesTableResponse;
                uint ruleTableHandle = this.OxoruleAdapter.RopGetRulesTable(this.InboxFolderHandle, TableFlags.Normal, out ropGetRulesTableResponse);
                Site.Assert.AreEqual<uint>(0, ropGetRulesTableResponse.ReturnValue, "Getting rule table should succeed.");
                #endregion

                #region TestUser1 retrieves rule information to check if the rule exists.
                PropertyTag[] propertyTags = new PropertyTag[2];
                propertyTags[0].PropertyId = (ushort)PropertyId.PidTagRuleName;
                propertyTags[0].PropertyType = (ushort)PropertyType.PtypString;
                propertyTags[1].PropertyId = (ushort)PropertyId.PidTagRuleActions;
                propertyTags[1].PropertyType = (ushort)PropertyType.PtypRuleAction;

                // Retrieves rows from the rule table.
                RopQueryRowsResponse queryRowResponse = this.OxoruleAdapter.QueryPropertiesInTable(ruleTableHandle, propertyTags);
                Site.Assert.AreEqual<uint>(0, queryRowResponse.ReturnValue, "Retrieving rows from the rule table should succeed.");
                MoveCopyActionData moveActionDataOfQueryRowsResponse = new MoveCopyActionData();
                RuleAction ruleAction = new RuleAction();
                for (int i = 0; i < queryRowResponse.RowCount; i++)
                {
                    System.Text.UnicodeEncoding converter = new UnicodeEncoding();
                    string ruleName = converter.GetString(queryRowResponse.RowData.PropertyRows.ToArray()[i].PropertyValues[0].Value);
                    if (ruleName == ruleProperties.Name + "\0")
                    {
                        // Verify structure RuleAction 
                        ruleAction.Deserialize(queryRowResponse.RowData.PropertyRows[i].PropertyValues[1].Value);
                        moveActionDataOfQueryRowsResponse.Deserialize(ruleAction.Actions[0].ActionDataValue.Serialize());
                        break;
                    }
                }

                #region Capture Code

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

                ServerEID serverEIDOfResponse = new ServerEID(new byte[] { });
                serverEIDOfResponse.Deserialize(moveActionDataOfQueryRowsResponse.FolderEID);
                bool isVerifiedR736 = moveActionDataOfQueryRowsResponse.FolderInThisStore == 0x01 && serverEIDOfResponse.FolderID != null && serverEIDOfResponse.MessageID != null && serverEIDOfResponse.Instance != null;

                // Verify MS-OXORULE requirement: MS-OXORULE_R736
                this.Site.CaptureRequirementIfIsTrue(
                    isVerifiedR736,
                    736,
                    @"[In OP_MOVE and OP_COPY ActionData Structure] [Buffer Format for Standard Rules] If the value of the FolderInThisStore field is 0x01, this field [FolderEID] contains a ServerEid structure, as specified in section 2.2.5.1.2.1.1. ");

                FolderID folderId = new FolderID();
                folderId.Deserialize(BitConverter.ToUInt64(serverEIDOfResponse.FolderID, 0));

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

                bool isVerifiedR983 = folderId.ReplicaId != null && folderId.GlobalCounter != null;

                // Verify MS-OXORULE requirement: MS-OXORULE_R983
                this.Site.CaptureRequirementIfIsTrue(
                    isVerifiedR983,
                    983,
                    @"[In ServerEid Structure] FolderId (8 bytes): A Folder ID structure, as specified in [MS-OXCDATA] section 2.2.1.1, identifies the destination folder.");
                if (Common.IsRequirementEnabled(7032, this.Site))
                {
                    // Add the debug information
                    this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R7032");

                    bool isVerifiedR703 = moveActionDataOfQueryRowsResponse.FolderInThisStore == 0x01 && getNewFolder1MailMessageContent.RowCount != 0;

                    // Verify MS-OXORULE requirement: MS-OXORULE_R7032
                    this.Site.CaptureRequirementIfIsTrue(
                        isVerifiedR703,
                        7032,
                        @"[In Appendix A: Product Behavior] Implementation does set this field (FolderInThisStore) to 0x01 if the destination folder is in the user's mailbox. (Exchange 2007 and Exchange 2016 follow this behavior).");
                }
                #endregion
                #endregion
            }

            #region Delete the newly created folder.
            RopDeleteFolderResponse deleteFolder = this.OxoruleAdapter.RopDeleteFolder(this.InboxFolderHandle, newFolderId);
            Site.Assert.AreEqual<uint>(0, deleteFolder.ReturnValue, "Deleting folder should succeed.");
            #endregion
        }
        public void MSOXORULE_S02_TC11_ServerExecuteRule_Action_OP_COPY()
        {
            this.CheckMAPIHTTPTransportSupported();
            Site.Assume.IsTrue(Common.IsRequirementEnabled(298, this.Site), "This case runs only when the server supports OP_COPY action when FolderInThisStore is set to 0.");

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

            #region TestUser1 creates folder1 in server store.
            RopCreateFolderResponse createFolderResponse;
            uint newFolderHandle = this.OxoruleAdapter.RopCreateFolder(this.InboxFolderHandle, Common.GenerateResourceName(this.Site, "User1Folder"), "TestForOP_COPY", out createFolderResponse);
            ulong newFolderId = createFolderResponse.FolderId;
            Site.Assert.AreEqual<uint>(0, createFolderResponse.ReturnValue, "Creating folder operation should succeed.");
            #endregion

            #region Prepare rules' data.
            MoveCopyActionData moveCopyActionData = new MoveCopyActionData();

            // Get the created folder entry ID.
            byte[] folderEId = this.OxoruleAdapter.GetFolderEntryId(StoreObjectType.Mailbox, newFolderHandle, newFolderId);

            // Get the store object's entry ID.
            byte[] storeEId = this.GetStoreObjectEntryID(StoreObjectType.Mailbox, this.Server, this.User1ESSDN);
            moveCopyActionData.FolderInThisStore = 0;
            moveCopyActionData.FolderEID = folderEId;
            moveCopyActionData.StoreEID = storeEId;
            moveCopyActionData.FolderEIDSize = (ushort)folderEId.Length;
            moveCopyActionData.StoreEIDSize = (ushort)storeEId.Length;
            #endregion

            #region Generate test RuleData.
            // Add rule for OP_COPY without rule Provider Data.
            ruleProperties.ProviderData = string.Empty;
            RuleData ruleForCopy = AdapterHelper.GenerateValidRuleData(ActionType.OP_COPY, TestRuleDataType.ForAdd, 0, RuleState.ST_ENABLED, moveCopyActionData, ruleProperties, null);
            #endregion

            #region TestUser1 adds OP_COPY rule to the Inbox folder.
            RopModifyRulesResponse modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForCopy });
            Site.Assert.AreEqual<uint>(0, modifyRulesResponse.ReturnValue, "Adding Copy rule should succeed.");
            #endregion

            #region TestUser2 delivers a message to TestUser1 to trigger these rules.

            // TestUser2 delivers a message to trigger these rules.
            string mailSubject = Common.GenerateResourceName(this.Site, ruleProperties.ConditionSubjectName + "Title");
            this.SUTAdapter.SendMailToRecipient(this.User2Name, this.User2Password, this.User1Name, mailSubject);

            // Wait for the mail to be received and the rule to take effect.
            Thread.Sleep(this.WaitForTheRuleToTakeEffect);
            #endregion

            #region TestUser1 gets the message content to verify the rule evaluation.
            PropertyTag[] propertyTagList = new PropertyTag[1];
            propertyTagList[0].PropertyId = (ushort)PropertyId.PidTagSubject;
            propertyTagList[0].PropertyType = (ushort)PropertyType.PtypString;

            uint inboxFolderContentTableHandler = 0;
            uint newFolderContentTableHandler = 0;
            int inboxFolderMessageIndex = 0;
            int newFolderMessageIndex = 0;
            RopQueryRowsResponse getInboxFolderMailMessageContent = this.GetExpectedMessage(this.InboxFolderHandle, ref inboxFolderContentTableHandler, propertyTagList, ref inboxFolderMessageIndex, mailSubject);
            Site.Assert.AreEqual<uint>(0, getInboxFolderMailMessageContent.ReturnValue, "Getting message on the inbox folder should succeed.");

            RopQueryRowsResponse getNewFolderMailMessageContent = this.GetExpectedMessage(newFolderHandle, ref newFolderContentTableHandler, propertyTagList, ref newFolderMessageIndex, mailSubject);
            Site.Assert.AreEqual<uint>(0, getNewFolderMailMessageContent.ReturnValue, "Getting message on the newly created folder should succeed.");
            string mailSubject2 = AdapterHelper.PropertyValueConvertToString(getNewFolderMailMessageContent.RowData.PropertyRows[newFolderMessageIndex].PropertyValues[0].Value);

            this.VerifyActionTypeOP_COPY(mailSubject2, getNewFolderMailMessageContent, getInboxFolderMailMessageContent, ruleProperties);

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

            // Verify MS-OXORULE requirement: MS-OXORULE_R298.
            // When the server copies the message to the destination store, it means StoreEID is set to the destination store EntryID.
            bool isVerifyR298 = mailSubject2.Equals(mailSubject) && getNewFolderMailMessageContent.RowCount == 1 && getInboxFolderMailMessageContent.RowCount == 1;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR298,
                298,
                @"[In OP_MOVE and OP_COPY ActionData Structure] [Buffer Format for Standard Rules] StoreEID (variable):  A Store Object EntryID structure, as specified in [MS-OXCDATA] section 2.2.4.3, [In OP_COPY action data] Identifies the message store.");
            #endregion

            #region Delete the newly created folder.
            RopDeleteFolderResponse deleteFolder = this.OxoruleAdapter.RopDeleteFolder(this.InboxFolderHandle, newFolderId);
            Site.Assert.AreEqual<uint>(0, deleteFolder.ReturnValue, "Deleting folder should succeed.");
            #endregion
        }
        public void MSOXORULE_S02_TC10_ServerExecuteRule_Action_OP_MOVE()
        {
            this.CheckMAPIHTTPTransportSupported();
            Site.Assume.IsTrue(Common.IsRequirementEnabled(929, this.Site), "This case runs only when the server supports OP_MOVE action when FolderInThisStore is set to 0.");

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

            #region TestUser1 creates folder1 in server store.
            RopCreateFolderResponse createFolderResponse;
            uint newFolderHandle = this.OxoruleAdapter.RopCreateFolder(this.InboxFolderHandle, Common.GenerateResourceName(this.Site, "User1Folder01"), "TestForOP_MOVE", out createFolderResponse);
            ulong newFolderId = createFolderResponse.FolderId;
            Site.Assert.AreEqual<uint>(0, createFolderResponse.ReturnValue, "Creating folder operation should succeed.");
            #endregion

            #region Prepare rules' data
            MoveCopyActionData moveCopyActionData1 = new MoveCopyActionData();

            // Get the created folder1 entry id.
            byte[] folder1EId = this.OxoruleAdapter.GetFolderEntryId(StoreObjectType.Mailbox, newFolderHandle, newFolderId);

            // Get the store object's entry id
            byte[] storeEId = this.GetStoreObjectEntryID(StoreObjectType.Mailbox, this.Server, this.User1ESSDN);
            moveCopyActionData1.FolderInThisStore = 0;
            moveCopyActionData1.FolderEID = folder1EId;
            moveCopyActionData1.StoreEID = storeEId;
            moveCopyActionData1.FolderEIDSize = (ushort)folder1EId.Length;
            moveCopyActionData1.StoreEIDSize = (ushort)storeEId.Length;

            IActionData[] moveCopyActionData = { moveCopyActionData1 };
            #endregion

            #region Generate test RuleData.
            // Add rule for move without rule Provider Data.
            ruleProperties.ProviderData = string.Empty;
            RuleData ruleForMoveFolder = AdapterHelper.GenerateValidRuleDataWithFlavor(new ActionType[] { ActionType.OP_MOVE }, 0, RuleState.ST_ENABLED, moveCopyActionData, new uint[] { 0 }, ruleProperties);

            #endregion

            #region TestUser1 adds OP_MOVE rule to the Inbox folder.
            RopModifyRulesResponse modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForMoveFolder });
            Site.Assert.AreEqual<uint>(0, modifyRulesResponse.ReturnValue, "Adding Move rule should succeed.");
            #endregion

            #region TestUser2 delivers a message to TestUser1 to trigger these rules.

            // TestUser2 deliver a message to trigger these rules.
            string mailSubject = Common.GenerateResourceName(this.Site, ruleProperties.ConditionSubjectName + "Title");
            this.SUTAdapter.SendMailToRecipient(this.User2Name, this.User2Password, this.User1Name, mailSubject);

            // Wait for the mail to be received and the rule to take effect.
            Thread.Sleep(this.WaitForTheRuleToTakeEffect);
            #endregion

            #region TestUser1 gets the message content to verify the rule evaluation.
            uint inboxFolderContentsTableHandle = 0;
            PropertyTag[] propertyTagList = new PropertyTag[1];
            propertyTagList[0].PropertyId = (ushort)PropertyId.PidTagSubject;
            propertyTagList[0].PropertyType = (ushort)PropertyType.PtypString;

            bool doesOriginalMessageExist = this.CheckUnexpectedMessageExist(this.InboxFolderHandle, ref inboxFolderContentsTableHandle, propertyTagList, mailSubject);
            uint newFolder1ContentsTableHandle = 0;
            uint rowCount = 0;
            RopQueryRowsResponse getNewFolder1MailMessageContent = this.GetExpectedMessage(newFolderHandle, ref newFolder1ContentsTableHandle, propertyTagList, ref rowCount, 1, mailSubject);
            Site.Assert.AreEqual<uint>(0, getNewFolder1MailMessageContent.ReturnValue, "Getting message on the folder should succeed.");

            this.VerifyActionTypeOP_MOVE(getNewFolder1MailMessageContent, doesOriginalMessageExist);

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

            // Verify MS-OXORULE requirement: MS-OXORULE_R929.
            // When the server moves the message to the destination store, it means StoreEID is set to the destination store EntryID.
            bool isVerifyR929 = getNewFolder1MailMessageContent.RowCount == 1 && !doesOriginalMessageExist;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR929,
                929,
                @"[In OP_MOVE and OP_COPY ActionData Structure] [Buffer Format for Standard Rules] StoreEID (variable):  A Store Object EntryID structure, as specified in [MS-OXCDATA] section 2.2.4.3, [In OP_MOVE action data] Identifies the message store.");
            #endregion

            #region Delete the folders created in step2 and step3.
            RopDeleteFolderResponse deleteFolder = this.OxoruleAdapter.RopDeleteFolder(this.InboxFolderHandle, newFolderId);
            Site.Assert.AreEqual<uint>(0, deleteFolder.ReturnValue, "Deleting folder should succeed.");
            #endregion
        }
        public void MSOXORULE_S04_TC04_AddNotSupportedRule_OnPublicFolder()
        {
            this.CheckMAPIHTTPTransportSupported();

            #region TestUser2 logs on to the public folder.
            RopOpenFolderResponse openFolderResponse;
            RopLogonResponse logonResponse;
            bool ret = this.OxoruleAdapter.Connect(ConnectionType.PublicFolderServer, this.User2Name, this.User2ESSDN, this.User2Password);
            Site.Assert.IsTrue(ret, "connect to public folder server should be successful");
            uint publicFolderLogonHandler = this.OxoruleAdapter.RopLogon(LogonType.PublicFolder, this.User2ESSDN, out logonResponse);

            // Assert the client to log on to the public folder successfully.
            Site.Assert.AreEqual<uint>(0, logonResponse.ReturnValue, "Logon the public folder should be successful.");

            // Folder index 1 is the Interpersonal Messages subtree, and this is defined in MS-OXCSTOR.
            uint publicfolderHandler = this.OxoruleAdapter.RopOpenFolder(publicFolderLogonHandler, logonResponse.FolderIds[1], out openFolderResponse);
            ulong publicFolderID = logonResponse.FolderIds[1];
            #endregion

            #region TestUser2 tests the unsupported rules in public folder.
            #region TestUser2 prepares value for ruleProperties variable.
            RuleProperties ruleProperties = AdapterHelper.GenerateRuleProperties(this.Site, Constants.RuleNameDeferredAction);
            #endregion

            #region TestUser2 adds a Rule set Action Type to OP_DEFER_ACTION.
            DeferredActionData deferredActionData = new DeferredActionData
            {
                Data = Common.GetBytesFromBinaryHexString(Constants.DeferredActionBufferData)
            };
            RuleData deferredActionRuleData = AdapterHelper.GenerateValidRuleData(ActionType.OP_DEFER_ACTION, TestRuleDataType.ForAdd, 5, RuleState.ST_ENABLED, deferredActionData, ruleProperties, null);
            RopModifyRulesResponse ropModifyRulesResponse = this.OxoruleAdapter.RopModifyRules(publicfolderHandler, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { deferredActionRuleData });
            #endregion

            // Add the debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R258: server returned value is {0}", ropModifyRulesResponse.ReturnValue);

            // Verify MS-OXORULE requirement: MS-OXORULE_R258.
            // If the ReturnValue is not 0x00000000, it means the server failed to add a public folder rule with this OP_DEFER_ACTION Type action.
            // So it is not used in a public folder rule.
            bool isVerifyR258 = ropModifyRulesResponse.ReturnValue != 0x00000000;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR258,
                258,
                @"[In ActionBlock Structure] The meaning of action type OP_DEFER_ACTION: MUST NOT be used in a public folder rule (2).");

            #region TestUser2 prepares rules' data.
            MoveCopyActionData moveCopyActionData = new MoveCopyActionData();

            // Get the Inbox folder entry ID.
            byte[] folderEId = this.OxoruleAdapter.GetFolderEntryId(StoreObjectType.PublicFolder, publicfolderHandler, publicFolderID);

            // Get the store object's entry ID.
            byte[] storeEId = this.GetStoreObjectEntryID(StoreObjectType.PublicFolder, this.Server, this.User1ESSDN);
            moveCopyActionData.FolderEID = folderEId;
            moveCopyActionData.StoreEID = storeEId;
            moveCopyActionData.FolderEIDSize = (ushort)folderEId.Length;
            moveCopyActionData.StoreEIDSize = (ushort)storeEId.Length;
            #endregion

            #region TestUser2 prepares value for ruleProperties variable.
            ruleProperties = AdapterHelper.GenerateRuleProperties(this.Site, Constants.RuleNameMoveOne);
            #endregion

            #region TestUser2 adds OP_MOVE rule to the public folder.
            ruleProperties.Name = Common.GenerateResourceName(this.Site, Constants.RuleNameMoveOne);
            RuleData ruleForMove = AdapterHelper.GenerateValidRuleData(ActionType.OP_MOVE, TestRuleDataType.ForAdd, 0, RuleState.ST_ENABLED, moveCopyActionData, ruleProperties, null);
            RopModifyRulesResponse modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(publicfolderHandler, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForMove });
            #endregion

            // Add the debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R839: server returned value is {0}", modifyRulesResponse.ReturnValue);

            // Verify MS-OXORULE requirement: MS-OXORULE_R839.
            // If the returnValue is not 0x00000000, it means this OP_MOVE Type used in a public folder rule is failed,
            // so it is not used in a public folder rule.
            bool isVerifyR839 = modifyRulesResponse.ReturnValue != 0x00000000;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR839,
                839,
                @"[In ActionBlock Structure] The meaning of action type OP_MOVE: MUST NOT be used in a public folder rule (2).");

            #region TestUser2 adds OP_COPY rule to the public folder.
            ruleProperties.Name = Common.GenerateResourceName(this.Site, Constants.RuleNameMoveTwo);
            RuleData ruleForCopy = AdapterHelper.GenerateValidRuleData(ActionType.OP_COPY, TestRuleDataType.ForAdd, 1, RuleState.ST_ENABLED, moveCopyActionData, ruleProperties, null);
            modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(publicfolderHandler, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForCopy });
            #endregion

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R840: server returned value is {0}", modifyRulesResponse.ReturnValue);

            // Verify MS-OXORULE requirement: MS-OXORULE_R840.
            // If the ReturnValue is not 0x00000000, it means this OP_COPY Type used in a public folder rule is failed,
            // so it is not used in a public folder rule.
            bool isVerifyR840 = modifyRulesResponse.ReturnValue != 0x00000000;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR840,
                840,
                @"[In ActionBlock Structure] The meaning of action type OP_COPY: MUST NOT be used in a public folder rule (2).");
            #endregion
        }