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);
        }
Пример #2
0
        private async Task GetArticlesAsync(object model)
        {
            BaseArticleViewModel viewmodel = model as BaseArticleViewModel;

            if (viewmodel != null)
            {
                await viewmodel.InitializeArticlesAsync();
            }
        }