public async void GetSearchesByPeriodQueryHandler_should_return_searches_by_period() { // Arrange var searches = Builder <Search> .CreateListOfSize(10) .TheFirst(1) .With(s => s.Id = "1254") .With(s => s.Timestamp = new DateTime(2021, 2, 3)) .TheRest() .With(s => s.Id = Guid.NewGuid().ToString()) .With(s => s.Timestamp = new DateTime(2021, 3, 3)) .Build(); A.CallTo(() => _mongoDBService.GetAsync(new DateTime(2021, 2, 1), new DateTime(2021, 2, 4))).Returns(new List <Search>() { searches[0] }); var command = new GetSearchesByPeriodQuery { StartDate = new DateTime(2021, 2, 1), EndDate = new DateTime(2021, 2, 4) }; // Act var result = await _getSearchesByPeriodQueryHandler.Handle(command, default); // Assert A.CallTo(() => _mongoDBService.GetAsync(new DateTime(2021, 2, 1), new DateTime(2021, 2, 4))).MustHaveHappenedOnceExactly(); Assert.Equal(searches[0].Id, result.ToList()[0].Id); }
public async void GetAllSearchesQueryHandler_should_return_searches() { // Arrange var searches = Builder <Search> .CreateListOfSize(10) .All() .With(s => s.Id = Guid.NewGuid().ToString()) .Build(); A.CallTo(() => _mongoDBService.GetAsync()).Returns(searches.ToList()); var command = new GetAllSearchesQuery(); // Act var result = await _getAllSearchesQueryHandler.Handle(command, default); // Assert A.CallTo(() => _mongoDBService.GetAsync()).MustHaveHappenedOnceExactly(); Assert.Equal(10, result.ToList().Count); }
public async Task <IEnumerable <SearchDto> > Handle(GetSearchesByPeriodQuery request, CancellationToken cancellationToken) { if (request.EndDate <= request.StartDate) { throw new ValidationException("End date must be greater than start date."); } var result = await _mongoDBService.GetAsync(request.StartDate, request.EndDate); return(_mapper.Map <List <SearchDto> >(result)); }
public async void GetSearchByIdQueryHandler_should_return_searches_by_id() { // Arrange var searches = Builder <Search> .CreateListOfSize(10) .TheFirst(1) .With(s => s.Id = "1254") .TheRest() .With(s => s.Id = Guid.NewGuid().ToString()) .Build(); A.CallTo(() => _mongoDBService.GetAsync("1254")).Returns(searches[0]); var command = new GetSearchByIdQuery { Id = "1254" }; // Act var result = await _getSearchByIdQueryHandler.Handle(command, default); // Assert A.CallTo(() => _mongoDBService.GetAsync("1254")).MustHaveHappenedOnceExactly(); Assert.Equal(searches[0].Id, result.Id); }
public async Task <SearchDto> Handle(GetSearchByIdQuery request, CancellationToken cancellationToken) { var result = await _mongoDBService.GetAsync(request.Id); return(_mapper.Map <SearchDto>(result)); }
public async Task <IEnumerable <SearchDto> > Handle(GetAllSearchesQuery request, CancellationToken cancellationToken) { var result = await _mongoDBService.GetAsync(); return(_mapper.Map <List <SearchDto> >(result)); }