コード例 #1
0
ファイル: CategoryTests.cs プロジェクト: mattdotmatt/dogalog
        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>());
        }
コード例 #2
0
ファイル: CategoryTests.cs プロジェクト: mattdotmatt/dogalog
        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();
        }
コード例 #3
0
 public RedirectToRouteResult Add(CategoryModel category)
 {
     _session.Store(AutoMapper.Mapper.Map<CategoryModel, Category>(category));
     _session.SaveChanges();
     return RedirectToAction("Index");
 }