public void Validate_Support_Log() { // Arrange SupportLog supportLog = new SupportLog() { SupportLogEntryDate = DateTime.Now, SupportLogEntry = "Filler text, just needs to be long enough", SupportLogUpdatedBy = "John Smith" }; SupportLog supportLog2 = new SupportLog() { SupportLogEntryDate = Convert.ToDateTime("2017-1-1 10:00"), SupportLogEntry = "fail", SupportLogUpdatedBy = "J" }; ModelValidation modelValidation = new ModelValidation(); // Act bool valid = modelValidation.ValidateSupportLog(supportLog, "save"); bool invald = modelValidation.ValidateSupportLog(supportLog2, "save"); // Assert Assert.IsTrue(valid); Assert.IsFalse(invald); Assert.AreEqual("Date is not valid", modelValidation.errorList[0].Error.ToString()); Assert.AreEqual("Enter at least 10 characters.", modelValidation.errorList[1].Error.ToString()); Assert.AreEqual("Enter at least 2 characters", modelValidation.errorList[2].Error.ToString()); }
public bool ValidateSupportLog(SupportLog supportLog, string updateOrSave) { bool valid = true; Errors error; if (updateOrSave.ToLower() == "update") { valid = SupportTicketIdExists(supportLog.SupportTicketId); error = new Errors { Position = 0, FieldName = "SupportTicketId", Error = "Not a valid SupportTicketId" }; errorList.Add(error); } if (supportLog.SupportLogEntryDate < DateTime.Now.AddSeconds(-180)) { valid = false; error = new Errors { Position = 0, FieldName = "SupportLogEntryDate", Error = "Date is not valid" }; errorList.Add(error); } if (supportLog.SupportLogEntry.Length < 10) { valid = false; error = new Errors { Position = 0, FieldName = "SupportLogEntry", Error = "Enter at least 10 characters." }; errorList.Add(error); } if (supportLog.SupportLogUpdatedBy.Length < 2) { valid = false; error = new Errors { Position = 0, FieldName = "SupportLogUpdatedBy", Error = "Enter at least 2 characters" }; errorList.Add(error); } return(valid); }
public ActionResult MakeAsChecked(int id) { var data = rtsrepo.GetById(id); SupportLog supportlog = new SupportLog(); supportlog.RequestSubject = data.RequestSubject; supportlog.RequestBody = data.RequestBody; supportlog.SenderUserName = data.SenderUserName; supportlog.UserType = data.UserType; supportlog.Date = DateTime.Now; supportlog.SupportUserName = Session["UserName"].ToString(); suplogrepo.Insert(supportlog); rtsrepo.Delete(id); return(RedirectToAction("ViewSupportRequest")); }
private void AddSupportLogEntry(string entry, bool close, int ticketId) { bool modelIsValid = false; ModelValidation mv = new ModelValidation(); Console.WriteLine("Saving new log entry"); using (MachineContext context = new MachineContext()) { SupportLog sLogEntry = new SupportLog() { SupportTicketId = ticketId, SupportLogEntry = entry, SupportLogUpdatedBy = Environment.UserName, SupportLogEntryDate = DateTime.Now //DateTime.Now.AddSeconds(-2000) }; modelIsValid = mv.ValidateSupportLog(sLogEntry, "save"); if (modelIsValid) { context.SupportLog.Add(sLogEntry); int res = context.SaveChanges(); Console.WriteLine($"{res} record saved"); } } if (modelIsValid) { if (close) { CloseTicket(ticketId); } } else { Console.WriteLine("There is a problem with your Entry"); foreach (var error in mv.errorList) { Console.WriteLine($"{error.FieldName} {error.Error}"); } } }
public CustomerSupportLogRequest(Customer c, SupportLog log) { }