public void GetConcreteAccountType_StaticRoute() { var propertyValueListResponse = BuildTPropertyValueListResponseFromFile("StaticRoute_TPropertyValueListResponse.xml"); Assert.NotNull(propertyValueListResponse); Assert.NotNull(propertyValueListResponse.HttpRequestResult); Assert.NotNull(propertyValueListResponse.Items); Assert.AreEqual(18, propertyValueListResponse.Items.Count); var account = TPropertyValHelper.GetConcreteAccountType(propertyValueListResponse.Items); Assert.AreEqual(typeof(StaticRoute), account.GetType()); //shared properties Assert.True(account.U_Type.HasValue); Assert.AreEqual(AccountType.StaticRoute, account.U_Type.Value); Assert.AreEqual("static-route", account.U_Alias); Assert.AreEqual("*****@*****.**", account.U_AliasList); Assert.True(String.IsNullOrEmpty(account.U_Name)); Assert.AreEqual("eJxjYWBgYLRmGKmAEUTwFJcklmQm6xbll5akDrSLBgAwDrQDRsHAAqaBdsBAA0buktTiksy8dL3k/NyBdswoGAWjYBSMgkEAAOJ3Caw=", account.U_Backup); Assert.False(account.U_GW_DailyAgenda.HasValue); //account type specific properties var specificAccountType = (StaticRoute)account; Assert.AreEqual("testing.com", specificAccountType.R_SaveTo); Assert.True(specificAccountType.R_ExternalDomain.HasValue); Assert.True(specificAccountType.R_ExternalDomain.Value); Assert.True(specificAccountType.R_ExternalFilter.HasValue); Assert.AreEqual(ExternalFilter.All, specificAccountType.R_ExternalFilter.Value); }
public void GetConcreteAccountType_User() { var propertyValueListResponse = BuildTPropertyValueListResponseFromFile("User_TPropertyValueListResponse.xml"); Assert.NotNull(propertyValueListResponse); Assert.NotNull(propertyValueListResponse.HttpRequestResult); Assert.NotNull(propertyValueListResponse.Items); Assert.AreEqual(153, propertyValueListResponse.Items.Count); var account = TPropertyValHelper.GetConcreteAccountType(propertyValueListResponse.Items); Assert.AreEqual(typeof(User), account.GetType()); //shared properties Assert.True(account.U_Type.HasValue); Assert.AreEqual(AccountType.User, account.U_Type.Value); Assert.AreEqual("test", account.U_Alias); Assert.AreEqual("*****@*****.**", account.U_AliasList); Assert.AreEqual("Test", account.U_Name); Assert.AreEqual("eJxjYGBkYA1JLS6xZhiJgBGEWUqA/h9olwwgGJT+Z6SDHSwQWzgDEouLy/OLUgzpYOcgBMKg+M/MS9dLztcrzY4B8WIG2k30BPRIaqNgFIyCUTAKhhYAAIQKEJc=", account.U_Backup); Assert.False(account.U_GW_DailyAgenda.HasValue); //account type specific properties var specificAccountType = (User)account; Assert.AreEqual("test", specificAccountType.U_EmailAlias); Assert.True(specificAccountType.U_Admin.HasValue); Assert.True(specificAccountType.U_Admin.Value); Assert.True(specificAccountType.U_MaxBoxSize.HasValue); Assert.AreEqual(0, specificAccountType.U_MaxBoxSize); Assert.True(specificAccountType.U_AccountValidTill_Date.HasValue); Assert.AreEqual(1899, specificAccountType.U_AccountValidTill_Date.Value.Year); Assert.AreEqual(12, specificAccountType.U_AccountValidTill_Date.Value.Month); Assert.AreEqual(30, specificAccountType.U_AccountValidTill_Date.Value.Day); }
/// <summary> /// Creates a new instance from a list of TPropertyValue. See <see cref="TPropertyValue"/> for more information. /// </summary> /// <param name="valueList">A list of property values. <see cref="List{TPropertyValue}"/></param> protected ComBaseClass(List <TPropertyValue> valueList) { var properties = ClassHelper.GetProperites(this.GetType(), BindingFlags.Instance | BindingFlags.Public); foreach (var property in properties) { //bool? //char? //DateTime? //int? //Enum? //string //List<string> if (property.PropertyType == typeof(bool)) { property.SetValue(this, TPropertyValHelper.GetPropertyValAsBool(valueList, property.Name)); } else if (property.PropertyType == typeof(bool?)) { property.SetValue(this, TPropertyValHelper.GetPropertyValAsNullableBool(valueList, property.Name)); } else if (property.PropertyType == typeof(char)) { property.SetValue(this, TPropertyValHelper.GetPropertyValAsChar(valueList, property.Name)); } else if (property.PropertyType == typeof(char?)) { property.SetValue(this, TPropertyValHelper.GetPropertyValAsNullableChar(valueList, property.Name)); } else if (property.PropertyType == typeof(int)) { property.SetValue(this, TPropertyValHelper.GetPropertyValAsInt(valueList, property.Name)); } else if (property.PropertyType == typeof(int?)) { property.SetValue(this, TPropertyValHelper.GetPropertyValAsNullableInt(valueList, property.Name)); } else if (property.PropertyType == typeof(DateTime)) { property.SetValue(this, TPropertyValHelper.GetPropertyValAsDateTime(valueList, property.Name)); } else if (property.PropertyType == typeof(DateTime?)) { property.SetValue(this, TPropertyValHelper.GetPropertyValAsNullableDateTime(valueList, property.Name)); } else if (property.PropertyType.IsEnum) { var enumVal = TPropertyValHelper.GetPropertyValAsInt(valueList, property.Name); if (Enum.IsDefined(property.PropertyType, enumVal)) { property.SetValue(this, Enum.ToObject(property.PropertyType, enumVal)); } } else if (property.PropertyType.IsNullableEnum()) { var enumVal = TPropertyValHelper.GetPropertyValAsNullableInt(valueList, property.Name); if (enumVal.HasValue) { var enumType = Nullable.GetUnderlyingType(property.PropertyType); if (Enum.IsDefined(enumType, enumVal)) { property.SetValue(this, Enum.ToObject(enumType, enumVal)); } } } else if (property.PropertyType == typeof(string)) { property.SetValue(this, TPropertyValHelper.GetPropertyValAsString(valueList, property.Name)); } else if (property.PropertyType == typeof(List <string>)) { property.SetValue(this, TPropertyValHelper.GetPropertyValAsStringList(valueList, property.Name)); } } }
private TPropertyValue buildTPropertyValue(PropertyInfo property) { if (property.SetMethod != null && property.SetMethod.IsPublic) { //bool? //char? //DateTime? //int? //Enum? //string //List<string> var value = property.GetValue(this); if (value != null) { if (property.PropertyType == typeof(bool)) { return(TPropertyValHelper.SetPropertyValue((bool)value, property.Name)); } if (property.PropertyType == typeof(bool?)) { return(TPropertyValHelper.SetPropertyValue((bool?)value, property.Name)); } if (property.PropertyType == typeof(char)) { return(TPropertyValHelper.SetPropertyValue((char)value, property.Name)); } if (property.PropertyType == typeof(char?)) { return(TPropertyValHelper.SetPropertyValue((char?)value, property.Name)); } if (property.PropertyType == typeof(int)) { return(TPropertyValHelper.SetPropertyValue((int)value, property.Name)); } if (property.PropertyType == typeof(int?)) { return(TPropertyValHelper.SetPropertyValue((int?)value, property.Name)); } if (property.PropertyType == typeof(DateTime)) { return(TPropertyValHelper.SetPropertyValue((DateTime)value, property.Name)); } if (property.PropertyType == typeof(DateTime?)) { return(TPropertyValHelper.SetPropertyValue((DateTime?)value, property.Name)); } if (property.PropertyType.IsEnum) { return(Enum.IsDefined(property.PropertyType, value) ? TPropertyValHelper.SetPropertyValue((int)Enum.ToObject(property.PropertyType, value), property.Name) : null); } if (property.PropertyType.IsNullableEnum()) { var enumType = Nullable.GetUnderlyingType(property.PropertyType); return(Enum.IsDefined(enumType, value) ? TPropertyValHelper.SetPropertyValue((int)Enum.ToObject(enumType, value), property.Name) : null); } if (property.PropertyType == typeof(string)) { return(TPropertyValHelper.SetPropertyValue((string)value, property.Name)); } if (property.PropertyType == typeof(List <string>)) { return(TPropertyValHelper.SetPropertyValue((List <string>)value, property.Name)); } } } return(null); }