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>()));
 }