public void AddTeacher_WithValidTeacherAndCourse() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_GUNNA, Type = TeacherType.MainTeacher }; var prevCount = _teacherRegistrations.Count; // Note: the method uses test data defined in [TestInitialize] // Act: var dto = _service.AddTeacherToCourse(COURSEID_VEFT_20163, model); // Assert: // Check that the dto object is correctly populated: Assert.AreEqual(SSN_GUNNA, dto.SSN); Assert.AreEqual(NAME_GUNNA, dto.Name); // Ensure that a new entity object has been created: var currentCount = _teacherRegistrations.Count; Assert.AreEqual(prevCount + 1, currentCount); // Get access to the entity object and assert that // the properties have been set: var newEntity = _teacherRegistrations.Last(); Assert.AreEqual(COURSEID_VEFT_20163, newEntity.CourseInstanceID); Assert.AreEqual(SSN_GUNNA, newEntity.SSN); Assert.AreEqual(TeacherType.MainTeacher, newEntity.Type); // Ensure that the Unit Of Work object has been instructed // to save the new entity object: Assert.IsTrue(_mockUnitOfWork.GetSaveCallCount() > 0); // Assert.HasBeenCalled(_mockUnitOfWork.Save); // spyOn(obj, "doStuff").andCallThrough(); // expect(obj.doStuff).to.haveBeenCalled(); }
public IActionResult AddTeacher(int id, AddTeacherViewModel model) { if (model == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = _service.AddTeacherToCourse(id, model); return(Created("TODO", result)); } catch (AppObjectNotFoundException) { return(NotFound()); } catch (AppValidationException) { return(BadRequest()); } }
public void AddTeacher_WithValidTeacherAndCourse() { // Arrange: var model = new AddTeacherViewModel { SSN = SSN_GUNNA, Type = TeacherType.MainTeacher }; var prevCount = _teacherRegistrations.Count; // Act: var dto = _service.AddTeacherToCourse(COURSEID_VEFT_20163, model); // Assert: // Check that the dto object is correctly populated: Assert.Equals(SSN_GUNNA, dto.SSN); Assert.Equals(NAME_GUNNA, dto.Name); // Ensure that a new entity object has been created: var currentCount = _teacherRegistrations.Count; Assert.Equals(prevCount + 1, currentCount); // Get access to the entity object and assert that // the properties have been set: var newEntity = _teacherRegistrations.Last(); Assert.Equals(COURSEID_VEFT_20163, newEntity.CourseInstanceID); Assert.Equals(SSN_GUNNA, newEntity.SSN); Assert.Equals(TeacherType.MainTeacher, newEntity.Type); // Ensure that the Unit Of Work object has been instructed // to save the new entity object: Assert.IsTrue(_mockUnitOfWork.GetSaveCallCount() > 0); }
public IActionResult AddTeacher(int id, AddTeacherViewModel model) { var result = _service.AddTeacherToCourse(id, model); return(Created("TODO", result)); }