public void MSOXORULE_S02_TC08_ServerExecuteRule_Action_OP_DELEGATE()
{
this.CheckMAPIHTTPTransportSupported();
#region Prepare value for ruleProperties variable.
RuleProperties ruleProperties = AdapterHelper.GenerateRuleProperties(this.Site, Constants.RuleNameDelegate);
#endregion
#region TestUser1 adds an OP_DELEGATE rule.
ForwardDelegateActionData delegateActionData = new ForwardDelegateActionData
{
RecipientCount = (ushort)0x01
};
RecipientBlock recipientBlock = new RecipientBlock
{
Reserved = 0x01,
NoOfProperties = (ushort)0x05u
};
#region Prepare recipient Block.
TaggedPropertyValue[] recipientProperties = new TaggedPropertyValue[5];
TaggedPropertyValue[] temp = AdapterHelper.GenerateRecipientPropertiesBlock(this.User2Name, this.User2ESSDN);
Array.Copy(temp, 0, recipientProperties, 0, temp.Length);
// Add PidTagSmtpEmailAdderss.
recipientProperties[4] = new TaggedPropertyValue();
PropertyTag pidTagSmtpEmailAdderssPropertyTag = new PropertyTag
{
PropertyId = (ushort)PropertyId.PidTagSmtpAddress,
PropertyType = (ushort)PropertyType.PtypString
};
recipientProperties[4].PropertyTag = pidTagSmtpEmailAdderssPropertyTag;
recipientProperties[4].Value = Encoding.Unicode.GetBytes(this.User2Name + "@" + this.Domain + "\0");
recipientBlock.PropertiesData = recipientProperties;
#endregion
delegateActionData.RecipientsData = new RecipientBlock[1] { recipientBlock };
RuleData ruleDelegate = AdapterHelper.GenerateValidRuleData(ActionType.OP_DELEGATE, TestRuleDataType.ForAdd, 1, RuleState.ST_ENABLED, delegateActionData, ruleProperties, null);
RopModifyRulesResponse ropModifyRulesResponse = this.OxoruleAdapter.RopModifyRules(this.InboxFolderHandle, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleDelegate });
Site.Assert.AreEqual<uint>(0, ropModifyRulesResponse.ReturnValue, "Adding delegate rule should succeed.");
#endregion
#region TestUser1 delivers a message to itself to trigger the rule.
Thread.Sleep(this.WaitForTheRuleToTakeEffect);
// TestUser1 delivers a message to itself to trigger the rule.
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 TestUser2 gets the delegate message to verify the rule evaluation.
// Let TestUser2 log on to the server.
this.LogonMailbox(TestUser.TestUser2);
PropertyTag[] propertyTagList = new PropertyTag[7];
propertyTagList[0].PropertyId = (ushort)PropertyId.PidTagSubject;
propertyTagList[0].PropertyType = (ushort)PropertyType.PtypString;
propertyTagList[1].PropertyId = (ushort)PropertyId.PidTagReceivedRepresentingEntryId;
propertyTagList[1].PropertyType = (ushort)PropertyType.PtypBinary;
propertyTagList[2].PropertyId = (ushort)PropertyId.PidTagReceivedRepresentingAddressType;
propertyTagList[2].PropertyType = (ushort)PropertyType.PtypString;
propertyTagList[3].PropertyId = (ushort)PropertyId.PidTagReceivedRepresentingEmailAddress;
propertyTagList[3].PropertyType = (ushort)PropertyType.PtypString;
propertyTagList[4].PropertyId = (ushort)PropertyId.PidTagReceivedRepresentingName;
propertyTagList[4].PropertyType = (ushort)PropertyType.PtypString;
propertyTagList[5].PropertyId = (ushort)PropertyId.PidTagReceivedRepresentingSearchKey;
propertyTagList[5].PropertyType = (ushort)PropertyType.PtypBinary;
propertyTagList[6].PropertyId = (ushort)PropertyId.PidTagDelegatedByRule;
propertyTagList[6].PropertyType = (ushort)PropertyType.PtypBoolean;
uint contentTableHandler = 0;
int expectedMessageIndex = 0;
RopQueryRowsResponse getNormalMailMessageContent = this.GetExpectedMessage(this.InboxFolderHandle, ref contentTableHandler, propertyTagList, ref expectedMessageIndex, mailSubject);
#endregion
#region Get TestUser1's information from address book
// Let TestUser1 log on to the server.
this.LogonMailbox(TestUser.TestUser1);
PropertyTagArray_r ptags = new PropertyTagArray_r
{
Values = 5,
AulPropTag = AdapterHelper.SerializeRecipientProperties()
};
// The Windows NSPI will be invoked when the first parameter is domain name instead of server address.
PropertyRowSet_r? propertyRows = this.OxoruleAdapter.GetRecipientInfo(this.Domain, this.User1Name, this.Domain, this.User1Password, ptags);
Site.Assert.IsNotNull(propertyRows, "The recipient information returned by the NSPI service should not be null");
int user1Index = 0;
for (int i = 0; i < propertyRows.Value.Rows; i++)
{
if (Encoding.Unicode.GetString(propertyRows.Value.PropertyRowSet[i].Props[3].Value.LpszW).ToLower(System.Globalization.CultureInfo.CurrentCulture) == this.User1Name.ToLower(System.Globalization.CultureInfo.CurrentCulture))
{
user1Index = i;
break;
}
}
// The two EntryId should be the same.
AddressBookEntryID addressbookEntryId = new AddressBookEntryID();
addressbookEntryId.Deserialize(propertyRows.Value.PropertyRowSet[user1Index].Props[0].Value.Bin.Lpb);
byte[] pidTagReceivedRepresentingEntryIdbytesTemp = getNormalMailMessageContent.RowData.PropertyRows[expectedMessageIndex].PropertyValues[1].Value;
byte[] pidTagReceivedRepresentingEntryIdbytes = new byte[pidTagReceivedRepresentingEntryIdbytesTemp.Length - 2];
Array.Copy(pidTagReceivedRepresentingEntryIdbytesTemp, 2, pidTagReceivedRepresentingEntryIdbytes, 0, pidTagReceivedRepresentingEntryIdbytes.Length);
AddressBookEntryID mailEntryID = new AddressBookEntryID();
mailEntryID.Deserialize(pidTagReceivedRepresentingEntryIdbytes);
string subject = AdapterHelper.PropertyValueConvertToString(getNormalMailMessageContent.RowData.PropertyRows[expectedMessageIndex].PropertyValues[0].Value);
#region Capture Code
// Add the debug information.
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R539");
// Verify MS-OXORULE requirement: MS-OXORULE_R539.
Site.CaptureRequirementIfAreEqual<string>(
mailSubject,
subject,
539,
@"[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_DELEGATE"": the server MUST resend the message to the recipients (2) specified in the action buffer structure.");
string pidTagEntryIdOfMailboxUser = addressbookEntryId.ValueOfX500DN.ToLower(System.Globalization.CultureInfo.CurrentCulture);
string pidTagReceivedRepresentingEntryId = mailEntryID.ValueOfX500DN.ToLower(System.Globalization.CultureInfo.CurrentCulture);
// Add the debug information.
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R540");
// Verify MS-OXORULE requirement: MS-OXORULE_R540.
Site.CaptureRequirementIfAreEqual<string>(
pidTagReceivedRepresentingEntryId,
pidTagEntryIdOfMailboxUser,
540,
@"[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_DELEGATE"": The server also MUST set the values of the following properties to match the current user's properties in the address book: The PidTagReceivedRepresentingEntryId property ([MS-OXOMSG] section 2.2.1.25) MUST be set to the same value as the mailbox user's PidTagEntryId property ([MS-OXOABK] section 2.2.3.3).");
string pidTagReceivedRepresentingAddressType = Encoding.Unicode.GetString(getNormalMailMessageContent.RowData.PropertyRows[expectedMessageIndex].PropertyValues[2].Value);
// The actual value of pidTagReceivedRepresentingAddressType should not contain the last '\0' character.
pidTagReceivedRepresentingAddressType = pidTagReceivedRepresentingAddressType.Substring(0, pidTagReceivedRepresentingAddressType.Length - 1);
// In this test case, the mailbox user's PidTagAddressType is "EX".
string pidTagAddressTypeOfMailboxUser = System.Text.UTF8Encoding.Unicode.GetString(propertyRows.Value.PropertyRowSet[user1Index].Props[1].Value.LpszW);
// Add the debug information.
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R541");
// Verify MS-OXORULE requirement: MS-OXORULE_R541.
Site.CaptureRequirementIfAreEqual<string>(
pidTagReceivedRepresentingAddressType,
pidTagAddressTypeOfMailboxUser,
541,
@"[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_DELEGATE"": The PidTagReceivedRepresentingAddressType property ([MS-OXOMSG] section 2.2.1.23) MUST be set to the same value as the mailbox user's PidTagAddressType property ([MS-OXOABK] section 2.2.3.13).");
string pidTagReceivedRepresentingEmailAddress = Encoding.Unicode.GetString(getNormalMailMessageContent.RowData.PropertyRows[expectedMessageIndex].PropertyValues[3].Value);
// The actual value of PidTagReceivedRepresentingEmailAddress should not contain the last '\0' character.
pidTagReceivedRepresentingEmailAddress = pidTagReceivedRepresentingEmailAddress.Substring(0, pidTagReceivedRepresentingEmailAddress.Length - 1).ToUpperInvariant();
// In this test case, the mailbox user's PidTagEmailAddress is the adminUserDN.
string pidTagEmailAddressOfMailboxUser = Encoding.Unicode.GetString(propertyRows.Value.PropertyRowSet[user1Index].Props[2].Value.LpszW).ToUpperInvariant();
// Add the debug information.
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R542");
// Verify MS-OXORULE requirement: MS-OXORULE_R542.
Site.CaptureRequirementIfAreEqual<string>(
pidTagReceivedRepresentingEmailAddress,
pidTagEmailAddressOfMailboxUser,
542,
@"[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_DELEGATE"": The PidTagReceivedRepresentingEmailAddress property ([MS-OXOMSG] section 2.2.1.24) MUST be set to the same value as the mailbox user's PidTagEmailAddress property ([MS-OXOABK] section 2.2.3.14).");
string pidTagReceivedRepresentingName = AdapterHelper.PropertyValueConvertToString(getNormalMailMessageContent.RowData.PropertyRows[expectedMessageIndex].PropertyValues[4].Value).ToLower(System.Globalization.CultureInfo.CurrentCulture);
// In this test case, the mailbox user's PidTagDisplayName is "administrator".
string pidTagDisplayNameOfMailboxUser = Encoding.Unicode.GetString(propertyRows.Value.PropertyRowSet[user1Index].Props[3].Value.LpszW).ToLower(System.Globalization.CultureInfo.CurrentCulture);
// Add the debug information.
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R543");
// Verify MS-OXORULE requirement: MS-OXORULE_R543.
Site.CaptureRequirementIfAreEqual<string>(
pidTagReceivedRepresentingName,
pidTagDisplayNameOfMailboxUser,
543,
@"[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_DELEGATE"": The PidTagReceivedRepresentingName property ([MS-OXOMSG] section 2.2.1.26) MUST be set to the same value as the mailbox user's PidTagDisplayName property ([MS-OXCFOLD] section 2.2.2.2.2.5).");
byte[] pidTagReceivedRepresentingSearchKeyOfbytes = getNormalMailMessageContent.RowData.PropertyRows[expectedMessageIndex].PropertyValues[5].Value;
byte[] pidTagReceivedRepresentingSearchKey = AdapterHelper.PropertyValueConvertToBinary(pidTagReceivedRepresentingSearchKeyOfbytes);
byte[] pidTagSearchKeyOfMailboxUser = propertyRows.Value.PropertyRowSet[user1Index].Props[4].Value.Bin.Lpb;
// Add the debug information.
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R544: the value of PidTagReceivedRepresentingSearchKey is {0}", pidTagSearchKeyOfMailboxUser);
// Verify MS-OXORULE requirement: MS-OXORULE_R544.
bool isVerifyR544 = Common.CompareByteArray(pidTagSearchKeyOfMailboxUser, pidTagReceivedRepresentingSearchKey);
Site.CaptureRequirementIfIsTrue(
isVerifyR544,
544,
@"[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_DELEGATE"": The PidTagReceivedRepresentingSearchKey property ([MS-OXOMSG] section 2.2.1.27) MUST be set to the same value as the mailbox user's PidTagSearchKey property ([MS-OXCPRPT] section 2.2.1.9).");
// BitConverter.ToBoolean() is used to convert a byte array to a bool value from the byte array index of 0.
bool pidTagDelegatedByRule = BitConverter.ToBoolean(getNormalMailMessageContent.RowData.PropertyRows[expectedMessageIndex].PropertyValues[6].Value, 0);
// Add the debug information.
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R545");
// Verify MS-OXORULE requirement: MS-OXORULE_R545.
Site.CaptureRequirementIfIsTrue(
pidTagDelegatedByRule,
545,
@"[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_DELEGATE"": The PidTagDelegatedByRule property ([MS-OXOMSG] section 2.2.1.84) MUST be set to ""TRUE"".");
#endregion
#endregion
#region TestUser1 calls RopGetRulesTable with valid TableFlags.
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 calls RopQueryRows to retrieve rows from the rule table
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.");
ForwardDelegateActionData forwardDelegateActionDataOfQueryRowResponse = new ForwardDelegateActionData();
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);
forwardDelegateActionDataOfQueryRowResponse.Deserialize(ruleAction.Actions[0].ActionDataValue.Serialize());
break;
}
}
#region Capture Code
// Add the debug information
this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R1003");
// Verify MS-OXORULE requirement: MS-OXORULE_R1003
this.Site.CaptureRequirementIfIsInstanceOfType(
forwardDelegateActionDataOfQueryRowResponse.RecipientsData,
typeof(RecipientBlock[]),
1003,
@"[In OP_FORWARD and OP_DELEGATE ActionData Structure] RecipientBlocks (variable): An array of RecipientBlockData structures, each of which specifies information about one recipient (2).");
for (int i = 0; i < forwardDelegateActionDataOfQueryRowResponse.RecipientsData.Length; i++)
{
// Add the debug information
this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R1006");
// Verify MS-OXORULE requirement: MS-OXORULE_R1006
this.Site.CaptureRequirementIfIsInstanceOfType(
forwardDelegateActionDataOfQueryRowResponse.RecipientsData[i].PropertiesData,
typeof(TaggedPropertyValue[]),
1006,
@"[In RecipientBlockData Structure] PropertyValues (variable): An array of TaggedPropertyValue structures, each of which contains a property that provides some information about the recipient (2).");
}
#endregion
#endregion
}