public async Task GetAvailableGroupDatesAsync__An_unexpected_internal_error_occurred__Should_throw_Exception() { _groupDbServiceMock.Setup(x => x.GetByAsync(It.IsAny <Expression <Func <SightseeingGroup, bool> > >())).ThrowsAsync(new Exception()); _infoDbServiceMock.Setup(x => x.GetAllAsync()).ThrowsAsync(new Exception()); var controller = new GroupsController(_dbServiceFactoryMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.GetAvailableGroupDatesAsync(); await result.Should().ThrowExactlyAsync <Exception>(); }
public async Task GetAvailableGroupDatesAsync__Sightseeing_info_not_found__Should_return_200OK_response_with_empty_IEnumerable() { _infoDbServiceMock.Setup(x => x.GetAllAsync()).ReturnsAsync(Enumerable.Empty <VisitInfo>()); _groupDbServiceMock.Setup(x => x.GetByAsync(It.IsAny <Expression <Func <SightseeingGroup, bool> > >())).ReturnsAsync(new SightseeingGroup[] { _validSightseeingGroup }.AsEnumerable()); var controller = new GroupsController(_dbServiceFactoryMock.Object, _logger, _mapperMock.Object); var result = await controller.GetAvailableGroupDatesAsync(); (result as ObjectResult).StatusCode.Should().Be(200); (((result as ObjectResult).Value as ResponseWrapper).Data as IEnumerable <GroupInfo>).Should().BeEmpty(); }
public async Task GetAvailableGroupDatesAsync__An_internal_error_reffered_to_the_database_occurred__Should_throw_InternalDbServiceException() { // Example of these errors: database does not exist, table does not exist etc. _groupDbServiceMock.Setup(x => x.GetByAsync(It.IsAny <Expression <Func <SightseeingGroup, bool> > >())).ThrowsAsync(new InternalDbServiceException()); _infoDbServiceMock.Setup(x => x.GetAllAsync()).ThrowsAsync(new InternalDbServiceException()); var controller = new GroupsController(_dbServiceFactoryMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.GetAvailableGroupDatesAsync(); await result.Should().ThrowExactlyAsync <InternalDbServiceException>(); }
public async Task GetAvailableGroupDatesAsync__At_least_one_element_found__Should_return_200OK_response_with_distinct_groups() { _infoDbServiceMock.Setup(x => x.GetAllAsync()).ReturnsAsync(new VisitInfo[] { _info }.AsEnumerable()); _groupDbServiceMock.Setup(x => x.GetByAsync(It.IsAny <Expression <Func <SightseeingGroup, bool> > >())).ReturnsAsync(new SightseeingGroup[] { _validSightseeingGroup }.AsEnumerable()); var controller = new GroupsController(_dbServiceFactoryMock.Object, _logger, _mapperMock.Object); var result = await controller.GetAvailableGroupDatesAsync(); (result as ObjectResult).StatusCode.Should().Be(200); var resultData = ((result as ObjectResult).Value as ResponseWrapper).Data as IEnumerable <GroupInfo>; // Each group should be different each other. resultData.ToList().Distinct().Count().Should().Be(resultData.Count()); }
public async Task GetAvailableGroupDatesAsync__There_is_group_without_available_places__Returned_IEnumerable_should_not_contain_date_of_this_group() { _infoDbServiceMock.Setup(x => x.GetAllAsync()).ReturnsAsync(new VisitInfo[] { _info }.AsEnumerable()); var notAvailableGroup = new SightseeingGroup { Id = "2", SightseeingDate = DateTime.Now.AddDays(1), MaxGroupSize = 1, Tickets = new Ticket[] { new Ticket { Id = "only_for_this_test" } } }; _groupDbServiceMock.Setup(x => x.GetByAsync(It.IsAny <Expression <Func <SightseeingGroup, bool> > >())) .ReturnsAsync(new SightseeingGroup[] { _validSightseeingGroup, notAvailableGroup }.AsEnumerable()); var controller = new GroupsController(_dbServiceFactoryMock.Object, _logger, _mapperMock.Object); var result = await controller.GetAvailableGroupDatesAsync(); (result as ObjectResult).StatusCode.Should().Be(200); (((result as ObjectResult).Value as ResponseWrapper).Data as IEnumerable <GroupInfo>).Any(x => x.SightseeingDate == notAvailableGroup.SightseeingDate).Should().BeFalse(); }