public void AddNote_InvalidStudent_ShouldReturnDefaultView() { AddNoteBm bind = new AddNoteBm() { Content = "Hi" }; _controller.WithCallTo(c => c.AddNote(bind, 2)).ShouldRenderDefaultView(); }
public void AddNote_ShouldRedirectToStudentNotes() { AddNoteBm bind = new AddNoteBm() { Content = "Hi" }; _controller.WithCallTo(c => c.AddNote(bind, 1)) .ShouldRedirectTo <StudentsController>(typeof(StudentsController).GetMethod("StudentNotes")); }
public ActionResult AddNote(AddNoteBm bind, int id) { if (this.ModelState.IsValid) { this.service.AddNote(bind, id); return(RedirectToAction("StudentNotes", "SchoolDiary")); } return(this.View()); }
public void AddNote_ShouldAddNote() { AddNoteBm bind = new AddNoteBm() { Content = "Hi" }; _service.AddNote(bind, 1); Assert.AreEqual(1, _context.Notes.Count()); Assert.AreEqual("Hi", _context.Notes.First().Content); }
public ActionResult AddNote(AddNoteBm bind, int id) { if (!this.service.IsStudentExists(id)) { this.ModelState.AddModelError("Student", "Ученикът трябва да фигурира в системата."); } if (this.ModelState.IsValid) { this.service.AddNote(bind, id); return(this.RedirectToAction("StudentNotes", "Students")); } return(this.View()); }
public void AddNote(AddNoteBm bind, int id) { Note note = new Note(); note.Content = bind.Content; note.Date = DateTime.Now; string username = bind.TeacherName; Teacher teacher = this.Context.Teachers.FirstOrDefault(t => t.User.UserName == username); note.Teacher = teacher; Student student = this.Context.Students.FirstOrDefault(s => s.Id == id); note.Student = student; this.Context.Notes.Add(note); this.Context.SaveChanges(); }