public void TestCreateGoalRequiredFields() { var goal1 = new Goal() { UserId = 1, Title = "This is a goal", Info = "info" /*EndDT = Convert.ToDateTime("")*/ }; var goal2 = new Goal() { UserId = 1, Title = "", Info = "info", EndDT = Convert.ToDateTime("2018-10-10 00:00:00") }; var goal3 = new Goal() { UserId = 1, Title = "I'm going to write a book", Info = "info", EndDT = Convert.ToDateTime("2019-12-12 00:00:00") }; var failList = new List <bool>(); var successList = new List <bool>(); // Logic aanroepen // Check fail 1 : goal1 failList.Add(gLogic.Add(goal1.UserId, goal1.Title, goal1.Info, goal1.StartDT, goal1.EndDT)); // Check fail 2 : goal2 failList.Add(gLogic.Add(goal2.UserId, goal2.Title, goal2.Info, goal2.StartDT, goal2.EndDT)); // Check success 1 : goal3 successList.Add(gLogic.Add(goal3.UserId, goal3.Title, goal3.Info, goal3.StartDT, goal3.EndDT)); for (int i = 0; i < failList.Count; i++) { if (failList[i]) { Assert.Fail("Check " + (i + 1) + " van de fails heeft gefaald."); } } // Resultaten van de success checks for (int i = 0; i < successList.Count; i++) { if (!successList[i]) { Assert.Fail("Check " + (i + 1) + " van de successes heeft gefaald."); } } }
public void TestGoals() { var userId = 99; // Goal aanmaken var goal = new Goal() { Title = "I am going to write a book!", Info = "it is going to be great!", StartDT = Convert.ToDateTime("05-05-2018"), EndDT = Convert.ToDateTime("12-12-2018") }; Assert.IsTrue(gLogic.Add(userId, goal.Title, goal.Info, goal.StartDT, goal.EndDT)); var get = gLogic.GetAllByUserId(userId)[0]; Assert.AreEqual(goal.Title, get.Title); // Goal aanpassen var edit = new Goal() { GoalId = get.GoalId, Title = "I am going to write a book!", Info = "", StartDT = null, EndDT = Convert.ToDateTime("12-12-2018"), Progress = 34, UserId = userId }; Assert.IsTrue(gLogic.Edit(edit)); // Goal afronden get = gLogic.GetAllByUserId(userId)[0]; Assert.AreEqual(edit.Info, get.Info); Assert.IsTrue(gLogic.FinishGoal(get.GoalId)); get = gLogic.GetAllByUserId(userId)[0]; Assert.AreEqual(100, get.Progress); Assert.AreEqual(GoalStatus.Finished, get.Status); }
public IActionResult Create(CreateGoalViewModel model) { if (!ModelState.IsValid) { return(View(model)); } int id = Convert.ToInt32(User.Claims.Where(c => c.Type == "Id") .Select(c => c.Value).SingleOrDefault()); bool created = logic.Add(id, model.Title, model.Info, model.StartDT, model.EndDT); if (!created) { ModelState.AddModelError("", "Creating of the goal failed."); return(View(model)); } return(RedirectToAction("Index")); }