public void CreateInstructor_UnderNormalConditions_AddsInstructorToInstructorList() { //arrange var instructorToBeCreated = new InstructorDto() { InstructorName = "test instructor name", IsActive = true }; var originalCountOfInstructors = _instructorList.Count; var mockInstructorRepo = Mock.Create <IInstructorRepository>(); Mock.Arrange(() => mockInstructorRepo.Create(Arg.IsAny <Instructor>())) .DoInstead(() => _instructorList.Add(instructorToBeCreated)) .OccursOnce(); _instructorService = new InstructorService(mockInstructorRepo); //act _instructorService.Create(instructorToBeCreated); var actualCount = _instructorList.Count; //assert Mock.Assert(mockInstructorRepo); Assert.That(actualCount, Is.EqualTo(originalCountOfInstructors + 1)); }
public async Task <IActionResult> Post([FromBody] Instructor instructor) { return(Ok(await _service.Create(instructor))); }