public async Task AddVisitsTicketTariffAsync__Already_there_is_the_same_element_in_database__Should_return_400BadRequest_response() { var ticketTariffs = new TicketTariff[] { new TicketTariff { Id = "1", DefaultPrice = 30 } }; var parentVisitTariff = new VisitTariff { Id = _visitTariffId, UpdatedAt = new DateTime(2019, 1, 1), Name = "sample parent visit tariff name", TicketTariffs = ticketTariffs }; var ticketTariffDto = CreateTicketTariffDto(ticketTariffs[0]); _mapperMock.Setup(x => x.Map <TicketTariff>(ticketTariffDto)).Returns(ticketTariffs[0]); _visitTariffDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ReturnsAsync(parentVisitTariff); _ticketTariffDbServiceMock.Setup(x => x.RestrictedAddAsync(It.IsNotNull <TicketTariff>())).ThrowsAsync(new InvalidOperationException()); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.AddVisitsTicketTariffAsync(_visitTariffId, ticketTariffDto); (result as ObjectResult).StatusCode.Should().Be(400); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeEquivalentTo(new ApiError()); }
public async Task UpdateVisitsTicketTariffAsync__Argument_id_and_id_property_in_element_to_be_updated_mismatches__Should_return_400BadRequest_response() { var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.UpdateVisitsTicketTariffAsync(_visitTariffId, "100", _ticketTariffDtos[0]); (result as ObjectResult).StatusCode.Should().Be(400); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull(); }
public async Task UpdateVisitsTicketTariffAsync__Argument_id_is_null_or_empty__Should_return_400BadRequest_response(string visitTariffId, string ticketTariffId) { var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.UpdateVisitsTicketTariffAsync(visitTariffId, ticketTariffId, _ticketTariffDtos[0]); (result as ObjectResult).StatusCode.Should().Be(400); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull(); }
public async Task GetAllTicketTariffAsync__An_unexpected_internal_error_occurred__Should_throw_Exception() { _ticketTariffDbServiceMock.Setup(x => x.GetAllAsync()).ThrowsAsync(new Exception()); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.GetAllTicketTariffsAsync(); await result.Should().ThrowExactlyAsync <Exception>(); }
public async Task UpdateVisitsTicketTariffAsync__An_unexpected_internal_error_occurred__Should_throw_Exception() { _visitTariffDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ThrowsAsync(new Exception()); _ticketTariffDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsAny <TicketTariff>())).ThrowsAsync(new Exception()); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.UpdateVisitsTicketTariffAsync(_visitTariffId, "4", _ticketTariffDtos[0]); await result.Should().ThrowExactlyAsync <Exception>(); }
public async Task AddVisitsTicketTariffAsync__Visit_tariff_not_found__Should_return_404NotFound_response_with_error() { _visitTariffDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ThrowsAsync(new InvalidOperationException()); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.AddVisitsTicketTariffAsync(_visitTariffId, _ticketTariffDtos[0]); (result as ObjectResult).StatusCode.Should().Be(404); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeEquivalentTo(new ApiError()); }
public async Task GetAllTicketTariffAsync__At_least_one_element_found__Should_return_200OK_response_with_not_empty_IEnumerable() { _ticketTariffDbServiceMock.Setup(x => x.GetAllAsync()).ReturnsAsync(_ticketTariffs); _mapperMock.Setup(x => x.Map <IEnumerable <TicketTariffDto> >(It.IsNotNull <IEnumerable <TicketTariff> >())).Returns(_ticketTariffDtos.AsEnumerable()); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.GetAllTicketTariffsAsync(); (result as ObjectResult).StatusCode.Should().Be(200); (((result as ObjectResult).Value as ResponseWrapper).Data as IEnumerable <TicketTariffDto>).Should().NotBeEmpty(); }
public async Task GetAllTicketTariffAsync__An_internal_error_reffered_to_the_database_occurred__Should_throw_InternalDbServiceException() { // Example of these errors: database does not exist, table does not exist etc. _ticketTariffDbServiceMock.Setup(x => x.GetAllAsync()).ThrowsAsync(new InternalDbServiceException()); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.GetAllTicketTariffsAsync(); await result.Should().ThrowExactlyAsync <InternalDbServiceException>(); }
public async Task GetVisitsTicketTariffAsync__Argument_id_is_null_or_empty__Should_return_400BadRequest_response(string visitTariffId, string ticketTariffId) { _ticketTariffDbServiceMock.Setup(x => x.GetAsync(ticketTariffId)).ThrowsAsync(new ArgumentException()); _visitTariffDbServiceMock.Setup(x => x.GetAsync(visitTariffId)).ThrowsAsync(new ArgumentException()); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.GetVisitsTicketTariffAsync(visitTariffId, ticketTariffId); (result as ObjectResult).StatusCode.Should().Be(400); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull(); }
public async Task GetVisitsTicketTariffAsync__visit_tariff_found_but_searching_ticket_tariff_does_not_belong_to_this__Should_return_404NotFound_response_with_error() { _visitTariffDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ReturnsAsync(_parentVisitTariff); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); // VisitTariff found, but TicketTariff with id = 111 doesn't belong to this. But may exists in db. var result = await controller.GetVisitsTicketTariffAsync(_visitTariffId, "111"); (result as ObjectResult).StatusCode.Should().Be(404); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull(); }
public async Task UpdateVisitsTicketTariffAsync__An_internal_error_reffered_to_the_database_occurred__Should_throw_InternalDbServiceException() { // Example of these errors: database does not exist, table does not exist etc. _visitTariffDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ThrowsAsync(new InternalDbServiceException()); _ticketTariffDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsAny <TicketTariff>())).ThrowsAsync(new InternalDbServiceException()); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.UpdateVisitsTicketTariffAsync(_visitTariffId, "4", _ticketTariffDtos[0]); await result.Should().ThrowExactlyAsync <InternalDbServiceException>(); }
public async Task AddVisitsTicketTariffAsync__Add_succesful__Should_return_201Created_response_and_add_ticket_tariff_to_parent() { // If in db doesn't exist the same TicketTariff as the one to be added then this tariff should be add to the parent VisitTariff and 201 Created response should be return. var ticketTariffDto = CreateTicketTariffDto(_ticketTariffs[0]); _mapperMock.Setup(x => x.Map <TicketTariff>(ticketTariffDto)).Returns(_ticketTariffs[0]); _mapperMock.Setup(x => x.Map <TicketTariffDto>(_ticketTariffs[0])).Returns(ticketTariffDto); _visitTariffDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ReturnsAsync(_parentVisitTariff); _ticketTariffDbServiceMock.Setup(x => x.RestrictedAddAsync(_ticketTariffs[0])).ReturnsAsync(_ticketTariffs[0]); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.AddVisitsTicketTariffAsync(_visitTariffId, ticketTariffDto); (result as ObjectResult).StatusCode.Should().Be(201); ((result as ObjectResult).Value as ResponseWrapper).Data.Should().BeEquivalentTo(ticketTariffDto); }
public async Task GetVisitsTicketTariffsAsync__visit_tariff_does_not_contain_any_ticket_tariffs__Should_return_200OK_response_with_empty_IEnumerable() { // Create parent VisitTariff with empty TicketTariffs. var parentvisitTariff = _parentVisitTariff.Clone() as VisitTariff; parentvisitTariff.TicketTariffs = Enumerable.Empty <TicketTariff>().ToArray(); _visitTariffDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ReturnsAsync(parentvisitTariff); _mapperMock.Setup(x => x.Map <IEnumerable <TicketTariffDto> >(It.IsNotNull <IEnumerable <TicketTariff> >())).Returns(Enumerable.Empty <TicketTariffDto>()); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.GetVisitsTicketTariffsAsync(_visitTariffId); (result as ObjectResult).StatusCode.Should().Be(200); (((result as ObjectResult).Value as ResponseWrapper).Data as IEnumerable <TicketTariffDto>).Should().BeEmpty(); }
public async Task UpdateVisitsTicketTariffAsync__Update_succeeded__Should_return_200OK_response_with_updated_element() { var validTicketTariff = new TicketTariff { Id = "4", Description = "Valid description updated" }; var validTicketTariffDto = CreateTicketTariffDto(validTicketTariff); _mapperMock.Setup(x => x.Map <TicketTariff>(It.IsNotNull <TicketTariffDto>())).Returns(validTicketTariff); _mapperMock.Setup(x => x.Map <TicketTariffDto>(It.IsNotNull <TicketTariff>())).Returns(validTicketTariffDto); _ticketTariffDbServiceMock.Setup(x => x.RestrictedUpdateAsync(validTicketTariff)).ReturnsAsync(validTicketTariff); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.UpdateVisitsTicketTariffAsync(_visitTariffId, "4", validTicketTariffDto); (result as ObjectResult).StatusCode.Should().Be(200); ((result as ObjectResult).Value as ResponseWrapper).Data.Should().BeEquivalentTo(validTicketTariffDto); }
public async Task GetVisitsTicketTariffAsync__Data_retrieve_succeeded__Should_return_200Ok_response_with_data() { var ticketTariffs = new TicketTariff[] { new TicketTariff { Id = "1", DefaultPrice = 30 } }; var parentVisitTariff = new VisitTariff { Id = _visitTariffId, UpdatedAt = new DateTime(2019, 1, 1), Name = "sample parent visit tariff name", TicketTariffs = ticketTariffs }; _ticketTariffDbServiceMock.Setup(x => x.RestrictedAddAsync(It.IsNotNull <TicketTariff>())).ReturnsAsync(ticketTariffs[0]); _visitTariffDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ReturnsAsync(parentVisitTariff); _mapperMock.Setup(x => x.Map <TicketTariffDto>(It.IsNotNull <TicketTariff>())).Returns(CreateTicketTariffDto(ticketTariffs[0])); var controller = new TicketTariffsController(_ticketTariffDbServiceMock.Object, _visitTariffDbServiceMock.Object, _logger, _mapperMock.Object); // Get first TicketTariff from _parentvisitTariff. var result = await controller.GetVisitsTicketTariffAsync(_visitTariffId, ticketTariffs[0].Id); (result as ObjectResult).StatusCode.Should().Be(200); ((result as ObjectResult).Value as ResponseWrapper).Data.Should().NotBeNull(); }