Ejemplo n.º 1
0
        public async Task <IActionResult> GetById(int id)
        {
            Lesson lesson = await _lessonService.GetByIdAsync(id, x => x.Attachments, x => x.Subject);

            if (lesson == null)
            {
                return(NotFound());
            }
            if (lesson.Subject.TeacherId != _userService.UserId)
            {
                return(Forbid());
            }
            LessonDto result = _mapper.Map <LessonDto>(lesson);

            result.Attachments = _mapper.Map <List <AttachmentDto> >(lesson.Attachments);

            return(Ok(result));
        }
Ejemplo n.º 2
0
        public async Task GetAsyncGivenAnIdThenReturnsALesson()
        {
            var mockLessonRepository = GetDefaultILessonRepositoryInstance();
            var mockUnityOfWork      = GetDefaultIUnitOfWorkInstance();
            var lessonId             = 2;
            var mockLesson           = new Mock <Lesson>();

            mockLesson.Object.Id      = 2;
            mockLesson.Object.Vacants = 3;
            mockLessonRepository.Setup(r => r.FindById(lessonId))
            .Returns(Task.FromResult(mockLesson.Object));

            var            service = new LessonService(mockLessonRepository.Object, mockUnityOfWork.Object);
            LessonResponse result  = await service.GetByIdAsync(lessonId);

            var id      = result.Resource.Id;
            var vacants = result.Resource.Vacants;

            id.Should().Be(2);
            vacants.Should().Be(3);
        }
Ejemplo n.º 3
0
        public async void WhenISeeTheLessonDescription__()
        {
            var service = new LessonService(mockLessonRepository.Object, mockUnitOfWork.Object);

            result = await service.GetByIdAsync(lesson.Id);
        }