public void MapReturnsPostViewModel()
        {
            // Arrange
            DateTime referenceDate = DateTime.Now;
            Author author = new Author {AuthorID = 1, Name = "Fred"};
            Category category = new Category {CategoryID = 1, Name = "Cat"};
            Guid externalIdentifier = Guid.NewGuid();
            Post post = new Post
                            {
                                Author = author,
                                AuthorID = 1,
                                Body = "Some text",
                                Categories = new List<Category> {category},
                                ExternalIdentifier = externalIdentifier,
                                PostID = 2,
                                PostedAt = referenceDate,
                                Subject = "A subject"
                            };
            _categoryMapper.Stub(x => x.Map(category)).Return(new CategoryViewModel());
            _markdownConverter.Stub(x => x.ToHtml("Some text")).Return("converted");
            PostToPostViewModelMapper mapper = new PostToPostViewModelMapper(_categoryMapper, _markdownConverter);

            // Act
            PostViewModel result = mapper.Map(post);

            // Assert
            Assert.That(result.AuthorName, Is.EqualTo("Fred"));
            Assert.That(result.AuthorId, Is.EqualTo(1));
            Assert.That(result.BodyAsHtml, Is.EqualTo("converted"));
            Assert.That(result.Categories.Count, Is.EqualTo(1));
            Assert.That(result.ExternalIdentifier, Is.EqualTo(externalIdentifier));
            Assert.That(result.PostID, Is.EqualTo(2));
            Assert.That(result.PostedAt, Is.EqualTo(referenceDate));
            Assert.That(result.Subject, Is.EqualTo("A subject"));
        }
        public void Setup()
        {
            _category1 = new Category {CategoryID = 1};
            _category2 = new Category {CategoryID = 2};
            _post1 = new Post { PostID = 1, PostedAt = DateTime.Now.Subtract(TimeSpan.FromDays(50)), Categories = new Collection<Category>{_category1}};
            _post2 = new Post { PostID = 2,  PostedAt = DateTime.Now, Categories = new Collection<Category>{ _category2}};
            List<Post> posts = new List<Post> { _post1, _post2 };

            _unitOfWorkFactory = MockRepository.GenerateStub<IUnitOfWorkFactory>();
            _unitOfWork = MockRepository.GenerateStub<IUnitOfWork>();
            _postRepository = MockRepository.GenerateStub<IRepository<Post>>();
            _mapper = MockRepository.GenerateStub<IMapper<Post, PostViewModel>>();

            _unitOfWorkFactory.Stub(x => x.Create()).Return(_unitOfWork);
            _unitOfWork.Stub(x => x.GetRepository<Post>()).Return(_postRepository);
            _unitOfWork.Stub(x => x.Execute(Arg<Action>.Is.Anything)).WhenCalled(x => ((Action)x.Arguments[0])());

            _postRepository.Stub(y => y.AllIncluding(Arg<Expression<Func<Post, object>>>.Is.Anything)).Return(posts.AsQueryable());
        }