Ejemplo n.º 1
0
        public async Task GetArticlesWithPagination()
        {
            var articleService       = new ArticlesService(BaseUri, HttpClient);
            var firstPageOfArticles  = (await articleService.GetArticlesAsync(1)).ToArray();
            var secondPageOfArticles = (await articleService.GetArticlesAsync(2)).ToArray();

            Assert.IsNotNull(firstPageOfArticles);
            Assert.IsNotNull(secondPageOfArticles);
            Assert.AreNotEqual(firstPageOfArticles[0].ArticleId, secondPageOfArticles[0].ArticleId);
        }
Ejemplo n.º 2
0
        public async Task GetArticlesWithPagination()
        {
            var articleService      = new ArticlesService(BaseUri, HttpClient);
            var firstPageOfArticles = await articleService.GetArticlesAsync(1);

            var secondPageOfArticles = await articleService.GetArticlesAsync(2);

            Assert.IsTrue(firstPageOfArticles.Any());
            Assert.IsTrue(secondPageOfArticles.Any());
            Assert.AreNotEqual(firstPageOfArticles.First().ArticleId, secondPageOfArticles.First().ArticleId);
        }
Ejemplo n.º 3
0
        public async Task GetArticles()
        {
            var articleService = new ArticlesService(BaseUri, HttpClient);
            var articles       = await articleService.GetArticlesAsync();

            Assert.IsNotNull(articles);
        }
Ejemplo n.º 4
0
        public async Task GetArticles()
        {
            var articleService = new ArticlesService(BaseUri, HttpClient);
            var articles       = await articleService.GetArticlesAsync();

            Assert.IsTrue(articles.Any());
        }
Ejemplo n.º 5
0
        public async Task GetArticlesAsync_ReturnListOfArticles_WhenGetData()
        {
            // Arrange
            m_MockArticlesSourceService.Setup(service => service.GetDataAsync(SECTION)).ReturnsAsync(ARTICLE_SOURCES.ToList());
            var articlesService  = new ArticlesService(m_MockArticlesSourceService.Object);
            var expectedArticles = ARTICLE_SOURCES;

            // Act
            var articles = await articlesService.GetArticlesAsync(SECTION);

            // Assert
            m_MockArticlesSourceService.Verify(service => service.GetDataAsync(SECTION), Times.Once);
            Assert.Equal(expectedArticles, articles);
        }
Ejemplo n.º 6
0
        public void GetArticlesByInvalidSectionAsync_ReturnException_WhenErrorGetData()
        {
            // Arrange
            var errorMessage = "Invalid section";

            m_MockArticlesSourceService.Setup(service => service.GetDataAsync(SECTION)).ThrowsAsync(new NancyAPICoreExeption(errorMessage));
            var articlesService = new ArticlesService(m_MockArticlesSourceService.Object);

            // Act
            Action act = () => articlesService.GetArticlesAsync(SECTION).GetAwaiter().GetResult();

            // Assert
            var exception = Assert.Throws <NancyAPICoreExeption>(act);

            Assert.Equal(errorMessage, exception.Message);
            m_MockArticlesSourceService.Verify(service => service.GetDataAsync(SECTION), Times.Once);
        }
Ejemplo n.º 7
0
        public void ArticlesOrderTest()
        {
            Mock <IImagesService> imagesServiceMock = new Mock <IImagesService>();

            imagesServiceMock
            .Setup(ls => ls.UploadImageAsync(new StreamMock()))
            .Returns(Task.FromResult("url"));

            using (ApplicationDbContext dbContext = serviceProvider.GetService <ApplicationDbContext>())
            {
                Article zeroViewsArticle = new Article
                {
                    Title      = "zeroViewsArticle",
                    Content    = "testContent",
                    Views      = 0,
                    IsApproved = true,
                };

                Article twoViewsArticle = new Article
                {
                    Title      = "twoViewsArticle",
                    Content    = "testContent",
                    Views      = 2,
                    IsApproved = true,
                };

                dbContext.Articles.Add(zeroViewsArticle);
                dbContext.Articles.Add(twoViewsArticle);
                dbContext.SaveChangesAsync().GetAwaiter().GetResult();

                ArticlesService articlesService = new ArticlesService(dbContext,
                                                                      serviceProvider.GetService <IMapper>(),
                                                                      serviceProvider.GetService <IConfiguration>(),
                                                                      imagesServiceMock.Object);

                CarWashPOI.ViewModels.Articles.ArticlesIndexOutputModel resultFromService = articlesService.GetArticlesAsync(0, 2, "views").GetAwaiter().GetResult();

                Assert.Equal(resultFromService.Articles.First().Title, twoViewsArticle.Title);
            }
        }