Esempio n. 1
0
        public void Test_Application_add_article()
        {
            // Arrange
            utils.CleanTables();
            var        userIds = utils.CreateUsers();
            AspNetUser user    = new AspNetUser()
            {
                Id = userIds.Item2
            };
            string  body    = "test body";
            string  title   = "test title";
            Article article = new Article()
            {
                Body  = body,
                Title = title,
            };

            // Act
            Article createdArticle = newsservice.AddArticle(user, article);

            // Assert
            Assert.IsNotNull(createdArticle);
            Assert.AreEqual <string>(userIds.Item2, createdArticle.AspNetUser.Id);
            Assert.AreEqual <string>(title, createdArticle.Title);
            Assert.AreEqual <string>(body, createdArticle.Body);
            Assert.AreNotEqual <DateTime?>(null, createdArticle.CreatedDate);
        }
Esempio n. 2
0
        public IHttpActionResult PostArticle(Article article)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _newsService.AddArticle(article);

            if (article.isLead)
            {
                ChangeLeadArticle(article.Id);
            }

            return(CreatedAtRoute("DefaultApi", new { id = article.Id }, article));
        }
Esempio n. 3
0
 public ActionResult CreateArticle([Bind(Exclude = "Id")] ArticleViewModel inputArticle)
 {
     ViewBag.ArticleAction = "CreateArticle";
     ViewBag.Title         = "Create";
     if (ModelState.IsValid)
     {
         Article mappedArticle  = _mapper.Map <ArticleViewModel, Article>(inputArticle);
         Article createdArticle = _newsService.AddArticle(_user, mappedArticle);
         if (createdArticle == null)
         {
             return(View("Error"));
         }
         else
         {
             return(Redirect("ArticleList"));
         }
     }
     else
     {
         return(View("CreateArticle"));
     }
 }