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
}