public async Task Post_InvalidArticle_ReturnsBadRequest()
        {
            //Arrange
            _articlesController.ModelState.AddModelError("ArticleTitle", "Required");

            //Act
            var result = await _articlesController.Post(TestHelper.DummyArticles(1).Single());

            //Assert
            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
예제 #2
0
        public async void Post_ShouldReturn_CreatedArticle()
        {
            // Arrange
            mockedRep.Setup(x => x.CreateArticleAsync(It.IsAny <Article>())).ReturnsAsync(new Article());

            // Act
            var actual = await sut.Post(new Article());

            // Assert
            Assert.IsType(typeof(JsonResult <Article>), actual);
        }
        public async Task Post_BadRequest()
        {
            //Arrange
            _articlesController.ModelState.Clear();
            _articlesController.ModelState.AddModelError("Title", "Title is Required");

            //Act
            var result = await _articlesController.Post(It.IsAny <ArticleModel> ());

            //Assert
            Assert.NotNull(result);
            var objectResult = result as BadRequestObjectResult;

            Assert.NotNull(objectResult);
        }
예제 #4
0
        public async Task Post_BadRequest()
        {
            _articlesController.ModelState.AddModelError("mock", "mock error");

            var model = new ArticleModel {
            };

            var result = await _articlesController.Post(model);

            Assert.NotNull(result);

            var badRequestResult = result as BadRequestObjectResult;

            Assert.NotNull(badRequestResult);
        }
예제 #5
0
        public async Task Post_BadRequest()
        {
            // Arrange
            _articlesController.ModelState.AddModelError("Content", "Required");

            // Act
            var result = await _articlesController.Post(Builder <ArticleModel> .CreateNew().Build());

            // Assert
            Assert.NotNull(result);

            var objectResult = result as BadRequestObjectResult;

            Assert.NotNull(objectResult);
        }
예제 #6
0
        public async Task Post_Article_InvalidState()
        {
            // Arrange
            var mockArticleModel = new ArticleModel {
                Title = "mock article"
            };

            _articlesController.ModelState.AddModelError("Description", "This field is required");
            // Act
            var result = await _articlesController.Post(mockArticleModel);

            // Assert
            var actionResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.Equal(new SerializableError(_articlesController.ModelState), actionResult.Value);
        }
예제 #7
0
        public async Task Post_Article_New()
        {
            // Arrange
            var articleDbSetMock = Builder <Article> .CreateNew().Build();

            _articleRepositoryMock.Setup(m => m.InsertAsync(articleDbSetMock));
            var articleModel = new ArticleModel
            {
                Title     = articleDbSetMock.Title,
                Content   = articleDbSetMock.Content,
                Published = articleDbSetMock.Published
            };

            // Act
            var result = await _articlesController.Post(articleModel);

            // Assert
            Assert.NotNull(result);

            var objectResult = result as CreatedResult;

            Assert.NotNull(objectResult);

            var content = objectResult.Value as ArticleModel;

            Assert.NotNull(content);

            Assert.Equal(articleModel.Title, content.Title);
            Assert.Equal(articleModel.Content, content.Content);
            Assert.Equal(DateTime.UtcNow.ToLocalTime().Date, content.Date.Date);
            Assert.Equal(articleModel.Published, content.Published);
        }
예제 #8
0
        public async Task Post_Article()
        {
            var article = new Article()
            {
                Title = "Post article Test"
            };
            var articleModel = new ArticleModel()
            {
                Title = "Post article Test"
            };

            // Arrange
            _articleRepositoryMock.Setup(m => m.InsertAsync(article)).Returns(Task.FromResult <Article>(article));

            // Act
            var result = await _articlesController.Post(articleModel);

            // Assert
            Assert.NotNull(result);

            var objectResult = result as CreatedResult;

            Assert.NotNull(objectResult);

            var content = objectResult.Value as Article;

            Assert.NotNull(content);

            Assert.Equal(201, objectResult.StatusCode);

            Assert.Equal("Post article Test", content.Title);
        }
예제 #9
0
        public async Task ArticlePost_Item()
        {
            // Model
            var modelPut = new ArticleModel()
            {
                Title     = "Title New",
                Content   = "Content New",
                Published = false,
                Date      = DateTime.Now
            };

            // Act
            var result = await _articlesController.Post(modelPut);

            Assert.NotNull(result);

            var objectResult = result as CreatedResult;

            Assert.NotNull(objectResult);

            var content = objectResult.Value as Article;

            Assert.NotNull(content);

            Assert.Equal(modelPut.Content, content.Content);
            Assert.Equal(modelPut.Title, content.Title);
        }
예제 #10
0
        public async Task Post_Returns400BadRequest()
        {
            // Arrange
            _articlesController.ModelState.AddModelError("Content", "Content is required");
            var article = Builder <ArticleModel> .CreateNew().Build();

            //Act
            var result = await _articlesController.Post(article);

            // Assert
            Assert.NotNull(result);

            var objectResult = result as BadRequestObjectResult;

            Assert.NotNull(objectResult);
            Assert.Equal(400, objectResult.StatusCode);
        }
예제 #11
0
        public async Task Post_OnCreateReturnsBadRequestForMissingTitleValue()
        {
            // Arrange
            _articlesController.ModelState.AddModelError("Title", "Article's title is required.");
            var newArticle = Builder <ArticleModel> .CreateNew().Build();

            // Act


            var result = await _articlesController.Post(newArticle);

            // Assert
            Assert.NotNull(result);
            var objectResult = result as BadRequestObjectResult;

            Assert.NotNull(objectResult);
            Assert.Equal(400, objectResult.StatusCode);
        }
예제 #12
0
        public async Task Create_Success()
        {
            // Arrange
            _articleRepositoryMock.Setup(m => m.InsertAsync(It.IsAny <Article>())).Returns(Task.FromResult(true));

            // Act
            var model = Builder <ArticleModel> .CreateNew().Build();

            var result = await _articlesController.Post(model);

            // Assert
            Assert.NotNull(result);

            var objectResult = result as CreatedResult;

            Assert.NotNull(objectResult);

            var content = objectResult.Value as ArticleModel;

            Assert.NotNull(content);

            Assert.Equal("Title1", content.Title);
        }
        public async Task CreateWithValidData()
        {
            var artitleModel = new ArticleModel
            {
                Title     = "new title",
                Content   = "new content",
                Date      = DateTime.Now,
                Published = false
            };
            // Act
            var result = await _articlesController.Post(artitleModel);

            // Assert
            Assert.NotNull(result);

            var objectResult = result as CreatedResult;

            Assert.NotNull(objectResult);
            var content = objectResult.Value as Article;

            Assert.NotNull(content);

            Assert.Equal("new title", content.Title);
        }
예제 #14
0
        public async Task Post_ReturnsCreated()
        {
            // Arrange
            var article = Builder <ArticleModel> .CreateNew()
                          .Build();


            // Act
            var result = await _articlesController.Post(article);

            // Assert
            Assert.NotNull(result);
            var objectResult = result as CreatedResult;

            Assert.NotNull(objectResult);
        }
예제 #15
0
        public async Task Post_Success()
        {
            // Arrange
            _articleRepositoryMock.Setup(m => m.InsertAsync(Builder <Article> .CreateNew().Build()));

            // Act
            var result = await _articlesController.Post(new ArticleModel());

            // Assert
            Assert.NotNull(result);

            var objectResult = result as CreatedResult;

            Assert.NotNull(objectResult);

            var content = objectResult.Value as Article;

            Assert.NotNull(content);
        }
예제 #16
0
        public async Task Post_InsertiTem()
        {
            // Arrange
            var article = Builder <ArticleModel> .CreateNew().Build();

            // Act
            var result = await _articlesController.Post(article);

            // Assert
            Assert.NotNull(result);

            var objectResult = result as CreatedResult;

            Assert.NotNull(objectResult);

            var content = objectResult.Value as Article;

            Assert.NotNull(content);

            Assert.Equal(1, _context.Articles.Count());
        }
 public void MustAddArticle()
 {
     _articlesController.Post(_articleModel);
     _articleRepositoryMock.Verify(r => r.save(It.IsAny <Article>()));
 }