public void Patch_WhenCorrectIdGiven_ShouldReturnOkResult()
        {
            var testId    = 1;
            var viewModel = new UpdateTestViewCountViewModel
            {
                Id = testId
            };

            _mockRepo.Setup(x => x.IncrementTestViewCount(It.Is <int>(t => t == testId))).Returns(Task.FromResult(true));

            var result = _sut.UpdateTestViewCount(viewModel).Result as OkResult;

            Assert.IsNotNull(result);
        }
        public void Patch_WhenCorrectIdAndErrorDuringProcessing_ShouldReturnStatusCode500()
        {
            var testId    = 2;
            var viewModel = new UpdateTestViewCountViewModel
            {
                Id = testId
            };

            _mockRepo.Setup(x => x.IncrementTestViewCount(testId)).Returns(Task.FromResult(false));

            var result = _sut.UpdateTestViewCount(viewModel).Result as StatusCodeResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.StatusCode, 500);
        }
        public async Task <IActionResult> UpdateTestViewCount([FromBody] UpdateTestViewCountViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(new BadRequestResult());
            }

            try
            {
                if (!await _repository.IncrementTestViewCount(viewModel.Id))
                {
                    throw new Exception($"Error during updating test ith id: {viewModel.Id}");
                }
                return(Ok());
            }
            catch (Exception e)
            {
                return(new StatusCodeResult(500));
            }
        }