public async Task <IEnumerable <HolidayDto> > Handle(GetHolidayListQuery request, CancellationToken cancellationToken) { var holidays = await _repository.Queryable().Where(x => x.CompanyId == request.CompanyId).ToListAsync(); _logger.LogInformation($"Got a request get holidays by CompanyId: {request.CompanyId}"); List <HolidayDto> holidayDtos = new List <HolidayDto>(); if (holidays.Count > 0) { holidayDtos.AddRange(holidays.Select(x => _mapper.Map <HolidayDto>(x)).ToList()); } return(holidayDtos); }
public async Task Should_ReturnEmptyList_When_PassValidCompanyId() { // Arrange IRepository <Holiday> repository = new Repository <Holiday>(_fixture.Context); var handler = new GetHolidayListHandler(repository, _mapper, _logger); var queryRequest = new GetHolidayListQuery(companyId: 3); // Act var tcs = new CancellationToken(); var result = await handler.Handle(queryRequest, tcs); // Assert Assert.Empty(result); }
public async Task Should_ReturnLeaveTypeList_When_PassValidCompanyId() { // Arrange var holiday = new Holiday() { HolidayId = 1, CompanyId = 1, CreatedAt = DateTime.Now, CreatedBy = -1, Name = "Holiday Test - 1" }; _fixture.Context.Holidays.Add(holiday); holiday = new Holiday() { HolidayId = 2, CompanyId = 1, CreatedAt = DateTime.Now, CreatedBy = -1, Name = "Holiday Test - 2" }; _fixture.Context.Holidays.Add(holiday); _fixture.Context.SaveChanges(); IRepository <Holiday> repository = new Repository <Holiday>(_fixture.Context); var handler = new GetHolidayListHandler(repository, _mapper, _logger); var queryRequest = new GetHolidayListQuery(companyId: 1); // Act var tcs = new CancellationToken(); var result = await handler.Handle(queryRequest, tcs); // Assert Assert.NotEmpty(result); Assert.Equal(2, result.Count()); }