public void AddCategoryPostShouldRedirectToCategoryList() { // Arrange _mockDocumentSession.Setup(o => o.Store(It.IsAny<Category>())).Verifiable("Category should be saved"); _mockDocumentSession.Setup(o=>o.SaveChanges()).Verifiable("Store should be saved"); var category = new CategoryModel { Description = "Category" }; // Act var sut = new CategoryController(_mockDocumentSession.Object); var result = sut.Add(category); // Assert Assert.That(result, Is.TypeOf<RedirectToRouteResult>()); }
public void AddCategoryPostShouldRequireADescription() { // Arrange const string description = "Category"; _mockDocumentSession.Setup(o => o.Store(It.Is<Category>( x=>x.Description==description ))).Verifiable("Category should be saved"); _mockDocumentSession.Setup(o=>o.SaveChanges()).Verifiable("Save the store"); var categoryModel = new CategoryModel { Description = description }; // Act var sut = new CategoryController(_mockDocumentSession.Object); var result = sut.Add(categoryModel); // Assert _mockDocumentSession.Verify(); }
public RedirectToRouteResult Add(CategoryModel category) { _session.Store(AutoMapper.Mapper.Map<CategoryModel, Category>(category)); _session.SaveChanges(); return RedirectToAction("Index"); }