public void Index_PageGet_ReturnsFeaturedOnlyArticlesInThePast()
        {
            //Arrange
            var featuredNews = new FeaturedNews();

            var notFeatured = new NewsArticle();

            var featuredInThePast = new NewsArticle();
            featuredInThePast.Featured = true;
            featuredInThePast.Date = DateTime.Now.AddDays(-1);

            var featuredInTheFuture = new NewsArticle();
            featuredInTheFuture.Featured = true;
            featuredInTheFuture.Date = DateTime.Now.AddDays(+1);

            featuredNews.NewsArticles = new[] { notFeatured, featuredInThePast, featuredInTheFuture };

            var context = Substitute.For<ISitecoreContext>();
            context.GetCurrentItem<FeaturedNews>().Returns(featuredNews);

            var controller = new StubFeaturedNewsController(context, null);

            //Act
            var result = controller.Index() as ViewResult;

            //Assert
            var model = result.Model as IndexGet;

            Assert.IsNotNull(result);
            Assert.AreEqual(featuredNews, model.FeaturedNews);
            Assert.AreEqual(featuredInThePast, model.Articles.First());
            Assert.AreEqual(1, model.Articles.Count());
        }
        protected virtual int DoCompare(NewsArticle item1, NewsArticle item2)
        {
            if ( (item1.Featured && item2.Featured) || (!item1.Featured && !item2.Featured))
            {
                return item1.Date.CompareTo(item2.Date);
            }
            if (item1.Featured && !item2.Featured)
                return -1;

            if (!item1.Featured && item2.Featured)
                return 1;

            return 0;
        }
        public void DoCompare_NotFeatureVsFeatured_ReturnsMinusOne()
        {
            //Arrange
            var featured = new NewsArticle();
            featured.Featured = true;
            var notFeatured = new NewsArticle();

            var comparer = new StubFeaturedNewsComparer();

            //Act
            var result = comparer.DoCompare(notFeatured, featured);

            //Assert
            Assert.AreEqual(1, result);
        }
 public int DoCompare(NewsArticle item1, NewsArticle item2)
 {
     return base.DoCompare(item1, item2);
 }
        public void Index_PageGet_ReturnsViewModelWithPageAndArticles()
        {
            //Arrange
            var featuredNews = new FeaturedNews();

            var article = new NewsArticle();
            article.Featured = true;

            featuredNews.NewsArticles = new []{article};

            var context = Substitute.For<ISitecoreContext>();
            context.GetCurrentItem<FeaturedNews>().Returns(featuredNews);

            var controller = new StubFeaturedNewsController(context, null);

            //Act
            var result = controller.Index() as ViewResult;

            //Assert
            var model = result.Model as IndexGet;

            Assert.IsNotNull(result);
            Assert.AreEqual(featuredNews, model.FeaturedNews);
            Assert.AreEqual(article, model.Articles.First());
            Assert.AreEqual(1, model.Articles.Count());
        }