public void WhenSelectedViewChanged_ArticlesInitilized()
        {
            //Prepare
            Mock<INewsService> mockedNewsService = new Mock<INewsService>();
            Article[] articles = new Article[] {
                new Article { ArticleType = ArticleTypes.Major, Keywords = new string[] { "Diablo" } },
                new Article { ArticleType = ArticleTypes.Notification, Keywords = new string[] { "Maintenance" } }
            };

            mockedNewsService.Setup(x => x.GetNewsAsync(It.Is<string[]>(keywords => keywords.Length > 0), It.IsAny<CancellationToken>())).Returns(Task.FromResult(articles));

            GameViewModel game = new GameViewModel(mockedNewsService.Object);
            game.BackgroundImage = "testimage";
            game.Keywords = new string[] { "Diablo", "Maintenance" };

            Mock<IGameService> mockedGameService = new Mock<IGameService>();
            mockedGameService.Setup(x => x.GetGames()).Returns(new GameViewModel[] { game }).Verifiable();

            GamesViewModel target = new GamesViewModel(mockedGameService.Object);

            //Act
            target.SelectedGameView = game;
            Thread.Sleep(3000);

            //Verify
            Assert.IsNotNull(game.MajorArticles);
            Assert.IsNotNull(game.MinorArticles);
        }
        public void ShouldSelectDataTemplate()
        {
            // Prepare
            ArticleTemplateSelector selector = new ArticleTemplateSelector();
            selector.MajorArticleTemplate = new DataTemplate("major");
            selector.MinorArticleTemplate = new DataTemplate("minor");
            selector.NotificationTemplate = new DataTemplate("notification");

            object majorArticle = new Article { ArticleType = ArticleTypes.Major };
            object minorArticle = new Article { ArticleType = ArticleTypes.Minor };
            object notificationArticle = new Article { ArticleType = ArticleTypes.Notification };
            object unknownArticle = new Article ();

            //Act
            DataTemplate majorTemplate = selector.SelectTemplate(majorArticle, null) as DataTemplate;
            DataTemplate minorTemplate = selector.SelectTemplate(minorArticle, null) as DataTemplate;
            DataTemplate notificationTemplate = selector.SelectTemplate(notificationArticle, null) as DataTemplate;
            DataTemplate unknownTemplate = selector.SelectTemplate(unknownArticle, null) as DataTemplate;

            //Verify
            Assert.AreEqual("major", majorTemplate.DataType);
            Assert.AreEqual("minor", minorTemplate.DataType);
            Assert.AreEqual("notification", notificationTemplate.DataType);
            Assert.IsNotNull(unknownTemplate.DataType);
        }
        public void WhenDisposed_ImageDisposed()
        {
            //Prepare
            Article target = new Article { Image = new Bitmap(10, 10) };

            //Act
            target.Dispose();

            //Verify
            Image image = target.Image;
        }
        public void WhenConstructed_IntializesValues()
        {
            //Act
            Article target = new Article
            {
                ArticleType = ArticleTypes.Major,
                Image = new Bitmap(10, 10),
                Content = "",
                Keywords = new string[] { "" },
                Title = ""
            };

            //Verify
            Assert.AreEqual(ArticleTypes.Major, target.ArticleType);
            Assert.AreEqual(string.Empty, target.Content);
            Assert.IsNotNull(target.Image);
            Assert.IsNotNull(target.Keywords);
            Assert.AreEqual(string.Empty, target.Title);
        }
        public void WhenArticlesInitialized_ArticlesSet()
        {
            //Prepare 
            Mock<INewsService> mockedNewsService = new Mock<INewsService>();
            Article[] articles = new Article[] { 
                new Article { ArticleType = ArticleTypes.Major, Keywords = new string[] { "Diablo" } },
                new Article { ArticleType = ArticleTypes.Notification, Keywords = new string[] { "Maintenance" } }
            };

            mockedNewsService.Setup(x => x.GetNews(It.Is<string[]>(keywords => keywords.Length > 0))).Returns(articles);

            BaseArticleViewModel target = new BaseArticleViewModel(mockedNewsService.Object);

            //Act
            target.InitializeArticles(new string[] { "Diablo", "Maintenance" });

            //Verify
            Assert.IsNotNull(target.MajorArticles);
            Assert.IsNotNull(target.MinorArticles);
            mockedNewsService.VerifyAll();
        }
        public async Task WhenArticlesInitializedAsync_ArticlesSet()
        {
            //Prepare 
            Mock<INewsService> mockedNewsService = new Mock<INewsService>();
            Article[] articles = new Article[] { 
                new Article { ArticleType = ArticleTypes.Major, Keywords = new string[] { "Diablo" } },
                new Article { ArticleType = ArticleTypes.Notification, Keywords = new string[] { "Maintenance" } }
            };

            mockedNewsService.Setup(x => x.GetNewsAsync(It.Is<string[]>(keywords => keywords.Length > 0), It.IsAny<CancellationToken>())).Returns(Task.FromResult(articles));

            BaseArticleViewModel target = new BaseArticleViewModel(mockedNewsService.Object);
            target.Keywords = new string[] { "Diablo", "Maintenance" };

            //Act
            await target.InitializeArticlesAsync();

            //Verify
            Assert.AreEqual(1, target.MajorArticles.Count);
            Assert.AreEqual(1, target.MinorArticles.Count);
        }