Exemplo n.º 1
0
        public void ControlerShouldReturnAllArticles()
        {
            var _articlesController = new ArticlesController(articleService);

            var result = _articlesController.GetArticles();

            CollectionAssert.AreEqual(result, randomArticles);
        }
Exemplo n.º 2
0
        public async Task GetArticles_GivenNoQuery_ReturnsArticles()
        {
            var controller = new ArticlesController(_mediator);

            var result = await controller.GetArticles();

            Assert.IsAssignableFrom <IActionResult>(result);
            Assert.IsType <OkObjectResult>(result);
        }
Exemplo n.º 3
0
        public async void GetArticlesTest()
        {
            var controller = new ArticlesController(_context, _userManager);
            var result     = await controller.GetArticles(1, null);

            // Assert
            var objectResult = Assert.IsType <OkObjectResult>(result);
            var model        = Assert.IsAssignableFrom <ArticleListDTO>(objectResult.Value);

            Assert.Equal(_articleListDTO, model);
        }
Exemplo n.º 4
0
        public async Task GetArticles_WithDefaultPagingValues_ReturnsArticleDtoListWith3Items()
        {
            // arrange

            // act
            var result = await _articlesController.GetArticles(_articleParams);

            // assert
            _articleRepositoryMock.Verify(m => m.GetArticlesAsync(It.IsAny <ArticleParams>()), Times.Once);
            Assert.That(result, Is.Not.Null);
            Assert.That(result.GetType(), Is.EqualTo(typeof(ActionResult <IEnumerable <ArticleDto> >)));
            Assert.That(result.Result.GetType(), Is.EqualTo(typeof(OkObjectResult)));
            Assert.That(((ObjectResult)result.Result).Value.GetType(), Is.EqualTo(typeof(List <ArticleDto>)));
            Assert.That(((List <ArticleDto>)((ObjectResult)result.Result).Value).Count, Is.EqualTo(3));
        }
        [Fact] public async void TestSuccesfullAddArticles()
        {
            var articleContext   = new ArticlesContext(options);
            var controller       = new ArticlesController(articleContext);
            var articleFactory   = new ArticleFactory();
            var publisherFactory = new PublisherFactory();
            var pub = publisherFactory.GetDataObject(0, 0).Publisher;
            await articleContext.Publishers.AddAsync(pub);

            await controller.AddArticles(articleFactory.GenerateArticle(pub.Id));

            var articles = await controller.GetArticles();

            Assert.True(await articleContext.Publishers.CountAsync() == 1);
            Assert.True(articles.Value.Count == 1);
        }
        public void GetArticlesTest_ReturnsOkResultWithListOfArticles()
        {
            var articles = ArticleHelper.GetRandomTestArticles(10);

            _mockArticleService.Setup(ser => ser.GetEntitiesAsync()).ReturnsAsync(articles);

            var okObjectResult = (_controller.GetArticles().Result.Result as OkObjectResult)?.Value;
            var result         = okObjectResult as IEnumerable <Article> ?? throw new InvalidOperationException();

            Assert.Contains(result, article => articles.Any(a => a.Category == article.Category &&
                                                            a.UserName == article.UserName &&
                                                            a.Content == article.Content &&
                                                            a.CreatedDate == article.CreatedDate &&
                                                            a.Id == article.Id &&
                                                            a.Title == article.Title
                                                            ));
        }
Exemplo n.º 7
0
        public async void GetArticlesOverPageTest()
        {
            var controller = new ArticlesController(_context, _userManager);
            var result     = await controller.GetArticles(2, null);

            // Assert
            var objectResult = Assert.IsType <OkObjectResult>(result);
            var model        = Assert.IsAssignableFrom <ArticleListDTO>(objectResult.Value);

            var emptyDTO = new ArticleListDTO()
            {
                Limit     = 20,
                Count     = _articleDTOs.Count,
                PageCount = 1,
                Page      = 2,
                Articles  = new List <ArticleListElemDTO>()
            };

            Assert.Equal(emptyDTO, model);
        }
        public async Task TestGetAllArticles()
        {
            var provider = CommonTestUtils.InitializeDatabaseProvider();

            provider.AddStore(new Store()
            {
                Address = "Test Address1", Name = "TestName1", Articles = new List <Article>()
                {
                    new Article()
                    {
                    }
                }
            });
            provider.AddStore(new Store()
            {
                Address = "Test Address2", Name = "TestName2", Articles = new List <Article>()
                {
                    new Article()
                    {
                    }
                }
            });
            await provider.Save();

            var controller = new ArticlesController(provider, CommonTestUtils.InitializeMapper());

            var result = controller.GetArticles();

            var okResult = Assert.IsType <OkObjectResult>(result);
            var model    = Assert.IsAssignableFrom <ArticlesListResponseDto>(okResult.Value);

            Assert.Equal(2, model.Articles.Count);
            Assert.Equal(2, model.TotalElements);
            Assert.Equal(200, okResult.StatusCode);
            return;
        }