public async Task UpdateInfoAsync__Argument_id_and_id_property_in_element_to_be_updated_mismatches__Should_return_400BadRequest_response() { var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object); var infoDto = _infoDtos[0]; string id = infoDto.Id + "_mismatched_id"; var result = await controller.UpdateInfoAsync(id, infoDto); (result as ObjectResult).StatusCode.Should().Be(400); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull(); }
public async Task UpdateInfoAsync__An_unexpected_internal_error_occurred__Should_throw_Exception() { _infoDbServiceMock.Setup(x => x.UpdateAsync(It.IsAny <VisitInfo>())).ThrowsAsync(new Exception()); _infoDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsAny <VisitInfo>())).ThrowsAsync(new Exception()); _mapperMock.Setup(x => x.Map <VisitInfo>(It.IsNotNull <VisitInfoDto>())).Returns(_info); var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.UpdateInfoAsync(_infoDto.Id, _infoDto); await result.Should().ThrowExactlyAsync <Exception>(); }
public async Task UpdateInfoAsync__Argument_id_is_null_or_empty__Should_return_400BadRequest_response([Values(null, "")] string id) { var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object); var infoDto = CreateInfoDto(CreateModel.CreateInfo()); infoDto.Id = id; var result = await controller.UpdateInfoAsync(id, infoDto); (result as ObjectResult).StatusCode.Should().Be(400); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull(); }
public async Task UpdateInfoAsync__An_internal_error_reffered_to_the_database_occurred__Should_throw_InternalDbServiceException() { // Example of these errors: database does not exist, table does not exist etc. _infoDbServiceMock.Setup(x => x.UpdateAsync(It.IsAny <VisitInfo>())).ThrowsAsync(new InternalDbServiceException()); _infoDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsAny <VisitInfo>())).ThrowsAsync(new InternalDbServiceException()); _mapperMock.Setup(x => x.Map <VisitInfo>(It.IsNotNull <VisitInfoDto>())).Returns(_info); var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.UpdateInfoAsync(_infoDto.Id, _infoDto); await result.Should().ThrowExactlyAsync <InternalDbServiceException>(); }
public async Task UpdateInfoAsync__Element_not_found__Should_return_404NotFound_response_with_error() { _mapperMock.Setup(x => x.Map <VisitInfo>(It.IsNotNull <VisitInfoDto>())).Returns(_info); _mapperMock.Setup(x => x.Map <VisitInfoDto>(It.IsNotNull <VisitInfo>())).Returns(_infoDto); _infoDbServiceMock.Setup(x => x.UpdateAsync(It.IsNotNull <VisitInfo>())).ThrowsAsync(new InvalidOperationException()); _infoDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsNotNull <VisitInfo>())).ThrowsAsync(new InvalidOperationException()); var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.UpdateInfoAsync(_infoDto.Id, _infoDto); (result as ObjectResult).StatusCode.Should().Be(404); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeEquivalentTo(new ApiError()); }
public async Task UpdateInfoAsync__Update_succeeded__Should_return_200OK_response_with_updated_element() { _mapperMock.Setup(x => x.Map <VisitInfo>(It.IsNotNull <VisitInfoDto>())).Returns(_info); _mapperMock.Setup(x => x.Map <VisitInfoDto>(It.IsNotNull <VisitInfo>())).Returns(_infoDto); _infoDbServiceMock.Setup(x => x.UpdateAsync(It.IsNotNull <VisitInfo>())).ReturnsAsync(_info); _infoDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsNotNull <VisitInfo>())).ReturnsAsync(_info); _mapperMock.Setup(x => x.Map <VisitInfoDto>(It.IsNotNull <VisitInfo>())).Returns(_infoDto); var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.UpdateInfoAsync(_infoDto.Id, _infoDto); (result as ObjectResult).StatusCode.Should().Be(200); ((result as ObjectResult).Value as ResponseWrapper).Data.Should().BeEquivalentTo(_infoDto); }