public void EditShouldWorkCorrectly() { var autoMapperConfig = new AutoMapperConfig(); autoMapperConfig.Execute(typeof(CategoriesController).Assembly); var categoriesServiceMock = new Mock<ICategoriesService>(); categoriesServiceMock.Setup(x => x.Find(It.IsAny<int>())) .Returns(this.categories[0]); var controller = new CategoriesController(categoriesServiceMock.Object); controller.WithCallTo(x => x.Edit(0)) .ShouldRenderView("Edit") .WithModel<CategoryEditModel>( model => Assert.AreEqual(model.Id, this.categories[0].Id)) .AndNoModelErrors(); }
public void IndexShouldWorkCorrectly() { var autoMapperConfig = new AutoMapperConfig(); autoMapperConfig.Execute(typeof(CategoriesController).Assembly); var categoriesServiceMock = new Mock<ICategoriesService>(); categoriesServiceMock.Setup(x => x.GetAll()) .Returns(this.categories.AsQueryable()); var controller = new CategoriesController(categoriesServiceMock.Object); controller.WithCallTo(x => x.Index()) .ShouldRenderView("Index") .WithModel<IEnumerable<CategoriesViewModel>>( model => Assert .AreEqual(model.First().Id, this.categories[0].Id)) .AndNoModelErrors(); }