public void Should_PostFeature() { Feature testFeature = new Feature { Id = 1, Title = "Title", Name = "Feature1", Detail = "Feature Details", Link = "www.something.com", Image = "Image Data", Order = 1 }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.Features.Create(testFeature)).Returns(true); FeaturesController controller = new FeaturesController(mock.Object); var features = controller.PostFeature(testFeature); Assert.IsType <CreatedAtActionResult>(features); }
public void ShouldNot_PostFeature_ModelStateError() { Feature testFeature = new Feature { Id = 1, Title = "Title", Name = "Feature1", Detail = "Feature Details", Link = "www.something.com", Image = "Image Data", Order = 1 }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.Features.Create(testFeature)).Returns(true); mock.Setup(f => f.Features.GetById(1)).Returns(testFeature); FeaturesController controller = new FeaturesController(mock.Object); controller.ModelState.AddModelError("TestError", "Error"); var features = controller.PostFeature(testFeature); Assert.IsType <BadRequestObjectResult>(features); }