public async Task Post_ShouldBe_ok() { // 1、Arrange User entity = new User() { Password = MD5Helper.Get32UpperMD5("123456"), Account = "admin" }; var str = JsonConvert.SerializeObject(entity); HttpContent content = new StringContent(str); // 2、Act content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); HttpResponseMessage response = await Client.PostAsync("api/login", content); string responseBody = await response.Content.ReadAsStringAsync(); Output.WriteLine(responseBody); ValidateInfo validate = JsonConvert.DeserializeObject <ValidateInfo>(responseBody); // 3、Assert Assert.Equal(0, validate.Code); }
private void LoginButton_Click(object sender, EventArgs e) { string username = UsernameText.Text; string password = PasswordText.Text; var cust = db.CUSTOMERs.Where(c => c.Username.Equals(username)).FirstOrDefault(); if (cust == null) { ValidateInfo.SetError(LoginButton, "Invalid Username or Password"); } else if (cust.Pswrd.Trim().Equals(password)) { CustomerForm cf = new CustomerForm(cust, db); this.Hide(); cf.ShowDialog(); this.Close(); } ValidateInfo.SetError(LoginButton, "Invalid Username or Password"); }
public async Task <ValidateInfo> Post([FromBody] User entity) { ValidateInfo validateInfo = new ValidateInfo(); Expression <Func <User, bool> > keySelector = p => p.Account.Equals(entity.Account); User user = await _service.GetSingleEntityAsync(keySelector); if (null != user && user.Password.Equals(MD5Helper.Get32UpperMD5(entity.Password))) { // 生成Token信息 TokenInfo token = _helper.CreateToken(user); validateInfo.Code = 0; validateInfo.Message = "成功"; validateInfo.TokenContent = token.TokenContent; } else { validateInfo.Code = 1; validateInfo.Message = "失败"; } return(validateInfo); }
public static List <String> GetNeedsUpdateReasons(DateTime currentTime, ValidateInfo info) { var history = info.History; List <String> reasons = new List <String>(); if (info.User.IsReadOnly) { return(reasons); } if (history?.LastUploadedCommandsAt == null || (currentTime - history.LastUploadedCommandsAt.Value > info.MaxCommandsAge)) { reasons.Add("UPLOAD_COMMANDS_REQUIRED"); } if (history?.LastUploadedIncomingsAt == null || (currentTime - history.LastUploadedIncomingsAt.Value > info.MaxIncomingsAge)) { reasons.Add("UPLOAD_INCOMINGS_REQUIRED"); } if (history?.LastUploadedReportsAt == null || (currentTime - history.LastUploadedReportsAt.Value > info.MaxReportsAge)) { reasons.Add("UPLOAD_REPORTS_REQUIRED"); } if (history?.LastUploadedTroopsAt == null || (currentTime - history.LastUploadedTroopsAt.Value > info.MaxTroopsAge)) { reasons.Add("UPLOAD_TROOPS_REQUIRED"); } return(reasons); }
/// <summary> /// Initializes a ConnectionAssertionError instance. /// </summary> /// <param name="caeType">The type of error.</param> /// <param name="elem">The graph element, where the error was found.</param> /// <param name="found">The number of edges found in the graph, if CAEType != CAEType.EdgeNotSpecified.</param> /// <param name="valInfo">The corresponding ValidatedInfo object, if CAEType != CAEType.EdgeNotSpecified, otherwise null.</param> public ConnectionAssertionError(CAEType caeType, IGraphElement elem, long found, ValidateInfo valInfo) { CAEType = caeType; Elem = elem; FoundEdges = found; ValidateInfo = valInfo; }
private static bool ValidateSource(INode node, ValidateInfo valInfo, List<ConnectionAssertionError> errors, Dictionary<IEdge, bool> checkedOutEdges, Dictionary<IEdge, bool> checkedInEdges) { bool result = true; // Check outgoing edges long num = CountOutgoing(node, valInfo.EdgeType, valInfo.TargetType, checkedOutEdges); if(valInfo.BothDirections) { long incoming = CountIncoming(node, valInfo.EdgeType, valInfo.TargetType, checkedInEdges); num -= CountReflexive(node, valInfo.EdgeType, valInfo.TargetType, num, incoming); num += incoming; } if(num < valInfo.SourceLower) { errors.Add(new ConnectionAssertionError(CAEType.NodeTooFewSources, node, num, valInfo)); result = false; } else if(num > valInfo.SourceUpper) { errors.Add(new ConnectionAssertionError(CAEType.NodeTooManySources, node, num, valInfo)); result = false; } return result; }
/// <summary> /// Validate that items in the event DB are internally consistent. /// </summary> public void Validate() { ValidateInfo validateInfo = new ValidateInfo(); validateInfo.eventDB = this; if (eventStore.IsPresent(new Id<Event>(1))) { GetEvent().Validate(new Id<Event>(1), validateInfo); } foreach (Id<ControlPoint> controlId in AllControlPointIds) GetControl(controlId).Validate(controlId, validateInfo); foreach (Id<Course> courseId in validateInfo.eventDB.AllCourseIds) GetCourse(courseId).Validate(courseId, validateInfo); foreach (Id<CourseControl> courseControlId in AllCourseControlIds) GetCourseControl(courseControlId).Validate(courseControlId, validateInfo); foreach (Id<Special> specialId in AllSpecialIds) GetSpecial(specialId).Validate(specialId, validateInfo); foreach (Id<Leg> legId in AllLegIds) GetLeg(legId).Validate(legId, validateInfo); }