public void MSOXORULE_S01_TC03_AddExtendedRule_WithLargeMessageCondition()
{
this.CheckMAPIHTTPTransportSupported();
#region TestUser1 creates an FAI message.
RopCreateMessageResponse ropCreateMessageResponse;
uint extendedRuleMessageHandle = this.OxoruleAdapter.RopCreateMessage(this.InboxFolderHandle, this.InboxFolderID, Convert.ToByte(true), out ropCreateMessageResponse);
Site.Assert.AreEqual<uint>(0, ropCreateMessageResponse.ReturnValue, "Creating the first FAI message should succeed.");
#endregion
#region TestUser1 adds the extended rule with NamedProperty successfully.
string ruleConditionSubjectName = Constants.RuleConditionSubjectContainString;
NamedPropertyInfo namedPropertyInfo = new NamedPropertyInfo
{
NoOfNamedProps = 2,
PropId = new uint[2]
{
0x8001, 0x8002
}
};
// 0x01 means the property is identified by the name property.
PropertyName testPropertyName = new PropertyName
{
Guid = System.Guid.NewGuid().ToByteArray(),
Kind = 0x01,
Name = Encoding.Unicode.GetBytes(Constants.NameOfPropertyName + "\0")
};
testPropertyName.NameSize = (byte)testPropertyName.Name.Length;
// 0x00 means the property is identified by the LID.
PropertyName secondPropertyName = new PropertyName
{
Guid = System.Guid.NewGuid().ToByteArray(),
Kind = 0x00,
LID = 0x88888888
};
namedPropertyInfo.NamedProperty = new PropertyName[2] { testPropertyName, secondPropertyName };
namedPropertyInfo.NamedPropertiesSize = (uint)(testPropertyName.Serialize().Length + secondPropertyName.Serialize().Length);
string ruleName = Common.GenerateResourceName(this.Site, Constants.ExtendRulename1);
TaggedPropertyValue[] extendedRuleProperties = AdapterHelper.GenerateExtendedRuleTestData(ruleName, 0, (uint)RuleState.ST_ENABLED, Constants.PidTagRuleProvider, ActionType.OP_MARK_AS_READ, new DeleteMarkReadActionData(), ruleConditionSubjectName, namedPropertyInfo);
// Set properties for extended rule FAI message.
RopSetPropertiesResponse ropSetPropertiesResponse = this.OxoruleAdapter.RopSetProperties(extendedRuleMessageHandle, extendedRuleProperties);
Site.Assert.AreEqual<uint>(0, ropSetPropertiesResponse.ReturnValue, "Setting property for Extended rule FAI message should succeed.");
// Save changes of message.
RopSaveChangesMessageResponse ropSaveChangesMessagResponse = this.OxoruleAdapter.RopSaveChangesMessage(extendedRuleMessageHandle);
Site.Assert.AreEqual<uint>(0, ropSaveChangesMessagResponse.ReturnValue, "Saving Extend rule message should succeed.");
// Specify the properties to be got.
PropertyTag[] propertyTagArray = new PropertyTag[2];
// PidTagRuleMessageProviderData
propertyTagArray[0].PropertyId = (ushort)PropertyId.PidTagRuleMessageProvider;
propertyTagArray[0].PropertyType = (ushort)PropertyType.PtypString;
// PidTagRuleMessageName
propertyTagArray[1].PropertyId = (ushort)PropertyId.PidTagRuleMessageName;
propertyTagArray[1].PropertyType = (ushort)PropertyType.PtypString;
// Get the specific properties of the extended rule.
RopGetPropertiesSpecificResponse ropGetPropertiesSpecificResponse = this.OxoruleAdapter.RopGetPropertiesSpecific(extendedRuleMessageHandle, propertyTagArray);
Site.Assert.AreEqual<uint>(0, ropGetPropertiesSpecificResponse.ReturnValue, "Getting folder id property operation should succeed.");
#region Capture Code
// Add the debug information
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R184");
// Verify MS-OXORULE requirement: MS-OXORULE_R184
string pidTagRuleMessageProviderData = AdapterHelper.PropertyValueConvertToString(ropGetPropertiesSpecificResponse.RowData.PropertyValues[0].Value);
Site.CaptureRequirementIfAreEqual<string>(
Constants.PidTagRuleProvider,
pidTagRuleMessageProviderData,
184,
@"[In PidTagRuleMessageProvider Property] This property has the same semantics as the PidTagRuleProvider property (section 2.2.1.3.1.5). [The PidTagRuleMessageProvider property identifies the client application that owns the rule (2).]");
// Add the debug information
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R164");
// Verify MS-OXORULE requirement: MS-OXORULE_R164
// The rule name set by client is "ExtendRulename1".
string pidTagRuleMessageNameValue = AdapterHelper.PropertyValueConvertToString(ropGetPropertiesSpecificResponse.RowData.PropertyValues[1].Value);
Site.CaptureRequirementIfAreEqual<string>(
ruleName,
pidTagRuleMessageNameValue,
164,
@"[In PidTagRuleMessageName Property] This property has the same semantics as the PidTagRuleName property (section 2.2.1.3.1.4). [The PidTagRuleMessageName property specifies the name of the rule (2).]");
#endregion
#endregion
#region TestUser1 retrieves data of the new extended rule.
this.OxoruleAdapter.TargetOfRop = TargetOfRop.ForExtendedRules;
RopGetPropertiesAllResponse ropGetExtendRuleMessageResponse = this.OxoruleAdapter.RopGetPropertiesAll(extendedRuleMessageHandle, this.PropertySizeLimitFlag, (ushort)WantUnicode.Want);
Site.Assert.AreEqual<uint>(0, ropGetExtendRuleMessageResponse.ReturnValue, "Getting all properties operation should succeed.");
Site.Assert.IsTrue(ropGetExtendRuleMessageResponse.PropertyValues.Length != 0, "Extended Rule data should be found in related FAI message!");
this.OxoruleAdapter.TargetOfRop = TargetOfRop.OtherTarget;
ExtendedRuleActions extendedRuleMessageActions = null;
// Check the properties set on Extended Rule, and find the Extended Rule Actions.
for (int i = 0; i < ropGetExtendRuleMessageResponse.PropertyValues.Length; i++)
{
// propertyId indicates the Id of a property set on Extended Rule.
ushort propertyId = ropGetExtendRuleMessageResponse.PropertyValues[i].PropertyTag.PropertyId;
if (propertyId == (ushort)PropertyId.PidTagExtendedRuleMessageActions)
{
byte[] propertyValue = ropGetExtendRuleMessageResponse.PropertyValues[i].Value;
extendedRuleMessageActions = AdapterHelper.PropertyValueConvertToExtendedRuleActions(propertyValue);
break;
}
}
Site.Assert.AreNotEqual<ExtendedRuleActions>(null, extendedRuleMessageActions, "extendedRuleMessageActions should not be null.");
// Get the Property Names saved by server in the extendedRuleMessageActions.
PropertyName[] propertyNames = extendedRuleMessageActions.NamedPropertyInformation.NamedProperty;
PropertyName testPropertyNameSavedOnServer = new PropertyName();
PropertyName secondPropertyNameSavedOnServer = new PropertyName();
if (propertyNames != null && propertyNames.Length > 0)
{
for (int i = 0; i < propertyNames.Length; i++)
{
// If the Kind is 0x01, it means this PropertyName is the testPropertyName.
if (propertyNames[i].Kind == 0x01)
{
testPropertyNameSavedOnServer = propertyNames[i];
}
else if (propertyNames[i].Kind == 0x00)
{
// If the Kind is 0x00, it means this PropertyName is the secondPropertyName.
secondPropertyNameSavedOnServer = propertyNames[i];
}
}
}
Site.Assert.IsNotNull(testPropertyNameSavedOnServer.Guid, "testPropertyNameSavedOnServer should not be null.");
Site.Assert.IsNotNull(secondPropertyNameSavedOnServer.Guid, "secondPropertyNameSavedOnServer should not be null.");
#endregion
#region TestUser1 creates a new FAI message.
extendedRuleMessageHandle = this.OxoruleAdapter.RopCreateMessage(this.InboxFolderHandle, this.InboxFolderID, Convert.ToByte(true), out ropCreateMessageResponse);
Site.Assert.AreEqual<uint>(0, ropCreateMessageResponse.ReturnValue, "Creating the second FAI message should succeed.");
#endregion
#region TestUser1 creates an extended rule with PidTagExtendedRuleMessageCondition property value size larger than the size set by the server.
propertyTagArray = new PropertyTag[1];
propertyTagArray[0].PropertyId = (ushort)PropertyId.PidTagExtendedRuleSizeLimit;
propertyTagArray[0].PropertyType = (ushort)PropertyType.PtypInteger32;
ropGetPropertiesSpecificResponse = this.OxoruleAdapter.RopGetPropertiesSpecific(this.LogonHandle, propertyTagArray);
uint pidTagExtendedRuleSizeLimit = Common.ConvertByteArrayToUint(ropGetPropertiesSpecificResponse.RowData.PropertyValues[0].Value);
// According to MS-OXCRPC, "The server SHOULD fail with the RPC status code of RPC_X_BAD_STUB_DATA (0x000006F7) if the request buffer is larger than 0x00040000 bytes in size."
if (pidTagExtendedRuleSizeLimit < 0x00040000)
{
ruleConditionSubjectName = Constants.RuleConditionSubjectContainString;
namedPropertyInfo = new NamedPropertyInfo
{
NoOfNamedProps = 2,
PropId = new uint[2]
{
0x8001, 0x8002
}
};
// Generate a string value whose size lager than the one specified by the PidTagExtendedRuleSizeLimit property.
StringBuilder stringByteValue = new StringBuilder("ExtentRuleSize");
stringByteValue.Append('a', (int)pidTagExtendedRuleSizeLimit);
// If the value of Kind is 0x01, it means that the property is identified by the name property.
testPropertyName = new PropertyName
{
Guid = System.Guid.NewGuid().ToByteArray(),
Kind = 0x01,
Name = Encoding.Unicode.GetBytes(stringByteValue + "\0")
};
testPropertyName.NameSize = (byte)testPropertyName.Name.Length;
// If the value of Kind is 0x00, it means that the property is identified by the LID.
secondPropertyName = new PropertyName
{
Guid = System.Guid.NewGuid().ToByteArray(),
Kind = 0x00,
LID = 0x88888888
};
namedPropertyInfo.NamedProperty = new PropertyName[2] { testPropertyName, secondPropertyName };
namedPropertyInfo.NamedPropertiesSize = (uint)(testPropertyName.Serialize().Length + secondPropertyName.Serialize().Length);
extendedRuleProperties = AdapterHelper.GenerateExtendedRuleTestData(Common.GenerateResourceName(this.Site, Constants.ExtendRulename1), 0, (uint)RuleState.ST_ENABLED, Constants.PidTagRuleProvider, ActionType.OP_MARK_AS_READ, new DeleteMarkReadActionData(), ruleConditionSubjectName, namedPropertyInfo);
TaggedPropertyValue pidTagExtendedRuleMessageCondition = new TaggedPropertyValue();
foreach (TaggedPropertyValue propertyValue in extendedRuleProperties)
{
if (propertyValue.PropertyTag.PropertyId == (ushort)PropertyId.PidTagExtendedRuleMessageCondition)
{
pidTagExtendedRuleMessageCondition = propertyValue;
break;
}
}
uint pidTagExtendedRuleMessageConditionSize = uint.Parse(pidTagExtendedRuleMessageCondition.Value.Length.ToString());
// Set properties for extended rule FAI message.
ropSetPropertiesResponse = this.OxoruleAdapter.RopSetProperties(extendedRuleMessageHandle, extendedRuleProperties);
// Save changes of message.
ropSaveChangesMessagResponse = this.OxoruleAdapter.RopSaveChangesMessage(extendedRuleMessageHandle);
// Add the debug information.
Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R1016");
// Verify MS-OXORULE requirement: MS-OXORULE_R1016.
if (pidTagExtendedRuleMessageConditionSize > pidTagExtendedRuleSizeLimit)
{
Site.CaptureRequirementIfAreNotEqual<uint>(
0x0000,
ropSaveChangesMessagResponse.ReturnValue,
1016,
@"[In Processing Incoming Messages to a Folder] If the PidTagExtendedRuleSizeLimit property is set and the size of the PidTagExtendedRuleMessageCondition property (section 2.2.4.1.10) exceeds the value specified by the PidTagExtendedRuleSizeLimit property, the server MUST return an error.");
}
else
{
Site.Assert.Fail("The size of the PidTagExtendedRuleMessageCondition property should exceeds the value specified by the PidTagExtendedRuleSizeLimit property.");
}
}
#endregion
}