public void TestShowPropertyInUI() { // If any of the later tests fail then the policy.resources may not contain the required actions // so make sure that you've added them all in either via the add-in manager or // the ManuallyInstallActions batch file (in hygiene/setup) IResourceManager resourceManager = ResourceManagerFactory.CreateResourceManager(); AddEditActionsForm addEditActionsForm = new AddEditActionsForm(resourceManager); //IResourceActionProperty is not read only and has no mapped system property IResourceAction testResourceAction = null; foreach(IResourceAction resourceAction in resourceManager.ResourceActions) { if (resourceAction.ActionClass == "Workshare.Policy.Actions.CleanUserAction") { testResourceAction = resourceAction; break; } } Assert.IsNotNull(testResourceAction, "test set up error - did not find expected CleanUserAction IResourceAction in resources"); IResourceActionProperty testResourceActionProperty = null; foreach (IResourceActionProperty resourceActionProperty in testResourceAction.Properties) { if (resourceActionProperty.Name == "BuiltInProperties") { testResourceActionProperty = resourceActionProperty; break; } } Assert.IsNotNull(testResourceActionProperty, "test set up error - found expected EXECUTE IResourceActionProperty in resources"); object[] methodParams = {testResourceAction.ActionClass, testResourceActionProperty.Name}; Assert.IsTrue((bool)AccessInternals.InvokeMethod(addEditActionsForm, "ShowPropertyInUIForType", methodParams), "Not displaying IResourceActionProperty that is readable and has no mapped system property"); //read only, no mapped system property testResourceAction = null; foreach (IResourceAction resourceAction in resourceManager.ResourceActions) { if (resourceAction.ActionClass == "Workshare.Policy.Actions.AlertUserAction") { testResourceAction = resourceAction; break; } } Assert.IsNotNull(testResourceAction, "test set up error - did not find expected AlertUserAction IResourceAction in resources"); testResourceActionProperty = null; foreach (IResourceActionProperty resourceActionProperty in testResourceAction.Properties) { if (resourceActionProperty.Name == "Description") { testResourceActionProperty = resourceActionProperty; break; } } Assert.IsNotNull(testResourceActionProperty, "test set up error - did not find expected EXECUTE IResourceActionProperty in resources"); Assert.IsNull(testResourceActionProperty.MappedSystemProperty, "test set up error - unexpected IResourceAction.MappedSystemProperty in resources"); testResourceActionProperty.ReadOnly = true; methodParams[0] = testResourceAction.ActionClass; methodParams[1] = testResourceActionProperty.Name; Assert.IsFalse((bool)AccessInternals.InvokeMethod(addEditActionsForm, "ShowPropertyInUIForType", methodParams), "Displaying IResourceActionProperty that is read only and has no mapped system property"); //unsupported IResourceActionProperty in valid IResourceAction testResourceActionProperty = null; const string unsupportedPropertyName = "This is an unsupported property"; foreach (IResourceActionProperty resourceActionProperty in testResourceAction.Properties) { if (resourceActionProperty.Name == unsupportedPropertyName) { testResourceActionProperty = resourceActionProperty; break; } } Assert.IsNull(testResourceActionProperty, "test set up error - unexpectedly found an unsupported property in IResourceActionProperty in resources"); methodParams[1] = unsupportedPropertyName; Assert.IsFalse((bool)AccessInternals.InvokeMethod(addEditActionsForm, "ShowPropertyInUIForType", methodParams), "Displaying IResourceActionProperty that is not in the resources"); //unsupported IResourceAction testResourceAction = null; const string unsupportedActionClass = "This is an unsupported action"; foreach (IResourceAction resourceAction in resourceManager.ResourceActions) { if (resourceAction.ActionClass == unsupportedActionClass) { testResourceAction = resourceAction; break; } } Assert.IsNull(testResourceAction, "test set up error - unexpectedly found an unsupported action IResourceAction in resources"); methodParams[0] = unsupportedActionClass; Assert.IsFalse((bool)AccessInternals.InvokeMethod(addEditActionsForm, "ShowPropertyInUIForType", methodParams), "Displaying IResourceAction that is not in the resources"); }
private bool CanLoadActionHelper(AddEditActionsForm form, IResourceAction action) { return (bool)AccessInternals.InvokeMethod(form, "CanLoadAction", new object[] { action }); }
public void TestPolicySupportsActionsTrue() { IResourceManager resourceManager = ResourceManagerFactory.CreateResourceManager(); resourceManager.ResourceActions.Clear(); AddEditActionsForm addEditActionsForm = new AddEditActionsForm(resourceManager); // The "User" has selected an SMTP channel of some sort probably a "ClientEmail" PolicyType addEditActionsForm.Channel = new PolicyChannel(Guid.NewGuid(), new NonTranslateableLanguageItem("SMTP channel"), ChannelType.SMTP); // The only action we have available in our resource list is an Http channel action. MockResourceAction mockHttpContentChannelAction = new MockResourceAction("mockHttpContentChannelAction", true); mockHttpContentChannelAction.SupportedChannelCapabilities = new ChannelType[] { ChannelType.HTTP }; resourceManager.ResourceActions.Add(mockHttpContentChannelAction); Assert.IsTrue(addEditActionsForm.PolicySupportsActions(), "Policy should support action as the ChannelType is Http which comes under an ClientEmail PolicyType (SMTP)"); }
public void TestCanLoadAction() { AddEditActionsForm addEditActionsForm = new AddEditActionsForm(null); IPolicyObjectCollection<IAction> currentlyLoadedActions = new PolicyObjectCollection<IAction>(); //Test that we can load an action when there are none currently active in the cell. addEditActionsForm.CurrentActions = new PolicyObjectCollection<IAction>(); MockResourceAction mockAction1 = new MockResourceAction("TestAction", true); Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, mockAction1), "Expected to be able to load an action when the current list is empty"); MockResourceAction nonCoExistableAction = new MockResourceAction("NoCoExistableAction", false); Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, nonCoExistableAction), "Expected to be able to load an action when the current list is empty when coexist = false"); //Test that we cannot load actions into a non empty cell when co-exist = false IPolicyObjectCollection<IAction> actions = new PolicyObjectCollection<IAction>(); actions.Add(new MockAction("TestAction")); addEditActionsForm.CurrentActions = actions; Assert.IsFalse(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("OtherTestAction", false)), "Should not be able to load any other actions if the action you are trying to add has CoExist = false"); //Test that we can load another action into the cell when co-exist = true Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("OtherTestAction", true)), "Should be able to load other actions if the action you are trying to add has CoExist = true"); //Test that we cannot load two actions of the same type into any cell. Assert.IsFalse(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("TestAction", true)), "Should not be able to add an action of this class because the current list already contains one"); //Test that we can add actions of different types with no problem Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("ActionA", true)), "If the class name is unique to the list and co-exist is true, should be able to add this item."); Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("ActionB", true)), "If the class name is unique to the list and co-exist is true, should be able to add this item."); Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("ActionC", true)), "If the class name is unique to the list and co-exist is true, should be able to add this item."); actions.Add(new MockAction("ActionC")); addEditActionsForm.CurrentActions = actions; Assert.IsFalse(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("ActionC", true)), "Should not be able to add an action of this class because the current list already contains one"); }
private void PopulateExecutionOption(AddEditActionsForm frm) { bool executeValue = (bool)((DataItem)m_executeOptionElem.Data).Value; bool executeOverride = Boolean.Parse(m_executeOptionElem["allowoverride"].Value); if (executeOverride) { frm.ExecutionOption = executeValue ? ExecutionOption.OverridableDefaultTrue : ExecutionOption.OverridableDefaultFalse; } else { frm.ExecutionOption = ExecutionOption.AlwaysExecute; } }
/// <summary> /// Invokes a dialog to allow the user to edit the action. If the user edits the action, /// the action data will be updated. /// </summary> /// <returns>The DialogResult of the edit dialog</returns> private DialogResult EditAction() { IResourceManager resourceManager = ResourcesCache.GetResources(); if (!ActionAvailable(resourceManager, m_action)) return DialogResult.Abort; m_transparentElem = InitDataElem(LanguageItemKeys.TRANSPARENT); m_autoExpandElem = InitDataElem(LanguageItemKeys.AUTOEXPAND); m_executeOptionElem = InitDataElem(LanguageItemKeys.ALWAYSEXECUTE); AddEditActionsForm frm = new AddEditActionsForm(resourceManager); frm.InitialAction = m_action; frm.OpenForEdit = true; frm.Channel = m_channel; frm.AllowTransparent = RoutingHelper.SupportTransparentProcessing(m_channel.Routing); frm.IsExceptionCell = m_isExceptionCell; if (m_transparentElem.Data is DataItem) frm.Transparent = (bool)((DataItem)m_transparentElem.Data).Value; //if (m_autoExpandElem.Data is DataItem) // frm.AutoExpand = (bool)((DataItem)m_autoExpandElem.Data).Value; if (m_executeOptionElem.Data is DataItem) { PopulateExecutionOption(frm); } DialogResult result = DoShowForm(frm); if (result == DialogResult.OK) { m_action.Override = frm.Override; m_action.Name.Value = frm.MyName; m_action.RunAt = frm.RunAt; m_transparentElem.Data = DataItem.CreateDataItem(new NonTranslateableLanguageItem(String.Empty), DataType.Boolean, frm.Transparent); ConnectExecutionOption(frm.ExecutionOption); IDictionaryEnumerator propEnumerator = frm.ListItems.GetEnumerator(); while (propEnumerator.MoveNext()) { ActionDataElement ade = (ActionDataElement)propEnumerator.Value; IDataElement de = m_action.DataElements[ade.Identifier]; if (0 == string.Compare(de.DisplayName.Value, LanguageItemKeys.AUTOEXPAND, StringComparison.InvariantCultureIgnoreCase)) continue; if (0 == string.Compare(de.DisplayName.Value, LanguageItemKeys.ALWAYSEXECUTE, StringComparison.InvariantCultureIgnoreCase)) continue; if (ade.IsDataSource) { de.Data = ade.Value; } else { if (de.Type == DataType.StringArray) { de.Data = ConversionUtils.StringArrayToPolicyObjectModelStringArray((string[])ade.Value); } else { ((IDataItem)de.Data).Value = ade.Value; } } de["allowoverride"].Value = ade.Override.ToString(); de["visible"].Value = ade.Visible.ToString(); } propEnumerator = frm.FileItems.GetEnumerator(); while (propEnumerator.MoveNext()) { ActionFiletype frmFtype = (ActionFiletype)propEnumerator.Value; IActionFiletype ftype = m_action.Filetypes[frmFtype.Identifier]; if (ftype != null) { ftype.Apply = frmFtype.Apply; ftype.Name.Value = frmFtype.Name.Value; ftype.Type = frmFtype.Type; } else m_action.Filetypes.Add(frmFtype); } StateMachine.ChildForm.IsModified = true; } return result; }