public void MSOXORULE_S02_TC12_ServerExecuteRules_InOrder()
{
this.CheckMAPIHTTPTransportSupported();
#region Prepare value for ruleProperties variable.
RuleProperties ruleProperties = AdapterHelper.GenerateRuleProperties(this.Site, Constants.RuleNameForward);
#endregion
#region TestUser1 adds a rule for ActionType OP_Forward with rule sequence set to 1.
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, 1, RuleState.ST_ENABLED, forwardActionData, ruleProperties, null);
RopModifyRulesResponse ropModifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForward });
Site.Assert.AreEqual<uint>(0, ropModifyRulesResponse.ReturnValue, "Adding Forward rule should succeed.");
#endregion
#region TestUser1 adds a delete rule for Inbox folder with rule Sequence set to 100.
ruleProperties.Name = Common.GenerateResourceName(this.Site, Constants.RuleNameDelete);
RuleData ruleForDelete = AdapterHelper.GenerateValidRuleData(ActionType.OP_DELETE, TestRuleDataType.ForAdd, 100, RuleState.ST_ENABLED, new DeleteMarkReadActionData(), ruleProperties, null);
ropModifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_OnExisting, new RuleData[] { ruleForDelete });
Site.Assert.AreEqual<uint>(0, ropModifyRulesResponse.ReturnValue, "Adding Delete rule should succeed.");
#endregion
#region TestUser1 gets 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 for the newly added rule.
PropertyTag[] propertyTags = new PropertyTag[]
{
new PropertyTag
{
PropertyId = (ushort)PropertyId.PidTagRuleName,
PropertyType = (ushort)PropertyType.PtypString
}
};
// Retrieve 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.");
// Two rules have been added to the Inbox folder, so the row count in the rule table should be 2.
Site.Assert.AreEqual<uint>(2, queryRowResponse.RowCount, "The rule number in the rule table is {0}", queryRowResponse.RowCount);
this.VerifyRuleTable();
#region Capture Code
// Add the debug information.
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R778");
// Add two rules to the Inbox folder. If the rule table is got successfully and the rule count is 2,
// it means that the server had stored all previously created rules.
Site.CaptureRequirementIfAreEqual<uint>(
2,
queryRowResponse.RowCount,
778,
@"[In Returning and Maintaining the Rules Table] When a user creates or modifies a rule using the RopModifyRules ROP request ([MS-OXCROPS] section 2.2.11.1), the server MUST store this and all previously created rules.");
// Add the debug information.
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R779: the row count of the rule table is {0}", queryRowResponse.RowCount);
// Add two rules to the Inbox folder. If the rule table is got successfully and the rule count is 2. This requirement can be verified.
Site.CaptureRequirementIfAreEqual<uint>(
2,
queryRowResponse.RowCount,
779,
@"[In Returning and Maintaining the Rules Table] [When a user creates or modifies a rule using the RopModifyRules ROP request ([MS-OXCROPS] section 2.2.11.1)] The server MUST also respond to a RopGetRulesTable ROP request ([MS-OXCROPS] section 2.2.11.2) by returning these rules to the client in the form of a rules table.");
#endregion
#endregion
#region TestUser1 delivers a message to itself to trigger these rules.
Thread.Sleep(this.WaitForTheRuleToTakeEffect);
// TestUser1 delivers a message to itself to trigger these rules.
string mailSubject = Common.GenerateResourceName(this.Site, ruleProperties.ConditionSubjectName + "Title");
this.SUTAdapter.SendMailToRecipient(this.User1Name, this.User1Password, this.User1Name, mailSubject);
Thread.Sleep(this.WaitForTheRuleToTakeEffect);
#endregion
#region TestUser1 gets the messages in the Inbox to verify the rule evaluation.
PropertyTag[] propertyTagList = new PropertyTag[2];
// pidTagSubject and pidTagMessageClass
propertyTagList[0].PropertyId = (ushort)PropertyId.PidTagSubject;
propertyTagList[0].PropertyType = (ushort)PropertyType.PtypString;
propertyTagList[1].PropertyId = (ushort)PropertyId.PidTagMessageClass;
propertyTagList[1].PropertyType = (ushort)PropertyType.PtypString;
uint contentsTableHandle = 0;
bool doesUnexpectedMessageExist = this.CheckUnexpectedMessageExist(this.InboxFolderHandle, ref contentsTableHandle, propertyTagList, mailSubject);
#endregion
#region TestUser2 gets the forwarded message to verify the rule evaluation.
// Let Testuser2 to logon to the server
this.LogonMailbox(TestUser.TestUser2);
uint contentTableHandler = 0;
int expectedMessageIndex = 0;
RopQueryRowsResponse testUser2getNormalMailMessageContent = this.GetExpectedMessage(this.InboxFolderHandle, ref contentTableHandler, propertyTagList, ref expectedMessageIndex, mailSubject);
Site.Assert.AreEqual<uint>(0, testUser2getNormalMailMessageContent.ReturnValue, "Getting message property operation should succeed.");
string testUser2mailSubject = AdapterHelper.PropertyValueConvertToString(testUser2getNormalMailMessageContent.RowData.PropertyRows[expectedMessageIndex].PropertyValues[0].Value);
// Add the debug information.
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R514, the value of mailSubject is {0}", testUser2mailSubject);
// Verify MS-OXORULE requirement: MS-OXORULE_R514.
// This test case has added 2 rules (OP_FORWARD and OP_DELETE) in increasing order of the value of the PidTagRuleSequence property.
// According to this order, OP_FORWARD should be performed before OP_DELETE.
// If there is a message existing under the forwarded recipient's Inbox folder, whose subject name contains the original received message's subject name,
// it means the server has forwarded the message to the corresponding recipient before executing the OP_DELETE rule.
// If the RowCount of getMailMessageContent equals 0, it means the original received message under the administrator's Inbox folder
// has been deleted. So it proves the server evaluates each rule in the increasing order.
bool isVerifyR514 = testUser2mailSubject.ToUpperInvariant().Contains(mailSubject.ToUpperInvariant()) && !doesUnexpectedMessageExist;
Site.CaptureRequirementIfIsTrue(
isVerifyR514,
514,
@"[In Processing Incoming Messages to a Folder] For each message delivered to a folder, the server evaluates each rule (2) in that folder in increasing order of the value of the PidTagRuleSequence property (section 2.2.1.3.1.2) in each rule (2).");
#endregion
}