public void pluralizer_factory_returns_unchanged_class_name_for_non_entity_type() { // Arrange string tableName = "Customer"; string result = tableName; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged"); PluralizerFactory factory = new PluralizerFactory(); // Act result = factory.SetWord(tableName, classType); // Assert Assert.AreEqual(tableName, result); }
public void pluralizer_factory_test() { // Arrange string tableName = "aspnet_Applications"; string result = tableName; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged"); PluralizerFactory factory = new PluralizerFactory(); // Act result = factory.SetWord(tableName, classType); // Assert Assert.AreEqual(tableName, result); }
public string ToPropertyName() { if (this.Alias.ToLower() == script.Settings.DataOptions.VersionColumnName.ToLower()) { return(this.Alias); } else { ////return script.DnpUtils.SetPascalCase(this.Alias); //return this.Alias; ePluralizerTypes propertyType = EnumFactory.Parse <ePluralizerTypes>(script.Settings.Pluralizer.PropertyNames.Selected); PluralizerFactory factory = new PluralizerFactory(); string result = factory.SetWord(this.Alias, propertyType); return(result); } }
public void plural_table_name_is_replaced_with_singular_table_name_using_singular_type() { // Arrange string tableName = "aspnet_Applications"; string actual = ""; string expected = "aspnet_Application"; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Singular"); PluralizerFactory factory = new PluralizerFactory(); // Act actual = factory.SetWord(tableName, classType); // Assert Assert.AreEqual(expected, actual); }
public void table_name_with_underscore_is_correctly_kept_using_unchanged_pluralizerfactory() { // Arrange string tableName = "aspnet_Applications"; string actual = ""; string expected = "aspnet_Applications"; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged"); PluralizerFactory factory = new PluralizerFactory(); // Act actual = factory.SetWord(tableName, classType); // Assert Assert.AreEqual(expected, actual); }
public void pluralizer_factory_returns_plural_result_for_singular_class_name_based_on_plural_setting() { // Arrange string tableName = "Customer"; string result = tableName; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Plural"); PluralizerFactory factory = new PluralizerFactory(); // Act result = factory.SetWord(tableName, classType); string expected = "Customers"; // Assert Assert.AreEqual(expected, result); }
public void pluralizer_factory_isentityset_returns_correct_result_for_input_with_underscore() { // Arrange string tableName = "aspnet_Applications"; string result = tableName; bool isEntitySet = true; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged"); PluralizerFactory factory = new PluralizerFactory(); // Act result = factory.SetWord(tableName, classType, isEntitySet); // Assert Assert.AreEqual(tableName, result); }
public void pluralizer_factory_isentityset_returns_plural_entitysetname_for_non_underscore_class_name() { // Arrange string tableName = "Project"; string result = tableName; bool isEntitySet = true; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged"); PluralizerFactory factory = new PluralizerFactory(); // Act result = factory.SetWord(tableName, classType, isEntitySet); string expected = "Projects"; // Assert Assert.AreEqual(expected, result); }
/// <summary> /// 获取用户 /// </summary> /// <param name="userDictionary"></param> /// <param name="host"></param> /// <param name="isMatch"></param> /// <param name="matchPlatform"></param> /// <param name="loginFuc"></param> /// <param name="cookie"></param> /// <returns></returns> public static DataResult <User> GetUser(ConcurrentDictionary <User, CookieContainer> userDictionary, string host, bool isMatch, MatchPlatform matchPlatform, Func <string, string, string, DataResult <CookieContainer> > loginFuc, out CookieContainer cookie) { var dataResult = new DataResult <User>(); var messageSubjectEnum = EnumFactory <MessageSubjectEnum> .Parse(matchPlatform); User user; cookie = null; var dateTime = DateTime.UtcNow.Date.AddHours(-8); using (var db = new ResumeMatchDBEntities()) { if (userDictionary.Keys.All(a => a.Host != host)) { List <User> users; if (isMatch) { users = db.User.Where(w => w.IsEnable && w.Platform == (short)matchPlatform && w.Status == 1 && w.Host == host).ToList(); } else { users = db.User.Where(w => w.IsEnable && w.Platform == (short)matchPlatform && w.Status == 1 /* && w.Host == host*/ && (w.LastLoginTime == null || w.DownloadNumber > 0 || w.LastLoginTime < dateTime)).ToList(); } if (!users.Any()) { dataResult.IsSuccess = false; dataResult.Code = ResultCodeEnum.NoUsers; return(dataResult); } foreach (var item in users) { for (var i = 0; i < 5; i++) { if (userDictionary.TryAdd(item, null)) { break; } if (i == 4) { LogFactory.Warn($"向字典中添加用户 {item.Email} 失败!", messageSubjectEnum); } } } } Next: if (isMatch) { var userQuery = userDictionary.Keys.Where(f => f.IsEnable && f.Host == host); if (!string.IsNullOrWhiteSpace(host)) { userQuery = userQuery.Where(w => w.RequestDate == null || w.RequestDate.Value.Date < DateTime.UtcNow.Date || w.RequestDate.Value.Date == DateTime.UtcNow.Date && w.RequestNumber < Global.TodayMaxRequestNumber); } user = userQuery.OrderBy(o => o.RequestNumber).FirstOrDefault(); } else { user = userDictionary.Keys .Where(f => f.IsEnable /*&& f.Host == host */ && (f.LastLoginTime == null || f.DownloadNumber > 0 || f.LastLoginTime < dateTime)) .OrderBy(o => o.Email) .FirstOrDefault(); } if (user == null) { dataResult.IsSuccess = false; if (isMatch) { dataResult.Code = ResultCodeEnum.RequestUpperLimit; } else { dataResult.Code = ResultCodeEnum.NoUsers; } LogFactory.Warn(JsonConvert.SerializeObject(userDictionary), messageSubjectEnum); var list = userDictionary.Keys.Where(w => w.Host == host); foreach (var item in list) { for (var i = 0; i < 5; i++) { if (userDictionary.TryRemove(item, out cookie)) { break; } if (i == 4) { LogFactory.Warn($"从字典中移除用户 {item.Email} 失败!", messageSubjectEnum); dataResult.ErrorMsg += $"向字典中移除用户 {item.Email} 失败!"; return(dataResult); } } } return(dataResult); } if (isMatch) { if (user.RequestDate == null || user.RequestDate.Value.Date < DateTime.UtcNow.Date) { user.RequestDate = DateTime.UtcNow.Date; user.RequestNumber = 0; } user.RequestNumber++; } for (var i = 0; i < 5; i++) { if (userDictionary.TryGetValue(user, out cookie)) { break; } } if (cookie == null) { var result = loginFuc(user.Email, user.Password, host); if (!result.IsSuccess) { LogFactory.Warn(result.ErrorMsg, messageSubjectEnum); userDictionary.TryRemove(user, out cookie); dataResult.IsSuccess = false; return(dataResult); } cookie = result.Data; if (cookie != null) { for (var i = 0; i < 5; i++) { if (userDictionary.TryUpdate(user, cookie, null)) { break; } } } } if (cookie == null) { goto Next; } var userEntity = db.User.FirstOrDefault(f => f.Id == user.Id); if (userEntity != null) { userEntity.RequestDate = user.RequestDate; userEntity.RequestNumber = user.RequestNumber; } db.TransactionSaveChanges(); } dataResult.Data = user; return(dataResult); }