예제 #1
0
        public void PostAutomobile_ShouldReturnBadRequest_GivenNull()
        {
            var controller = new GasAutomobileController(_mockRepo.Object);

            _mockRepo.Setup(a => a.InsertAutomobile(It.IsAny <GasAutomobile>())).Throws(new Exception("should not be called"));

            IHttpActionResult result = controller.PostAutomobile(null);

            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
        }
예제 #2
0
        public void PostAutomobile_ShouldReturnExceptionRequest_GivenRepositoryThrows()
        {
            var controller = new GasAutomobileController(_mockRepo.Object);

            _mockRepo.Setup(a => a.InsertAutomobile(It.IsAny <GasAutomobile>())).Throws(new Exception("boom"));

            IHttpActionResult result = controller.PostAutomobile(new GasAutomobile());

            Assert.IsInstanceOfType(result, typeof(ExceptionResult));
        }
예제 #3
0
        public void PostAutomobile_ShouldCallRepository_InsertAutomobileWithCorrectVIN()
        {
            var _mockRepo  = new Mock <IGasAutomobileRepository>();
            var controller = new GasAutomobileController(_mockRepo.Object);
            var newAuto    = new GasAutomobile()
            {
                VIN = "123"
            };

            controller.PostAutomobile(newAuto);

            _mockRepo.Verify(m => m.InsertAutomobile(newAuto));
        }
예제 #4
0
        public void PostAutomobile_ShouldReturnContentResult_GivenAutoSaved()
        {
            var expectedAuto = new GasAutomobile()
            {
                VIN = "1"
            };
            var controller = new GasAutomobileController(_mockRepo.Object);

            IHttpActionResult actionResult = controller.PostAutomobile(expectedAuto);
            var result = actionResult as NegotiatedContentResult <GasAutomobile>;

            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.Accepted, result.StatusCode);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(expectedAuto.VIN, result.Content.VIN);
        }