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);
        }
Ejemplo n.º 3
0
        private void DisposeArticles(object viewmodel)
        {
            BaseArticleViewModel articleviewmodel = viewmodel as BaseArticleViewModel;

            if (articleviewmodel != null)
            {
                articleviewmodel.DisposeArticles();
            }
        }
Ejemplo n.º 4
0
        private async Task GetArticlesAsync(object model)
        {
            BaseArticleViewModel viewmodel = model as BaseArticleViewModel;

            if (viewmodel != null)
            {
                await viewmodel.InitializeArticlesAsync();
            }
        }
        public void WhenPropertyChanged_PropertyIsUpdated()
        {
            //Prepare
            Mock <INewsService> mockedNewsService = new Mock <INewsService>();

            mockedNewsService.Setup(x => x.GetNews(It.Is <string[]>(keywords => keywords.Length > 0))).Returns(
                new Article[] { new Article() }).Verifiable();

            BaseArticleViewModel target = new BaseArticleViewModel(mockedNewsService.Object);

            bool majorArticlesChangedRaised = false;

            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "MajorArticles")
                {
                    majorArticlesChangedRaised = true;
                }
            };

            bool minorArticlesChangedRaised = false;

            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "MinorArticles")
                {
                    minorArticlesChangedRaised = true;
                }
            };

            bool stateChangedRaised = false;

            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "State")
                {
                    stateChangedRaised = true;
                }
            };

            //Act
            target.MajorArticles = new Article[] { new Article() };
            target.MinorArticles = new Article[] { new Article() };
            target.State         = "";

            //Verify
            Assert.IsTrue(majorArticlesChangedRaised);
            Assert.IsTrue(minorArticlesChangedRaised);
            Assert.IsTrue(stateChangedRaised);
        }
        public void WhenConstructed_IntializesValues()
        {
            //Prepare
            Mock <INewsService> mockedNewsService = new Mock <INewsService>();

            //Act
            BaseArticleViewModel target = new BaseArticleViewModel(mockedNewsService.Object);

            //Verify
            Assert.IsNull(target.Keywords);
            Assert.IsNull(target.MajorArticles);
            Assert.IsNull(target.MinorArticles);
            Assert.AreEqual(LoadingStates.NormalState, target.State);
            mockedNewsService.VerifyAll();
        }