コード例 #1
0
        public async Task GetAsync_StudentIdDoesnotExist_ReturnsNullObject()
        {
            Mock <IStudentRepository> studentRepositoryMock = new Mock <IStudentRepository>();

            studentRepositoryMock.Setup(m => m.GetAsync(It.IsAny <int>())).ReturnsAsync(this.GetStudent_DoesnotExit(It.IsAny <int>()));

            DataAccess.Model.Student actual = await studentRepositoryMock.Object.GetAsync(It.IsAny <int>());

            actual.Should().BeNull();
        }
コード例 #2
0
        public async Task GetAsync_StudentIdExists_ReturnsStudentInfo()
        {
            Mock <IStudentRepository> studentRepositoryMock = new Mock <IStudentRepository>();

            studentRepositoryMock.Setup(m => m.GetAsync(It.IsAny <int>())).ReturnsAsync(this.GetStudent(It.IsAny <int>()));
            DataAccess.Model.Student expected = this.GetStudent(It.IsAny <int>());

            DataAccess.Model.Student actual = await studentRepositoryMock.Object.GetAsync(It.IsAny <int>());

            actual.Should().NotBeNull();
            actual.Should().BeEquivalentTo(expected);
        }
コード例 #3
0
        public async Task <IActionResult> CreateAsync(StudentDto studentDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("values provided are invalid"));
            }

            DataAccess.Model.Student student = mapper.Map <DataAccess.Model.Student>(studentDto);

            var result = await studentService.CreateAsync(student);

            student.Id = result;

            return(CreatedAtAction(nameof(GetAsync), new { id = result }, student));
        }
コード例 #4
0
        public async Task <IActionResult> UpdateAsync(DataAccess.Model.Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("values provided are invalid"));
            }

            var result = await studentService.UpdateAsync(student);

            if (!result)
            {
                return(NotFound($"Student with id {student.Id} was not found"));
            }

            return(NoContent());
        }