public void Details_ReturnTheCorrectDefaultView()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            var fakeViewMapper = new Mock<IViewMapper>();

            var sut = new AdminController(fakePostRepository.Object, fakeViewMapper.Object);
            var viewResult = sut.Details(1) as ViewResult;

            Assert.AreEqual(string.Empty, viewResult.ViewName);
        }
        public void Details_IfPostFoundIsNull_ReturnHttpNotFound()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            fakePostRepository.Setup(x => x.Find(It.IsAny<int>())).Returns(()=> null);
            var fakeViewMapper = new Mock<IViewMapper>();

            var sut = new AdminController(fakePostRepository.Object, fakeViewMapper.Object);
            var viewResult = sut.Details(1) as ViewResult;

            Assert.AreEqual(string.Empty, viewResult.ViewName);
        }
        public void Create_ReturnTheCorrectModelType()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            var fakeViewMapper = new Mock<IViewMapper>();

            var sut = new AdminController(fakePostRepository.Object, fakeViewMapper.Object);

            var model = sut.Create().Model as BlogPostViewModel;

            Assert.IsInstanceOf(typeof(BlogPostViewModel), model);
        }
        public void Create_ReturnTheCorrectView()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            var fakeViewMapper = new Mock<IViewMapper>();

            var sut = new AdminController(fakePostRepository.Object, fakeViewMapper.Object);

            string expected = string.Empty;
            string actual = sut.Create().ViewName;

            Assert.AreEqual(expected, actual);
        }
        public void Details_SetIdParamToDefaultValueOfOne_IfParamNotSpecified()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            fakePostRepository.Setup(x => x.All).Returns(Mother.GetTenPosts_With_1_Comment_PerPost());
            var fakeViewMapper = new Mock<IViewMapper>();

            var sut = new AdminController(fakePostRepository.Object, fakeViewMapper.Object);
            sut.Details();

            fakeViewMapper.Verify(x => x.MapIndexViewModel(It.IsAny<List<Post>>(), It.Is<int>(i => i == 29), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>(), ""));
        }
        public void Index_SetPageSizeToDefaultOfOne_IfValueGivenIsNull()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            fakePostRepository.Setup(x => x.All).Returns(Mother.GetTenPosts_With_1_Comment_PerPost());

            var fakeViewMapper = new Mock<IViewMapper>();
            var sut = new AdminController(fakePostRepository.Object, fakeViewMapper.Object);

            sut.Index(null);

            fakeViewMapper.Verify(x => x.MapIndexViewModel(It.IsAny<List<Post>>(), It.Is<int>(i => i ==3), It.IsAny<int>(), "Index", false, ""));
        }
        public void Index_SetPageNumberParaToDefaultOfOne_IfParamIsNull()
        {
            List<Post> posts = Mother.GetTenPosts_No_Categories_NoComments_No_Tags();
            var fakePostRepository = new Mock<IPostRepository>();
            fakePostRepository.Setup(x => x.All).Returns(posts);
            var fakeViewMapper = new Mock<IViewMapper>();
            fakeViewMapper.Setup(x => x.MapIndexViewModel(posts, 1, It.IsAny<int>(), "Index", false, ""))
                          .Returns(() => new BlogPostViewModel());

            var sut = new AdminController(fakePostRepository.Object, fakeViewMapper.Object);
            sut.Index(1);

            fakeViewMapper.Verify();
        }
        public void Index_ReturnTheCorrectView()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            var fakeViewMapper = new Mock<IViewMapper>();

            var sut = new AdminController(fakePostRepository.Object, fakeViewMapper.Object);
            ViewResult  viewResult = sut.Index(1);

            Assert.AreEqual(string.Empty, viewResult.ViewName);
        }
        public void Index_ReturnTheCorrectModelType()
        {
            List<Post> posts = Mother.GetTenPosts_No_Categories_NoComments_No_Tags();
            var fakePostRepository = new Mock<IPostRepository>();
            fakePostRepository.Setup(x => x.All).Returns(posts);
            var fakeViewMapper = new Mock<IViewMapper>();
            fakeViewMapper.Setup(x => x.MapIndexViewModel(posts, 1, It.IsAny<int>(), "Index", false, "")).Returns(()=> new BlogPostViewModel());

            var sut = new AdminController(fakePostRepository.Object, fakeViewMapper.Object);
            var viewResult = sut.Index(1);
            var model = viewResult.Model as BlogPostViewModel;

            Assert.IsInstanceOf(typeof (BlogPostViewModel), model);
        }
        public void Index_CallProperty_All()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            var fakeViewMapper = new Mock<IViewMapper>();
            var sut = new AdminController(fakePostRepository.Object, fakeViewMapper.Object);

            sut.Index(1);

            fakePostRepository.Verify(x => x.All, Times.Once());
        }