public void ConstructorControlParameters_NullKey() { var attr = new FilterUIHintAttribute("", "", null, "value"); ExceptionHelper.ExpectException <InvalidOperationException>(delegate() { var v = attr.ControlParameters; }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.UIHintImplementation_ControlParameterKeyIsNull, 0)); }
public void ConstructorControlParameters_DuplicateKey() { var attr = new FilterUIHintAttribute("", "", "key", "value1", "key", "value2"); ExceptionHelper.ExpectException <InvalidOperationException>(delegate() { var v = attr.ControlParameters; }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.UIHintImplementation_ControlParameterKeyOccursMoreThanOnce, 2, "key")); }
public void ConstructorControlParameters_UnevenNumber() { var attr = new FilterUIHintAttribute("", "", ""); ExceptionHelper.ExpectException <InvalidOperationException>(delegate() { var v = attr.ControlParameters; }, Resources.DataAnnotationsResources.UIHintImplementation_NeedEvenNumberOfControlParameters); }
private static void VerifyAttribute(FilterUIHintAttribute attribute, string filterUIHint, string presentationLayer, IDictionary <string, object> controlParameters) { Assert.Equal(filterUIHint, attribute.FilterUIHint); Assert.Equal(presentationLayer, attribute.PresentationLayer); Assert.Equal(controlParameters, attribute.ControlParameters); // ControlParameters is cached Assert.Same(attribute.ControlParameters, attribute.ControlParameters); }
private static void VerifyAttribute(FilterUIHintAttribute attribute, string filterUIHint, string presentationLayer, IDictionary<string, object> controlParameters) { Assert.Equal(filterUIHint, attribute.FilterUIHint); Assert.Equal(presentationLayer, attribute.PresentationLayer); Assert.Equal(controlParameters, attribute.ControlParameters); // ControlParameters is cached Assert.Same(attribute.ControlParameters, attribute.ControlParameters); }
public void Ctor(string filterUIHint, string presentationLayer, object[] controlParameters, IDictionary<string, object> expectedControlParameters) { if (controlParameters == null || controlParameters.Length == 0) { if (presentationLayer == null) { // Use FilterUIHintAttribute(string) FilterUIHintAttribute attribute1 = new FilterUIHintAttribute(filterUIHint); VerifyAttribute(attribute1, filterUIHint, presentationLayer, expectedControlParameters); } // Use FilterUIHintAttribute(string, string) FilterUIHintAttribute attribute2 = new FilterUIHintAttribute(filterUIHint, presentationLayer); VerifyAttribute(attribute2, filterUIHint, presentationLayer, expectedControlParameters); } // Use FilterUIHintAttribute(string, string, object[]) FilterUIHintAttribute attribute3 = new FilterUIHintAttribute(filterUIHint, presentationLayer, controlParameters); VerifyAttribute(attribute3, filterUIHint, presentationLayer, expectedControlParameters); }
public void Ctor(string filterUIHint, string presentationLayer, object[] controlParameters, IDictionary <string, object> expectedControlParameters) { if (controlParameters == null || controlParameters.Length == 0) { if (presentationLayer == null) { // Use FilterUIHintAttribute(string) FilterUIHintAttribute attribute1 = new FilterUIHintAttribute(filterUIHint); VerifyAttribute(attribute1, filterUIHint, presentationLayer, expectedControlParameters); } // Use FilterUIHintAttribute(string, string) FilterUIHintAttribute attribute2 = new FilterUIHintAttribute(filterUIHint, presentationLayer); VerifyAttribute(attribute2, filterUIHint, presentationLayer, expectedControlParameters); } // Use FilterUIHintAttribute(string, string, object[]) FilterUIHintAttribute attribute3 = new FilterUIHintAttribute(filterUIHint, presentationLayer, controlParameters); VerifyAttribute(attribute3, filterUIHint, presentationLayer, expectedControlParameters); }
public void FilterUIHintAttribute_Simple_Ctors_Set_Properties() { var attr = new FilterUIHintAttribute(null, null); Assert.IsNull(attr.FilterUIHint); Assert.IsNull(attr.PresentationLayer); Assert.AreEqual(0, attr.ControlParameters.Count); attr = new FilterUIHintAttribute(string.Empty, string.Empty); Assert.AreEqual(string.Empty, attr.FilterUIHint); Assert.AreEqual(string.Empty, attr.PresentationLayer); Assert.AreEqual(0, attr.ControlParameters.Count); attr = new FilterUIHintAttribute("theHint"); Assert.AreEqual("theHint", attr.FilterUIHint); Assert.IsNull(attr.PresentationLayer); Assert.AreEqual(0, attr.ControlParameters.Count); attr = new FilterUIHintAttribute("theHint", "theLayer"); Assert.AreEqual("theHint", attr.FilterUIHint); Assert.AreEqual("theLayer", attr.PresentationLayer); Assert.AreEqual(0, attr.ControlParameters.Count); }
public void ConstructorControlParameters_NullKey() { var attr = new FilterUIHintAttribute("", "", null, "value"); var v = attr.ControlParameters; }
public void ConstructorControlParameters_UnevenNumber() { var attr = new FilterUIHintAttribute("", "", ""); var v = attr.ControlParameters; }
public void InvalidControlParameters_Get_ThrowsInvalidOperationException(object[] controlParameters) { FilterUIHintAttribute attribute = new FilterUIHintAttribute("FilterUIHint", "PresentationLayer", controlParameters); Assert.Throws <InvalidOperationException>(() => attribute.ControlParameters); }
public FilteredList <Pet> ReadAll(FilterUIHintAttribute filter) { var filteredList = new FIlteredList <Pet>(); }
public void Equals(FilterUIHintAttribute attribute, object obj, bool expected) { Assert.Equal(expected, attribute.Equals(obj)); Assert.Equal(attribute.GetHashCode(), attribute.GetHashCode()); }
public void InvalidControlParameters_Get_ThrowsInvalidOperationException(object[] controlParameters) { FilterUIHintAttribute attribute = new FilterUIHintAttribute("FilterUIHint", "PresentationLayer", controlParameters); Assert.Throws<InvalidOperationException>(() => attribute.ControlParameters); }
public void ConstructorControlParameters_DuplicateKey() { var attr = new FilterUIHintAttribute("", "", "key", "value1", "key", "value2"); var v = attr.ControlParameters; }
public static void UpdateCrudServices(DbContext entityManager) { Func <Type, String, String> generateFieldsStr = (entityClass, strFields) => { var fields = entityClass.GetProperties(); JObject jsonOriginal = JObject.Parse(strFields); JObject jsonBuilder = new JObject(); foreach (var field in fields) { String fieldName = CaseConvert.UnderscoreToCamel(field.Name, false); ColumnAttribute column = field.GetCustomAttribute <ColumnAttribute> (); ForeignKeyAttribute foreignKey = field.GetCustomAttribute <ForeignKeyAttribute>(); DisplayAttribute display = field.GetCustomAttribute <DisplayAttribute>(); MaxLengthAttribute maxLength = field.GetCustomAttribute <MaxLengthAttribute>(); EditableAttribute editable = field.GetCustomAttribute <EditableAttribute>(); FilterUIHintAttribute filterUIHint = field.GetCustomAttribute <FilterUIHintAttribute>(); String typeDesc = field.PropertyType.FullName; if (typeDesc.Contains(".String")) { typeDesc = "s"; } else if (typeDesc.Contains(".Int32")) { typeDesc = "i"; } else if (typeDesc.Contains(".Boolean")) { typeDesc = "b"; } else if (typeDesc.Contains(".Decimal")) { typeDesc = "n3"; // numero com separação de milhar com casas decimais if (column != null && column.TypeName != null) { if (column.TypeName.Equals("numeric(9,2)")) { typeDesc = "n2"; // numero com separação de cents } else if (column.TypeName.Equals("numeric(9,1)")) { typeDesc = "n1"; // numero com separação de decimais } } } else if (typeDesc.Contains(".DateTime")) { typeDesc = "datetime-local"; // data e hora completa } else if (typeDesc.Contains(".Date")) { typeDesc = "date"; // data } else if (typeDesc.Contains(".Time")) { typeDesc = "time"; // hora completa } else { Console.WriteLine("{0} : {1} : Unknow type : {2}", entityClass.Name, field.Name, typeDesc); continue; } // type (columnDefinition), readOnly, hiden, primaryKey, required (insertable), updatable, defaultValue, length, precision, scale JObject jsonNewValue = new JObject(); if (typeDesc != null) { jsonNewValue.Add("type", typeDesc); } //if (column != null && column.updatable() == false) { // jsonBuilderValue.Add("updatable", false); //} if (maxLength != null && maxLength.Length != 255) { jsonNewValue.Add("length", maxLength.Length); } //if (column != null && column.precision() != 0) { // jsonBuilderValue.Add("precision", column.precision()); //} //if (column != null && column.scale() != 0) { // jsonBuilderValue.Add("scale", column.scale()); //} if (fieldName.Equals("crudGroupOwner") && entityClass.Name.Equals("CrudGroupOwner") == false) { jsonNewValue.Add("hiden", true); } if (field.GetCustomAttribute <KeyAttribute> () != null) { jsonNewValue.Add("primaryKey", true); } if (filterUIHint != null && filterUIHint.ControlParameters.ContainsKey("defaultValue")) { jsonNewValue.Add("defaultValue", (String)filterUIHint.ControlParameters["defaultValue"]); } if (filterUIHint != null && filterUIHint.ControlParameters.ContainsKey("isClonable")) { jsonNewValue.Add("isClonable", (String)filterUIHint.ControlParameters["isClonable"]); } if (filterUIHint != null && filterUIHint.ControlParameters.ContainsKey("options")) { jsonNewValue.Add("options", (String)filterUIHint.ControlParameters["options"]); } if (field.GetCustomAttribute <RequiredAttribute>() != null || (field.GetCustomAttribute <KeyAttribute> () != null && field.GetCustomAttribute <DatabaseGeneratedAttribute> () == null)) { jsonNewValue.Add("required", true); } if (foreignKey != null && foreignKey.Name != null) { jsonNewValue.Add("service", CaseConvert.UnderscoreToCamel(foreignKey.Name, false)); } if (display != null && display.Name != null) { jsonNewValue.Add("title", display.Name); } if (field.GetCustomAttribute <DatabaseGeneratedAttribute>() != null) { jsonNewValue.Add("hiden", true); } if (editable != null && editable.AllowEdit == false) { jsonNewValue.Add("readOnly", true); } if (jsonOriginal.ContainsKey(fieldName)) { JToken jsonOldValue = jsonOriginal.GetValue(fieldName); JObject jsonValue = new JObject(); jsonValue.Merge(jsonNewValue); jsonValue.Merge(jsonOldValue); jsonBuilder.Add(fieldName, jsonValue); // SHOW WARNING { String oldFieldStr = jsonOldValue.ToString(Formatting.Indented); String newFieldStr = jsonNewValue.ToString(Formatting.Indented); if (oldFieldStr.Equals(newFieldStr) == false) { Console.WriteLine("{0} : {1} : diference (database data / classes data) :", entityClass.Name, field.Name); Console.WriteLine(oldFieldStr); Console.WriteLine(newFieldStr); } } } else { jsonBuilder.Add(fieldName, jsonNewValue); } } return(jsonBuilder.ToString(Formatting.None)); }; foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Type entityClass in assembly.GetTypes()) { if (entityClass.GetCustomAttributes(typeof(TableAttribute), true).Length > 0) { String serviceName = CaseConvert.UnderscoreToCamel(entityClass.Name, false); CrudService service = entityManager.Find <CrudService> (serviceName); if (service != null) { String oldFields = service.Fields; String newFields = generateFieldsStr(entityClass, oldFields); if (oldFields.Equals(newFields) == false) { service.Fields = newFields; entityManager.Update(service); entityManager.SaveChanges(); } } else { service = new CrudService(); service.Name = serviceName; service.Fields = generateFieldsStr(entityClass, "{}"); entityManager.Add(service); entityManager.SaveChanges(); } RequestFilter.mapClass.Add(serviceName, entityClass); RequestFilter.mapService.Add(serviceName, service); } } } }
public void Equals(FilterUIHintAttribute attribute, object obj, bool expected) { Assert.Equal(expected, attribute.Equals(obj)); Assert.Equal(attribute.GetHashCode(), attribute.GetHashCode()); }