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)); }
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)); }
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)); }
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"]); }