コード例 #1
0
            public async Task <GetObjectListVm <GetTimeslotItemDto> > Handle(GetTimeslotListQuery request, CancellationToken cancellationToken)
            {
                var dailySchedules = await context.Timeslots
                                     .AsNoTracking()
                                     .ToListAsync(cancellationToken);

                var list = dailySchedules
                           .Select(entity => new GetTimeslotItemDto
                {
                    Id              = entity.Id,
                    Duration        = entity.Duration,
                    StartTime       = entity.StartTime,
                    Disabled        = entity.Disabled,
                    DailyScheduleId = entity.DailyScheduleId,
                }).ToList();


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

                return(dto);
            }
コード例 #2
0
        public async Task ShouldGetTimeslotList()
        {
            var instructorDto = await CreateInstructorAsync();

            var courseDto = await CreateCourseAsync();

            var locationDto = await CreateLocationWithInstructorAsync(instructorDto);

            var classroomDto = await CreateClassroomAsync(locationDto);

            var dailyScheduleDto = await CreateDailyScheduleAsync(classroomDto);

            var courseClassDto = await CreateCourseClassAsync(courseDto, locationDto);

            var subjectDto = await CreateSubjectAsync(instructorDto);

            var classSubjectDto = await CreateClassSubjectAsync(subjectDto, courseClassDto);

            var command = new CreateTimeslotItemCommand()
            {
                Disabled        = false,
                Duration        = new TimeSpan(1, 0, 0),
                StartTime       = new TimeSpan(0, 22, 0),
                DailyScheduleId = dailyScheduleDto.Id,
                ClassSubjectId  = classSubjectDto.Id,
            };
            var timeslotDto = await SendAsync(command);

            GetTimeslotListQuery query = new GetTimeslotListQuery()
            {
            };
            var dto = await SendAsync(query);

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

            dto.ShouldNotBeNull();
            dto.Count.ShouldBeGreaterThanOrEqualTo(1);
            dto.Data.ShouldContain(d => d.Id.Equals(created.Id));
        }