public void TestGetDisplayName() { //nominal case - display name already set IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>(); dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), ConditionUnitFactory.FileHiddenDataType.Field))); dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), ConditionUnitFactory.FileHiddenDataType.HiddenColumn))); IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem("This is a preset Display Name"), DataType.StringArray, dataItems); ConditionDisplayParameterHiddenData hiddenDataParam = new ConditionDisplayParameterHiddenData(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail); Assert.AreEqual("Field, Hidden column", hiddenDataParam.GetDisplayName(), "unexpected displayname - displayname should be the same as dataElement"); //data items in collection dataElement.DisplayName.Value = ""; Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value"); Assert.AreEqual("Field, Hidden column", hiddenDataParam.GetDisplayName(), "unexpected displayname"); Assert.AreEqual("Field, Hidden column", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value"); //no data items in collection dataItems = new PolicyObjectCollection<IDataItem>(); dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems); Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected length on dataelement.displayname.value"); hiddenDataParam = new ConditionDisplayParameterHiddenData(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail); Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_HIDDENDATA_DEFAULT, hiddenDataParam.GetDisplayName(), "unexpected displayname"); Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_HIDDENDATA_DEFAULT, dataElement.DisplayName.Value, "unexpected length on dataelement.displayname.value"); //invalid format for data dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.Header))); hiddenDataParam = new ConditionDisplayParameterHiddenData(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail); hiddenDataParam.Object = dataElement; try { string displayName = hiddenDataParam.GetDisplayName(); Assert.IsTrue(false, "didn't throw on invalid data format"); } catch (PolicyDesignerException) { Assert.IsTrue(true); } catch { Assert.IsTrue(false, "Unexpected exception"); } //no data hiddenDataParam = new ConditionDisplayParameterHiddenData(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail); try { string displayName = hiddenDataParam.GetDisplayName(); Assert.IsTrue(false, "didn't throw on empty data"); } catch (PolicyDesignerException) { Assert.IsTrue(true); } catch { Assert.IsTrue(false, "Unexpected exception"); } }
public void TestConstructor() { //empty dataElement ConditionDisplayParameterHiddenData hiddenDataParam = new ConditionDisplayParameterHiddenData(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail); Assert.IsTrue(Object.ReferenceEquals(null, hiddenDataParam.Object), "unexpected Object"); Assert.IsTrue(Properties.Resources.IDS_EXPRESSION_PARAM_HIDDENDATA_DEFAULT == hiddenDataParam.Text, "unexpected Text"); //nominal case with no display name IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>(); dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), ConditionUnitFactory.FileHiddenDataType.AttachedTemplate))); dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), ConditionUnitFactory.FileHiddenDataType.AutoVersion))); IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems); hiddenDataParam = new ConditionDisplayParameterHiddenData(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail); Assert.IsTrue(Object.ReferenceEquals(dataElement, hiddenDataParam.Object), "unexpected Object"); Assert.AreEqual("Attached template, Auto version", hiddenDataParam.Text, "unexpected Text"); m_callbackCalled = false; hiddenDataParam.Execute(); Assert.IsTrue(m_callbackCalled, "Execute not called"); //nominal case with display name dataElement.DisplayName.Value = "This is a display name"; hiddenDataParam = new ConditionDisplayParameterHiddenData(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail); Assert.IsTrue(Object.ReferenceEquals(dataElement, hiddenDataParam.Object), "unexpected Object"); Assert.AreEqual("Attached template, Auto version", hiddenDataParam.Text, "unexpected Text - displayname should be the same as dataElement"); m_callbackCalled = false; hiddenDataParam.Execute(); Assert.IsTrue(m_callbackCalled, "Execute not called"); //invalid format case try { dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), ConditionUnitFactory.FileHiddenDataType.Field))); hiddenDataParam = new ConditionDisplayParameterHiddenData(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail); Assert.IsTrue(false, "Didnt throw on invalid dataelement"); } catch (PolicyDesignerException) { Assert.IsTrue(true); } catch { Assert.IsTrue(false, "unexpected exception thrown"); } }