public void MSOXORULE_S04_TC01_AddModifyDeleteStandardRule_OnPublicFolder()
{
this.CheckMAPIHTTPTransportSupported();
#region TestUser1 logs on to the public folder.
RopOpenFolderResponse openFolderResponse;
RopLogonResponse logonResponse;
bool ret = this.OxoruleAdapter.Connect(ConnectionType.PublicFolderServer, this.User1Name, this.User1ESSDN, this.User1Password);
Site.Assert.IsTrue(ret, "connect to public folder server should be successful");
uint publicFolderLogonHandler = this.OxoruleAdapter.RopLogon(LogonType.PublicFolder, this.User1ESSDN, 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);
// Get the store object's entry ID.
this.GetStoreObjectEntryID(StoreObjectType.PublicFolder, this.Server, this.User1ESSDN);
RopCreateFolderResponse createFolderResponse;
string newFolderName = Common.GenerateResourceName(this.Site, Constants.FolderDisplayName);
uint newFolderHandle = this.OxoruleAdapter.RopCreateFolder(publicfolderHandler, newFolderName, Constants.FolderComment, out createFolderResponse);
Site.Assert.AreEqual<uint>(0, createFolderResponse.ReturnValue, "Creating folder operation should succeed.");
#endregion
#region TestUser1 prepares value for rule properties variable.
RuleProperties ruleProperties = AdapterHelper.GenerateRuleProperties(this.Site, Constants.RuleNameDelete);
RuleData ruleForDelete = AdapterHelper.GenerateValidRuleData(ActionType.OP_DELETE, TestRuleDataType.ForAdd, 1, RuleState.ST_ENABLED, new DeleteMarkReadActionData(), ruleProperties, null);
#endregion
#region TestUser1 adds rule OP_Delelte.
RopModifyRulesResponse modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(newFolderHandle, ModifyRuleFlag.Modify_ReplaceAll, new RuleData[] { ruleForDelete });
Site.Assert.AreEqual<uint>(0, modifyRulesResponse.ReturnValue, "Adding Delete rule should succeed.");
#endregion
#region TestUser1 gets rule ID of the created rule.
RopGetRulesTableResponse ropGetRulesTableResponse;
uint ruleTableHandle = this.OxoruleAdapter.RopGetRulesTable(newFolderHandle, TableFlags.Normal, out ropGetRulesTableResponse);
Site.Assert.AreEqual<uint>(0, ropGetRulesTableResponse.ReturnValue, "Getting rule table should succeed.");
PropertyTag ruleIDTag = new PropertyTag
{
PropertyId = (ushort)PropertyId.PidTagRuleId,
PropertyType = (ushort)PropertyType.PtypInteger64
};
RopQueryRowsResponse queryRowsResponse = this.OxoruleAdapter.QueryPropertiesInTable(ruleTableHandle, new PropertyTag[1] { ruleIDTag });
Site.Assert.AreEqual<uint>(0, queryRowsResponse.ReturnValue, "Retrieving rows from the rule table should succeed.");
// Only one rule added in this folder, so the row count in the rule table should be 1.
Site.Assert.AreEqual<uint>(1, queryRowsResponse.RowCount, "The rule number in the rule table is {0}", queryRowsResponse.RowCount);
this.VerifyRuleTable();
ulong ruleId = BitConverter.ToUInt64(queryRowsResponse.RowData.PropertyRows[0].PropertyValues[0].Value, 0);
#endregion
#region TestUser1 modifies the created rule.
ruleProperties.Name = Common.GenerateResourceName(this.Site, "RuleNameForModify");
ruleForDelete = AdapterHelper.GenerateValidRuleData(ActionType.OP_DELETE, TestRuleDataType.ForModify, 1, RuleState.ST_ENABLED, new DeleteMarkReadActionData(), ruleProperties, ruleId);
modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(newFolderHandle, ModifyRuleFlag.Modify_OnExisting, new RuleData[] { ruleForDelete });
Site.Assert.AreEqual<uint>(0, modifyRulesResponse.ReturnValue, "Modifying the OP_DELETE rule should be success");
#endregion
#region TestUser1 calls RopGetRulesTable with valid TableFlags.
ruleTableHandle = this.OxoruleAdapter.RopGetRulesTable(newFolderHandle, TableFlags.Normal, out ropGetRulesTableResponse);
#endregion
#region TestUser1 retrieves rule information for the modified rule.
PropertyTag ruleNameTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleName, PropertyType = (ushort)PropertyType.PtypString };
// Retrieves rows from the rule table.
queryRowsResponse = this.OxoruleAdapter.QueryPropertiesInTable(ruleTableHandle, new PropertyTag[2] { ruleIDTag, ruleNameTag });
Site.Assert.AreEqual<uint>(0, queryRowsResponse.ReturnValue, "Retrieving rows from the rule table should succeed.");
// Only one rule added in this folder, so the row count in the rule table should be 1.
Site.Assert.AreEqual<uint>(1, queryRowsResponse.RowCount, "The rule number in the rule table is {0}", queryRowsResponse.RowCount);
this.VerifyRuleTable();
ulong ruleIdModified = BitConverter.ToUInt64(queryRowsResponse.RowData.PropertyRows[0].PropertyValues[0].Value, 0);
bool isSameRuleId = ruleId == ruleIdModified;
Site.Assert.IsTrue(isSameRuleId, "The original rule Id is {0} and the modified rule Id is {1}", ruleId, ruleIdModified);
string modifiedRuleName = AdapterHelper.PropertyValueConvertToString(queryRowsResponse.RowData.PropertyRows.ToArray()[0].PropertyValues[1].Value);
Site.Assert.AreEqual<string>(ruleProperties.Name, modifiedRuleName, "The actual rule name {0} should be equal to the expected rule name {1}.", modifiedRuleName, ruleProperties.Name);
#endregion
#region TestUser1 deletes the created rule.
ruleForDelete = AdapterHelper.GenerateValidRuleData(ActionType.OP_DELETE, TestRuleDataType.ForRemove, 1, RuleState.ST_ENABLED, null, ruleProperties, ruleId);
modifyRulesResponse = this.OxoruleAdapter.RopModifyRules(newFolderHandle, ModifyRuleFlag.Modify_OnExisting, new RuleData[] { ruleForDelete });
Site.Assert.AreEqual<uint>(0, modifyRulesResponse.ReturnValue, "Deleting the OP_DELETE rule should succeed.");
RopDeleteFolderResponse deleteFolder = this.OxoruleAdapter.RopDeleteFolder(publicfolderHandler, createFolderResponse.FolderId);
Site.Assert.AreEqual<uint>(0, deleteFolder.ReturnValue, "Deleting folder should succeed.");
#endregion
}