public async Task Then_Gets_Standards_From_Courses_Api(
            GetCourseListQuery query,
            GetStandardsListResponse apiResponse,
            [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockApiClient,
            GetCourseListQueryHandler handler)
        {
            mockApiClient
            .Setup(client => client.Get <GetStandardsListResponse>(It.IsAny <GetActiveStandardsListRequest>()))
            .ReturnsAsync(apiResponse);

            var result = await handler.Handle(query, CancellationToken.None);

            result.Courses.Should().BeEquivalentTo(apiResponse.Standards);
        }
Пример #2
0
        public async Task <IReadOnlyList <CourseStatisticsViewModel> > Handle(GetCourseListQuery request, CancellationToken cancellationToken)
        {
            string query = "SELECT Id AS 'CourseId'," +
                           "		MinimumStudentAge AS 'MinimumAgeOfStudents',"+
                           "		MaximumStudentAge AS 'MaximumAgeOfStudents',"+
                           "		AverageStudentAge AS 'AverageAgeOfStudents',"+
                           "		MaximumStudentsCount AS 'TotalCapacity',"+
                           "		EnrolledStudentsCount AS 'CurrentNumberOfStudents'"+
                           "FROM dbo.Courses";

            using (IDbConnection db = new SqlConnection(_options.Value.ConnectionString))
            {
                return((await db.QueryAsync <CourseStatisticsViewModel>(query))
                       .ToList()
                       .AsReadOnly());
            }
        }
Пример #3
0
        public async Task ShouldGetCourseList()
        {
            var command = new CreateCourseItemCommand()
            {
                Name = "Course1",
                Rate = 40,
            };
            var createCourseItemDto = await SendAsync(command);

            var created = await ExecuteDbContextAsync(db =>
                                                      db.Courses.Where(c => c.Id.Equals(createCourseItemDto.Id)).SingleOrDefaultAsync());

            GetCourseListQuery query = new GetCourseListQuery();
            GetObjectListVm <GetCourseItemDto> dto = await SendAsync(query);

            dto.ShouldNotBeNull();
            dto.Count.ShouldBeGreaterThanOrEqualTo(1);
            dto.Data.ShouldContain(d => d.Id.Equals(created.Id));
        }
Пример #4
0
            public async Task <GetObjectListVm <GetCourseItemDto> > Handle(GetCourseListQuery request, CancellationToken cancellationToken)
            {
                var courses = await context.Courses
                              .AsNoTracking()
                              .ToListAsync(cancellationToken);

                var list = courses
                           .Select(x => new GetCourseItemDto
                {
                    Id   = x.Id,
                    Name = x.Name,
                    Rate = x.Rate,
                }).ToList();


                var dto = new GetObjectListVm <GetCourseItemDto>
                {
                    Count = list.Count,
                    Data  = list
                };

                return(dto);
            }
Пример #5
0
        public async Task <IActionResult> Get(GetCourseListQuery query)
        {
            var result = await _mediatr.Send(query);

            return(Ok(result));
        }
Пример #6
0
 public async Task <ActionResult <PagenatedList <CourseDto> > > GetActives(GetCourseListQuery query)
 {
     query.Status = CourseApprovalStatus.ApprovedByAdminOrActivatedByTeacher;
     return(Ok(await _mediator.Send(query)));
 }
Пример #7
0
 public async Task <ActionResult <PagenatedList <CourseDto> > > Get(GetCourseListQuery query)
 {
     return(Ok(await _mediator.Send(query)));
 }