public async Task ShouldGetInstructorList() { var instructorDto = await SendAsync(new CreateInstructorItemCommand() { FirstName = "first", LastName = "last", HireDate = DateTime.UtcNow.DateTimeWithoutMilisecond(), }); var created = await ExecuteDbContextAsync(db => db.Instructor.Where(c => c.Id.Equals(instructorDto.Id)).SingleOrDefaultAsync()); GetInstructorListQuery query = new GetInstructorListQuery(); GetObjectListVm <GetInstructorItemDto> dto = await SendAsync(query); dto.ShouldNotBeNull(); dto.Count.ShouldBeGreaterThanOrEqualTo(1); dto.Data.ShouldContain(d => d.Id.Equals(created.Id)); }
public async Task <GetObjectListVm <GetInstructorItemDto> > Handle(GetInstructorListQuery request, CancellationToken cancellationToken) { var instructors = await context.Instructor .AsNoTracking() .ToListAsync(cancellationToken); var list = instructors .Select(entity => new GetInstructorItemDto { Id = entity.Id, Name = entity.FullName(), }).ToList(); var dto = new GetObjectListVm <GetInstructorItemDto> { Count = list.Count, Data = list }; return(dto); }