Ejemplo n.º 1
0
        public void Index_Test()
        {
            var mockRepo = new Mock <DevCmsDb>();

            mockRepo.SetupDbSetMock(db => db.ContentTypes, GetContentTypeList());

            var model = new CreateContentTypeModel
            {
                Name       = "Test",
                Attributes = null
            };

            Assert.Equal(1, mockRepo.Object.ContentTypes.Count());

            var controller  = new ContentTypeController(mockRepo.Object);
            var result      = controller.Index(model);
            var viewResult  = Assert.IsType <ViewResult>(result);
            var resultModel = Assert.IsAssignableFrom <EditContentTypeModel>(
                viewResult.ViewData.Model);

            Assert.Equal("Edit", viewResult.ViewName);

            mockRepo.Verify(db => db.SaveChanges(), Times.Once());
            Assert.Equal(2, mockRepo.Object.ContentTypes.Count());

            var newEntity = mockRepo.Object.ContentTypes.Last();

            Assert.Equal("Test", newEntity.Name);
            Assert.Empty(resultModel.Attrs);
        }
Ejemplo n.º 2
0
        public void Index_Test_InvalidModel()
        {
            var mockRepo = new Mock <DevCmsDb>();

            mockRepo.SetupDbSetMock(db => db.ContentTypes, GetContentTypeList());

            Assert.Equal(1, mockRepo.Object.ContentTypes.Count());

            var model = new CreateContentTypeModel();

            var controller = new ContentTypeController(mockRepo.Object);

            controller.ModelState.AddModelError("Name", "Required");
            var result     = controller.Index(model);
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.IsAssignableFrom <CreateContentTypeModel>(viewResult.ViewData.Model);

            mockRepo.Verify(db => db.SaveChanges(), Times.Never);
            Assert.Equal(1, mockRepo.Object.ContentTypes.Count());
        }