public void CustomProps_TryAllTypes() { var page1 = this.GetNewPage(); var s1 = page1.DrawRectangle(0, 0, 2, 2); // string var cp_string = new CustomPropertyCells(); cp_string.Value = "\"Hello World\""; cp_string.Type = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.String); var cp_int = new CustomPropertyCells(); cp_int.Value = 1024; cp_int.Type = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Number); var cp_dt = new CustomPropertyCells(); cp_dt.Value = "DATETIME(\"03/31/1979\")"; cp_dt.Type = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Date); var cp_bool = new CustomPropertyCells(); cp_bool.Value = "TRUE"; cp_bool.Type = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Boolean); var cp_float = new CustomPropertyCells(); cp_float.Value = 3.14; cp_float.Type = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Number); CustomPropertyHelper.Set(s1, "PropertyString", cp_string); CustomPropertyHelper.Set(s1, "PropertyInt", cp_int); CustomPropertyHelper.Set(s1, "PropertyFloat", cp_float); CustomPropertyHelper.Set(s1, "PropertyDateTime", cp_dt); CustomPropertyHelper.Set(s1, "PropertyBool", cp_bool); var cpdic = CustomPropertyHelper.GetDictionary(s1, CellValueType.Formula); var out_cpstring = cpdic["PropertyString"]; var out_cpint = cpdic["PropertyInt"]; var out_cpfloat = cpdic["PropertyFloat"]; var out_cpdatetime = cpdic["PropertyDateTime"]; var out_cpbool = cpdic["PropertyBool"]; Assert.AreEqual("\"Hello World\"", out_cpstring.Value.Value); Assert.AreEqual("0", out_cpstring.Type.Value); Assert.AreEqual("1024", out_cpint.Value.Value); Assert.AreEqual("2", out_cpint.Type.Value); Assert.AreEqual("3.14", out_cpfloat.Value.Value); Assert.AreEqual("2", out_cpfloat.Type.Value); Assert.AreEqual("DATETIME(\"03/31/1979\")", out_cpdatetime.Value.Value); Assert.AreEqual("5", out_cpdatetime.Type.Value); Assert.AreEqual("TRUE", out_cpbool.Value.Value); Assert.AreEqual("3", out_cpbool.Type.Value); page1.Delete(0); }
public void CustomProps_AllTypes() { var page1 = this.GetNewPage(); var s1 = page1.DrawRectangle(0, 0, 1, 1); s1.Text = "Checking for Custom Properties"; // String Custom Property var prop_string_in = new CustomPropertyCells(); prop_string_in.Format = "\"Format\""; prop_string_in.Label = "\"Label\""; prop_string_in.Prompt = "\"Prompt\""; prop_string_in.Type = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.String); prop_string_in.Value = "1"; // Boolean var prop_bool_in = new CustomPropertyCells(); prop_bool_in.Format = "\"Format\""; prop_bool_in.Label = "\"Label\""; prop_bool_in.Prompt = "\"Prompt\""; prop_bool_in.Type = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Boolean); prop_bool_in.Value = true; // Date var dt = new System.DateTime(2017, 3, 31, 14, 5, 6); var st = dt.ToString(CultureInfo.InvariantCulture); var prop_date_in = new CustomPropertyCells(); prop_date_in.Format = "\"Format\""; prop_date_in.Label = "\"Label\""; prop_date_in.Prompt = "\"Prompt\""; prop_date_in.Type = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Date); prop_date_in.Value = string.Format("DATETIME(\"{0}\")", st);; // Boolean var prop_number_in = new CustomPropertyCells(); prop_number_in.Format = "\"Format\""; prop_number_in.Label = "\"Label\""; prop_number_in.Prompt = "\"Prompt\""; prop_number_in.Type = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Number); prop_number_in.Value = "3.14"; CustomPropertyHelper.Set(s1, "PROP_STRING", prop_string_in); CustomPropertyHelper.Set(s1, "PROP_BOOLEAN", prop_bool_in); CustomPropertyHelper.Set(s1, "PROP_DATE", prop_date_in); CustomPropertyHelper.Set(s1, "PROP_NUMBER", prop_number_in); var props_dic = CustomPropertyHelper.GetDictionary(s1, CellValueType.Formula); var prop_string_out = props_dic["PROP_STRING"]; Assert.AreEqual("\"Format\"", prop_string_out.Format.Value); Assert.AreEqual("\"Label\"", prop_string_out.Label.Value); Assert.AreEqual("\"Prompt\"", prop_string_out.Prompt.Value); Assert.AreEqual("0", prop_string_out.Type.Value); Assert.AreEqual("1", prop_string_out.Value.Value); var prop_bool_out = props_dic["PROP_BOOLEAN"]; Assert.AreEqual("\"Format\"", prop_bool_out.Format.Value); Assert.AreEqual("\"Label\"", prop_bool_out.Label.Value); Assert.AreEqual("\"Prompt\"", prop_bool_out.Prompt.Value); Assert.AreEqual("3", prop_bool_out.Type.Value); Assert.AreEqual("TRUE", prop_bool_out.Value.Value); var prop_date_out = props_dic["PROP_DATE"]; Assert.AreEqual("\"Format\"", prop_date_out.Format.Value); Assert.AreEqual("\"Label\"", prop_date_out.Label.Value); Assert.AreEqual("\"Prompt\"", prop_date_out.Prompt.Value); Assert.AreEqual("5", prop_date_out.Type.Value); Assert.AreEqual("DATETIME(\"03/31/2017 14:05:06\")", prop_date_out.Value.Value); var prop_number_out = props_dic["PROP_NUMBER"]; Assert.AreEqual("\"Format\"", prop_number_out.Format.Value); Assert.AreEqual("\"Label\"", prop_number_out.Label.Value); Assert.AreEqual("\"Prompt\"", prop_number_out.Prompt.Value); Assert.AreEqual("2", prop_number_out.Type.Value); Assert.AreEqual("3.14", prop_number_out.Value.Value); var app = this.GetVisioApplication(); var doc = app.ActiveDocument; if (doc != null) { doc.Close(true); } }
public void CustomProps_GetSet2() { var page1 = this.GetNewPage(); var s1 = page1.DrawRectangle(0, 0, 1, 1); s1.Text = "Checking for Custom Properties"; var cp1 = new CustomPropertyCells(); cp1.Ask = "1"; cp1.Calendar = "0"; cp1.Format = "\"1\""; cp1.Invisible = "0"; cp1.Label = "\"1\""; cp1.LangID = "0"; cp1.Prompt = "\"1\""; cp1.SortKey = "0"; cp1.Type = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.String); cp1.Value = "1"; CustomPropertyHelper.Set(s1, "PROP1", cp1); var props1 = CustomPropertyHelper.GetCells(s1, CellValueType.Formula); var cp2 = props1["PROP1"]; Assert.AreEqual("TRUE", cp2.Ask.Value); Assert.AreEqual("0", cp2.Calendar.Value); Assert.AreEqual("\"1\"", cp2.Format.Value); Assert.AreEqual("FALSE", cp2.Invisible.Value); Assert.AreEqual("\"1\"", cp2.Label.Value); Assert.AreEqual("0", cp2.LangID.Value); Assert.AreEqual("\"1\"", cp2.Prompt.Value); Assert.AreEqual("0", cp2.SortKey.Value); Assert.AreEqual("0", cp2.Type.Value); Assert.AreEqual("1", cp2.Value.Value); var cp3 = new CustomPropertyCells(); cp3.Ask = "0"; cp3.Calendar = "2"; cp3.Format = "\"0\""; cp3.Invisible = "TRUE"; cp3.Label = "\"3\""; cp3.LangID = "2"; cp3.Prompt = "\"3\""; cp3.SortKey = "2"; cp3.Type = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Boolean); cp3.Value = "2"; CustomPropertyHelper.Set(s1, "PROP1", cp3); var props2 = CustomPropertyHelper.GetCells(s1, CellValueType.Formula); var cp4 = props2["PROP1"]; Assert.AreEqual("FALSE", cp4.Ask.Value); Assert.AreEqual("2", cp4.Calendar.Value); Assert.AreEqual("\"0\"", cp4.Format.Value); Assert.AreEqual("TRUE", cp4.Invisible.Value); Assert.AreEqual("\"3\"", cp4.Label.Value); Assert.AreEqual("2", cp4.LangID.Value); Assert.AreEqual("\"3\"", cp4.Prompt.Value); Assert.AreEqual("2", cp4.SortKey.Value); Assert.AreEqual("3", cp4.Type.Value); Assert.AreEqual("2", cp4.Value.Value); var app = this.GetVisioApplication(); var doc = app.ActiveDocument; if (doc != null) { doc.Close(true); } }