public void fails_to_add_a_duplicate_teacher() { _rep.Insert(new Teacher(1619, "Miguel Carvalho")); var cmd = new AddTeacherCommand { Id = 1619, Name = "Miguel Carvalho" }; var handler = new AddTeacher(_rep); Assert.Throws<DuplicateAggregateException>(() => handler.Handle(cmd)); }
public void adds_a_teacher() { var cmd = new AddTeacherCommand { Id = 1619, Name = "Miguel Carvalho" }; var handler = new AddTeacher(_rep); handler.Handle(cmd); var teacher = _rep.Query<Teacher>().FirstOrDefault(f => f.Id == cmd.Id); Assert.NotNull(teacher); Assert.AreEqual(cmd.Name, teacher.Name); }
public ActionResult Create(AddTeacherCommand teacherCommand) { try { _addTeacher.Handle(teacherCommand); return RedirectToAction("Index"); }catch(Exception e) { ModelState.AddModelError("", e.Message); } return View(teacherCommand); }