public void TestCreateReturnView() { var controller = new ProductoController(null, null); var view = controller.Create(); Assert.IsInstanceOf(typeof(ViewResult), view); Assert.AreEqual("Create", view.ViewName); }
public void TestIndexCallAllMethodFromRepository() { var mock = new Mock<InterfaceProducto>(); mock.Setup(o => o.All()).Returns(new List<Producto>()); var controller = new ProductoController(mock.Object, null); controller.Index(); mock.Verify(o => o.All(), Times.Exactly(1)); }
public void TestIndexReturnView() { var mock = new Mock<InterfaceProducto>(); mock.Setup(o => o.All()).Returns(new List<Producto>()); var controller = new ProductoController(mock.Object); var view = controller.Index(); Assert.IsInstanceOf(typeof(ViewResult), view); Assert.AreEqual("Inicio", view.ViewName); Assert.IsInstanceOf(typeof(List<Producto>), view.Model); }
public void TestIndexReturnView() { var mock = new Mock<InterfaceProducto>(); var query = ""; DateTime? date = null; mock.Setup(o => o.ByQueryAll(query, date)).Returns(new List<Producto>()); var controller = new ProductoController(mock.Object, null); var view = controller.Index(query, date); Assert.IsInstanceOf(typeof(ViewResult), view); Assert.AreEqual("Inicio", view.ViewName); Assert.IsInstanceOf(typeof(List<Producto>), view.Model); }
public void TestPostCreateCallStoreMethodFromRepository() { var producto = new Producto(); var repositoryMock = new Mock<InterfaceProducto>(); var validatorMock = new Mock<ProductoValidator>(); validatorMock.Setup(o => o.Pass(producto)).Returns(true); repositoryMock.Setup(o => o.Store(producto)); var controller = new ProductoController(repositoryMock.Object, validatorMock.Object); var redirect = controller.Create(producto, null); repositoryMock.Verify(o => o.Store(producto), Times.Once()); }
public void TestPostCreateOKReturnRedirect() { var producto = new Producto(); var repositoryMock = new Mock<InterfaceProducto>(); repositoryMock.Setup(o => o.Store(new Producto())); var validatorMock = new Mock<ProductoValidator>(); validatorMock.Setup(o => o.Pass(producto)).Returns(true); var controller = new ProductoController(repositoryMock.Object, validatorMock.Object); var redirect = (RedirectToRouteResult)controller.Create(producto, null); Assert.IsInstanceOf(typeof(RedirectToRouteResult), redirect); }
public void TestPostCreateReturnViewWithErrorsWhenValidationFail() { var producto = new Producto { }; var mock = new Mock<ProductoValidator>(); mock.Setup(o => o.Pass(producto)).Returns(false); var controller = new ProductoController(null, mock.Object); var view = controller.Create(producto, null); Assert.IsInstanceOf(typeof(ViewResult), view); }