public void GetUnit() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor propertyPourcentage = beanDefinition.Properties["Pourcentage"]; Assert.AreEqual(FormatterPercent.UnitPercentage, propertyPourcentage.Unit); }
public void ConvertToStringFormatteur() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor propertyDate = beanDefinition.Properties["Date"]; propertyDate.ConvertToString(DateTime.Now); }
/// <summary> /// Prend en charge l'alimentation de la classe pour les valeurs d'initialisation. /// </summary> /// <param name="classe">Classe concernée.</param> /// <param name="item">Bean d'initialisation.</param> protected void HandleCorrectInit(ModelClass classe, TableInit item) { if (!DictionaryItemInit.ContainsKey(classe)) { DictionaryItemInit.Add(classe, item); } foreach (ItemInit itemInit in item.ItemInitList) { BeanDefinition definition = BeanDescriptor.GetDefinition(itemInit.Bean); BeanPropertyDescriptor propertyDescriptor = GetReferenceKeyDescriptor(classe, definition); object propertyValue = propertyDescriptor.GetValue(itemInit.Bean); if (propertyDescriptor.PrimitiveType == typeof(string)) { propertyValue = "\"" + propertyValue + "\""; } BeanPropertyDescriptor libelleDescriptor = GetLibelleDescriptor(classe, definition); string libelle = null; if (libelleDescriptor != null) { libelle = (string)libelleDescriptor.GetValue(itemInit.Bean); } else { libelle = itemInit.VarName; } classe.ConstValues.Add(itemInit.VarName, new StaticListElement() { Code = propertyValue, Libelle = libelle, CodeType = propertyDescriptor.PrimitiveType.ToString() }); } }
public void ConvertFromStringFormatteur() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor propertyDate = beanDefinition.Properties["Date"]; propertyDate.ConvertFromString("02/01/2007"); }
/// <summary> /// Applique le tri et le filtrage à la liste. /// </summary> /// <typeparam name="TSource">Type source.</typeparam> /// <param name="list">Liste source.</param> /// <returns>Liste triée.</returns> public ICollection <TSource> Apply <TSource>(ICollection <TSource> list) { if (list == null) { throw new ArgumentNullException("list"); } if (_sortList.Count != 1) { throw new NotImplementedException(); } if (this.InlineCount) { QueryContext.InlineCount = list.Count; } string sortColumn = _sortList[0]; SortOrder sortOrder = _mapSort[sortColumn]; BeanDefinition beanDef = BeanDescriptor.GetDefinition(typeof(TSource)); BeanPropertyDescriptor propertyDescriptor = beanDef.Properties[FirstToUpper(sortColumn)]; if (sortOrder == SortOrder.Asc) { list = list.OrderBy(x => propertyDescriptor.GetValue(x)).ToList(); } else { list = list.OrderByDescending(x => propertyDescriptor.GetValue(x)).ToList(); } // If this.Limit == 0 we disable pagination. return(list.Skip(this.Offset).Take(this.Limit > 0 ? this.Limit : list.Count).ToList()); }
/// <summary> /// Crée un dictionnaire { nom de la propriété => valeur } pour un item à insérer. /// </summary> /// <param name="modelClass">Modele de la classe.</param> /// <param name="initItem">Item a insérer.</param> /// <param name="isPrimaryKeyIncluded">True si le script d'insert doit comporter la clef primaire.</param> /// <returns>Dictionnaire contenant { nom de la propriété => valeur }.</returns> protected override Dictionary <string, string> CreatePropertyValueDictionary(ModelClass modelClass, ItemInit initItem, bool isPrimaryKeyIncluded) { Dictionary <string, string> nameValueDict = new Dictionary <string, string>(); BeanDefinition definition = BeanDescriptor.GetDefinition(initItem.Bean); foreach (ModelProperty property in modelClass.PersistentPropertyList) { if (!property.DataDescription.IsPrimaryKey || isPrimaryKeyIncluded) { BeanPropertyDescriptor propertyDescriptor = definition.Properties[property.Name]; object propertyValue = propertyDescriptor.GetValue(initItem.Bean); string propertyValueStr = propertyValue == null ? string.Empty : propertyValue.ToString(); if (property.DataType == "byte[]") { nameValueDict[property.DataMember.Name] = GetBulkColumn(propertyValueStr); } else if (propertyDescriptor.PrimitiveType == typeof(string)) { nameValueDict[property.DataMember.Name] = "'" + propertyValueStr.Replace("'", "''") + "'"; } else { nameValueDict[property.DataMember.Name] = propertyValueStr; } } } return(nameValueDict); }
public void GetDefinitionUnsupportedType() { BeanDefinition definition = BeanDescriptor.GetDefinition(new BeanInvalidUnsupportedType()); BeanPropertyDescriptor property = definition.Properties["OtherId"]; property.ValidConstraints(3, null); }
public void CheckValueTypeUnsupportedGenericType() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor primaryKey = beanDefinition.PrimaryKey; primaryKey.CheckValueType(new Generic <Bean>()); }
public void GetCollectionUnit() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor property = beanDefinition.Properties["RoleList"]; Assert.IsNull(property.Unit); }
public void CheckValueTypeBadType() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor primaryKey = beanDefinition.PrimaryKey; primaryKey.CheckValueType(String.Empty); }
public void ValidConstraintsError() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor property = beanDefinition.Properties["Libelle"]; property.ValidConstraints("0123456789012345678901234567890123456789", null); }
public void GetObjectUnit() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor property = beanDefinition.Properties["Child"]; Assert.IsNull(property.Unit); }
public string GetReferenceValueByPrimaryKey(Type referenceType, object primaryKey, object dataSource, string defaultPropertyName = null) { BeanDefinition definition = BeanDescriptor.GetDefinition(referenceType); BeanPropertyDescriptor primaryKeyProperty = definition.PrimaryKey; BeanPropertyDescriptor valueProperty = string.IsNullOrEmpty(defaultPropertyName) ? definition.DefaultProperty : definition.Properties[defaultPropertyName]; ICollection dataSourceColl = (ICollection)dataSource; if (dataSourceColl == null) { throw new NotSupportedException("DataSource must be an ICollection."); } object candidate = null; foreach (object item in dataSourceColl) { if (primaryKeyProperty.GetValue(item).Equals(primaryKey)) { candidate = item; break; } } if (candidate == null) { throw new NotSupportedException("The datasource does not contain an object with this primary key."); } return(valueProperty.ConvertToString(valueProperty.GetValue(candidate))); }
public void Item() { BeanDefinition definition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor primaryKey = definition.PrimaryKey; Assert.AreEqual(primaryKey, definition.Properties[primaryKey.PropertyName]); }
public void ConvertFromStringBadType() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor primaryKey = beanDefinition.PrimaryKey; primaryKey.ConvertFromString("aaa"); }
public void ConvertToString() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor primaryKey = beanDefinition.PrimaryKey; string text = primaryKey.ConvertToString(3); Assert.AreEqual("3", text); }
public void ValidConstraints() { Bean b = new Bean(); BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(b); BeanPropertyDescriptor primaryKey = beanDefinition.PrimaryKey; primaryKey.ValidConstraints(2, null); }
public void SetValueBadType() { Bean b = new Bean(); BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(b); BeanPropertyDescriptor primaryKey = beanDefinition.PrimaryKey; primaryKey.SetValue(b, "test"); }
public void ConvertFromString() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor primaryKey = beanDefinition.PrimaryKey; object o = primaryKey.ConvertFromString("3"); Assert.AreEqual(3, o); }
/// <summary> /// Retourne le nom d'un champ. /// </summary> /// <param name="i">Indice.</param> /// <returns>Nom du champ.</returns> public override string GetName(int i) { BeanPropertyDescriptor desc = _descriptors[i]; return(String.IsNullOrEmpty(desc.MemberName) ? desc.PropertyName : desc.MemberName.ToLower(CultureInfo.InvariantCulture)); }
/// <summary> /// Retourne la valeur d'une liste de référence à partir /// de son identifiant. /// </summary> /// <param name="referenceType">Type de la liste de référence.</param> /// <param name="primaryKey">Identifiant de la liste de référence.</param> /// <param name="defaultPropertyName">Nom de la propriété par défaut à utiliser. Null pour utiliser la valeur définie au niveau de l'objet.</param> /// <returns>Libellé de la liste de référence.</returns> public string GetReferenceValueByPrimaryKey(Type referenceType, object primaryKey, string defaultPropertyName = null) { object reference = GetReferenceObjectByPrimaryKey(referenceType, primaryKey); BeanDefinition definition = BeanDescriptor.GetDefinition(reference); BeanPropertyDescriptor property = string.IsNullOrEmpty(defaultPropertyName) ? definition.DefaultProperty : definition.Properties[defaultPropertyName]; return(property.ConvertToString(property.GetValue(reference))); }
public void SetValue() { Bean b = new Bean(); BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(b); BeanPropertyDescriptor primaryKey = beanDefinition.PrimaryKey; primaryKey.SetValue(b, 2); Assert.AreEqual(2, b.Id); }
public void CheckValueTypeBadGenericType() { BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor primaryKey = beanDefinition.PrimaryKey; Nullable <double> d = new Nullable <double>(); d = 3; primaryKey.CheckValueType(d); }
/// <summary> /// Appelle le PrimaryKeyAccessor pour le type donné avec la valeur de PK donnée. /// </summary> /// <param name="type">Type concerné.</param> /// <param name="primaryKey">Clef primaire.</param> /// <param name="propertyName">Propriété évaluée.</param> /// <returns>Libellé par défaut.</returns> private string InvokePrimaryKeyAccessor(Type type, object primaryKey, string propertyName = null) { object o = GetBeanByPrimaryKey(type, primaryKey); Accessor accessor = _primaryKeyAccessors[type.FullName]; BeanDefinition definition = BeanDescriptor.GetDefinition(accessor.ReturnType); BeanPropertyDescriptor property = string.IsNullOrEmpty(propertyName) ? definition.DefaultProperty : definition.Properties[propertyName]; return(property.ConvertToString(property.GetValue(o))); }
public void Contains() { BeanDefinition definition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor primaryKey = definition.PrimaryKey; ICollection <BeanPropertyDescriptor> coll = definition.Properties; Assert.IsTrue(coll.Contains(primaryKey)); Assert.IsTrue(definition.Properties.Contains(primaryKey.PropertyName)); }
public void CopyTo() { BeanDefinition definition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor[] array = new BeanPropertyDescriptor[definition.Properties.Count]; ICollection <BeanPropertyDescriptor> coll = definition.Properties; coll.CopyTo(array, 0); Assert.IsNotNull(array[0]); }
public void ItemNotFound() { BeanDefinition definition = BeanDescriptor.GetDefinition(new Bean()); BeanPropertyDescriptor primaryKey = definition.PrimaryKey; try { definition.Properties["PasDePropriete"].ToString(); } catch (Exception e) { Assert.IsTrue(e.Message.Contains("Bean")); } }
/// <summary> /// Renvoie la valeur de la propriété. /// </summary> /// <param name="item">Item.</param> /// <param name="property">Descrition de l'item.</param> /// <returns>Valeur.</returns> private static object GetPropertyValue(T item, BeanPropertyDescriptor property) { object value = property.GetValue(item); ExtendedValue v = value as ExtendedValue; if (v != null) { value = v.Value; } return(value); }
public void ValidConstraintsForceMandatory() { Bean b = new Bean(); BeanDefinition beanDefinition = BeanDescriptor.GetDefinition(b); BeanPropertyDescriptor propertyPourcentage = beanDefinition.Properties["Pourcentage"]; try { propertyPourcentage.ValidConstraints(b.Pourcentage, null); } catch (Exception e) { throw new Exception(e.Message, e); } propertyPourcentage.ValidConstraints(b.Pourcentage, true); }
/// <summary> /// Crée la chaîne liée à la clause Where. /// </summary> /// <param name="bean">Bean à mettre à jour.</param> /// <param name="sbUpdateWhere">Clause Where.</param> /// <param name="property">Propriété courante.</param> /// <param name="rule">Règle à appliquer.</param> protected void BuildUpdateWhere(T bean, StringBuilder sbUpdateWhere, BeanPropertyDescriptor property, IStoreRule rule) { if (sbUpdateWhere == null) { throw new ArgumentNullException("sbUpdateWhere"); } if (property == null) { throw new ArgumentNullException("property"); } if (rule == null) { return; } object value = property.GetValue(bean); if (value != null) { ExtendedValue extValue = value as ExtendedValue; if (extValue != null) { value = extValue.Value; } } ValueRule valueRule = rule.GetWhereClause(value); if (valueRule == null) { return; } switch (valueRule.Action) { case ActionRule.Check: sbUpdateWhere.Append(" and ").Append(property.MemberName).Append(" = "); sbUpdateWhere.Append(VariablePrefix).Append("RU_").Append( property.MemberName); break; case ActionRule.DoNothing: break; default: throw new NotSupportedException(); } }