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 CanGetFeatureIfDoesNotExist()
        {
            const int featureId = 123;

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

            var actual = await _controller.GetFeatureAsync(featureId);

            _featuresRepository.Verify(repo => repo.GetAsync(featureId), Times.Once);
            _mapper.Verify(m => m.Map <Feature, KeyValuePairResource>(_features.First()), Times.Never);

            var error = ControllerTestHelper.GetNotFoundError(actual);

            Assert.AreEqual("Feature with id = 123 does not exist!", error);
        }
Example #4
0
        public async Task CanValidateFeature_UpdateFeature_RequiredFielsAreMissing()
        {
            FeatureResource FeatureResource = new FeatureResource {
                Name = null
            };

            _controller.ModelState.AddModelError("Name", "Name field is required.");

            IActionResult actual = await _controller.UpdateFeatureAsync(It.IsAny <int>(), FeatureResource);

            _featuresRepository.Verify(db => db.GetAsync(It.IsAny <int>()), Times.Never);
            var errors = ControllerTestHelper.GetBadRequestErrors(actual);

            Assert.AreEqual(new[] { "Name field is required." }, errors["Name"]);
        }
Example #5
0
        public async Task CanGetMakeIfDoesNotExist()
        {
            const int makeId = 123;

            _makesRepository.Setup(repo => repo.GetAsync(makeId)).ReturnsAsync(default(Make));

            var actual = await _controller.GetMakeAsync(makeId);

            _makesRepository.Verify(repo => repo.GetAsync(makeId), Times.Once);
            _mapper.Verify(m => m.Map <Make, MakeResource>(_makes.First()), Times.Never);

            var error = ControllerTestHelper.GetNotFoundError(actual);

            Assert.AreEqual("Make with id = 123 does not exist!", error);
        }
Example #6
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);
        }