Пример #1
0
        public void TC1_GetNews_Datewise()
        {
            GoogleNewsSource GoogleNews = new GoogleNewsSource();
            var result = GoogleNews.GetNews(x => x.CreatedAt >= DateTime.UtcNow.AddDays(-1));

            Assert.NotNull(result);
        }
Пример #2
0
        public void TC3_Get_PoliticalNews()
        {
            GoogleNewsSource GoogleNews = new GoogleNewsSource();
            var result = GoogleNews.GetNews(x => x.Category.Name == "Political");

            Assert.NotNull(result);
        }
Пример #3
0
        public void TC2_Get_SportNews()
        {
            GoogleNewsSource GoogleNews = new GoogleNewsSource();
            var result = GoogleNews.GetNews(x => x.Category.Name == "Sports");

            Assert.NotNull(result);
        }
        public void TC1_GetPublishData()
        {
            var googleSource   = new GoogleNewsSource();
            var internalSource = new InternalNewsSource();
            var ptiSource      = new PressTrustOfIndiaNewsSource();

            var newsList = new List <News>()
            {
                new News {
                    Title       = "New 1",
                    Content     = "Content 1",
                    CreatedAt   = DateTime.UtcNow,
                    IsBreaking  = false,
                    Priority    = 0,
                    PublishedAt = DateTime.UtcNow,
                    Category    = new NewsCategory {
                        Id = 1, Name = "Sports", IsAdvertisement = true
                    }
                },
                new News {
                    Title       = "New 2",
                    Content     = "Content 2",
                    CreatedAt   = DateTime.UtcNow,
                    IsBreaking  = false,
                    Priority    = 0,
                    PublishedAt = DateTime.UtcNow,
                    Category    = new NewsCategory {
                        Id = 1, Name = "Sports", IsAdvertisement = true
                    }
                }
            };

            var pageNumber = 1;

            var publisher = new NewspaperPublisher(_mockNewsSourceRegistery.Object, _mockAppConfig.Object);

            _mockNewsSourceRegistery.Setup(x => x.Register(googleSource)).Returns(Task.CompletedTask);
            _mockNewsSourceRegistery.Setup(x => x.Register(internalSource)).Returns(Task.CompletedTask);
            _mockNewsSourceRegistery.Setup(x => x.Register(ptiSource)).Returns(Task.CompletedTask);

            _mockNewsSourceRegistery.Setup(x => x.GetAllRegisteredNews()).Returns(Task.FromResult <IEnumerable <News> >(newsList));


            var result = publisher.Publish(pageNumber);

            Assert.NotNull(result);
        }
        public async void TC4_GetAllRegisteredNews()
        {
            //Arrange
            INewsSource source = new InternalNewsSource();
            await newsSourceRegistery.Register(source);

            source = new GoogleNewsSource();
            await newsSourceRegistery.Register(source);

            source = new PressTrustOfIndiaNewsSource();
            await newsSourceRegistery.Register(source);

            //Act
            var result = newsSourceRegistery.GetAllRegisteredNews();

            //Assert
            Assert.NotNull(result);
        }
Пример #6
0
        static void Main(string[] args)
        {
            var newsSource = new GoogleNewsSource();
            var adSource   = new AdvertisementSource();
            var newsAgency = new MyNewsAgency(newsSource, adSource);

            //Example demoing push model of Observable pattern
            //The news source would publish/push this news to all it's subscribers
            newsSource.PublishNews(new News {
                Headline = "Microsoft jumping into gaming space", Priority = Priority.Low, Category = NewsCategory.Technical, Content = "A good news for gaming enthusiasts as Microsoft to soon launch a new gaming platform."
            });

            var newsPaper = newsAgency.CompileNewsPaper();

            Console.WriteLine("--------------" + newsPaper.Name + "-" + newsPaper.Date.ToShortDateString() + "-----------------");
            int pageNumber = 1;

            foreach (var page in newsPaper.Pages)
            {
                Console.WriteLine("-----Page -" + pageNumber + "--------");
                foreach (var news in page.NewsArticles)
                {
                    Console.WriteLine(news.Headline);
                    Console.WriteLine(news.Content);
                    Console.WriteLine("-----------------------------------");
                }
                Console.WriteLine("----------Advertisements Section-------------------");
                foreach (var add in page.Advertisements)
                {
                    Console.WriteLine(add.Product);
                    Console.WriteLine(add.AdContent);
                    Console.WriteLine("-----------------------------------");
                }
                pageNumber++;
            }
            Console.ReadLine();
        }