コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public ActionResult Create(AddTeacherCommand teacherCommand)
 {
     try
     {
         _addTeacher.Handle(teacherCommand);
         return RedirectToAction("Index");
     }catch(Exception e)
     {
         ModelState.AddModelError("", e.Message);
     }
     return View(teacherCommand);
 }