Ejemplo n.º 1
0
        public void PostAutomobile_ShouldReturnBadRequest_GivenNull()
        {
            var controller = new ElectricAutomobileController(_mockRepo.Object);

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

            IHttpActionResult result = controller.PostAutomobile(null);

            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
        }
Ejemplo n.º 2
0
        public void PostAutomobile_ShouldReturnExceptionRequest_GivenRepositoryThrows()
        {
            var controller = new ElectricAutomobileController(_mockRepo.Object);

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

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

            Assert.IsInstanceOfType(result, typeof(ExceptionResult));
        }
Ejemplo n.º 3
0
        public void PostAutomobile_ShouldCallRepository_InsertAutomobileWithCorrectVIN()
        {
            var _mockRepo  = new Mock <IElectricAutomobileRepository>();
            var controller = new ElectricAutomobileController(_mockRepo.Object);
            var newAuto    = new ElectricAutomobile()
            {
                VIN = "123"
            };

            controller.PostAutomobile(newAuto);

            _mockRepo.Verify(m => m.InsertAutomobile(newAuto));
        }
Ejemplo n.º 4
0
        public void PostAutomobile_ShouldSetLocationHeader()
        {
            var controller   = new ElectricAutomobileController(_mockRepo.Object);
            var expectedAuto = new ElectricAutomobile()
            {
                VIN = "1"
            };

            IHttpActionResult actionResult = controller.PostAutomobile(expectedAuto);
            var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult <ElectricAutomobile>;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual("DefaultApi", createdResult.RouteName);
            Assert.AreEqual(expectedAuto.VIN, createdResult.RouteValues["id"]);
        }