Exemplo n.º 1
0
        public async void PutImageTest()
        {
            var controller = new ArticlesController(_context, _userManager);

            var article = _articleDTOs.First(a => a.IsHighlighted == true);

            ImageDTO newImage = new ImageDTO()
            {
                Name   = "New Image",
                Base64 = article.Images.First().Base64
            }
            ;

            //POST TEST (Highlight)
            var result = await controller.PutImage(article.Id, newImage);

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

            newImage.Id = model.Id;
            Assert.Equal(newImage, model);


            //GET TEST (Image added to Article)
            article.Images.Add(newImage);
            var result2 = await controller.GetArticle(article.Id);

            var objectResult2 = Assert.IsType <OkObjectResult>(result2);
            var model2        = Assert.IsAssignableFrom <ArticleDTO>(objectResult2.Value);

            Assert.Equal(article, model2);
        }
Exemplo n.º 2
0
        public async void PutImageInvalidIdTest()
        {
            var controller = new ArticlesController(_context, _userManager);

            var article = _articleDTOs.First(a => a.IsHighlighted == true);

            ImageDTO newImage = new ImageDTO()
            {
                Name   = "New Image",
                Base64 = article.Images.First().Base64
            }
            ;


            var result = await controller.PutImage(40, newImage);

            Assert.IsType <NotFoundResult>(result);


            var result2 = await controller.PutImage(-1, newImage);

            Assert.IsType <BadRequestResult>(result2);
        }
Exemplo n.º 3
0
        public async void PutImageEmptyDataTest()
        {
            var controller = new ArticlesController(_context, _userManager);

            var article = _articleDTOs.First(a => a.IsHighlighted == true);

            ImageDTO newImage = new ImageDTO()
            {
                Name   = "New Image",
                Base64 = ""
            }
            ;


            var result = await controller.PutImage(article.Id, newImage);

            Assert.IsType <BadRequestResult>(result);
        }