Example #1
0
        public async Task CanUpdateFeature_DoesNotExist()
        {
            const int id = 123;

            _featuresRepository.Setup(db => db.GetAsync(123)).Returns(Task.FromResult(default(Feature)));

            IActionResult actual = await _controller.UpdateFeatureAsync(id, _featureResource);

            _featuresRepository.Verify(db => db.GetAsync(id), Times.Once);
            var error = ControllerTestHelper.GetBadRequestError(actual);

            Assert.AreEqual("Feature with id = 123 does not exist!", error);
        }
Example #2
0
        public async Task CanDeleteUnexistingFeature()
        {
            const int featureId = 123;

            _featuresRepository.Setup(repo => repo.GetAsync(featureId)).ReturnsAsync(default(Feature));

            var actual = await _controller.DeleteAsync(featureId);

            _featuresRepository.Verify(repo => repo.GetAsync(featureId), Times.Once);
            var error = ControllerTestHelper.GetBadRequestError(actual);

            Assert.AreEqual("Feature with id = 123 does not exist!", error);
        }
Example #3
0
        public async Task CanDeleteExistingFeatureIfErrorOccured()
        {
            const int featureId = 123;
            Feature   Feature   = new Feature()
            {
                Id = featureId, Name = "Audi"
            };

            _featuresRepository.Setup(repo => repo.GetAsync(featureId)).ReturnsAsync(Feature);
            _featuresRepository.Setup(repo => repo.Delete(Feature)).Throws(new Exception("Sql exception occured"));

            var actual = await _controller.DeleteAsync(featureId);

            _featuresRepository.Verify(repo => repo.GetAsync(featureId), Times.Once);
            _featuresRepository.Verify(repo => repo.Delete(Feature), Times.Once);
            var error = ControllerTestHelper.GetBadRequestError(actual);

            Assert.AreEqual($"Cannot delete Feature with id = 123 : \"Sql exception occured\"", error);
        }