public IHttpActionResult CreateNews(CreateNewsBindingModel model)
 {
     var loggedUsedId = this.UserIdProvider.GetUserId();
     if (loggedUsedId == null)
     {
         return this.BadRequest("Please log in the system to post news");
     }
     if (!this.ModelState.IsValid)
     {
         return this.BadRequest(this.ModelState);
     }
     if (model.Title == null || model.Content == null)
     {
         return this.BadRequest();
     }
     var loggedUser = this.Data.Users.Find(loggedUsedId);
     var news = new News.Models.News()
     {
         Title = model.Title,
         Content = model.Content,
         PublishDate = DateTime.Now,
         Author = loggedUser
     };
     this.Data.News.Add(news);
     this.Data.SaveChanges();
     var result = this.Data.News.Find(news.Id);
     return this.Ok(result);
 }
 public IHttpActionResult PutNews(CreateNewsBindingModel model, int id)
 {
     if (!this.ModelState.IsValid)
     {
         return this.BadRequest(this.ModelState);
     }
     if (model.Title.IsNullOrWhiteSpace() || model.Content.IsNullOrWhiteSpace())
     {
         return this.BadRequest();
     }
     var news = this.Data.News.Find(id);
     if (news == null)
     {
         return this.BadRequest("News does not exist");
     }
     news.Title = model.Title;
     news.Content = model.Content;
     news.PublishDate = DateTime.Now;
     this.Data.SaveChanges();
     var result = this.Data.News.Find(id);
     return this.Ok(result);
 }
        public void CreateNewsWithCorrectData_ShouldReturnCreated()
        {
            var b = new AspNetUserIdProvider();
            
            var news = new CreateNewsBindingModel
            {
                Title = "News title",
                Content = "some news content"
            };

            var newsContent = new FormUrlEncodedContent(new[] 
            {
                new KeyValuePair<string, string>("Title", news.Title),
                new KeyValuePair<string, string>("Content", news.Content)
            });            
            var response = this.PostNews(newsContent);
            var createdNews = response.Content.ReadAsStringAsync().Result;
            var result = JsonConvert.DeserializeObject<News.Models.News>(createdNews);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual("News title", result.Title);
            Assert.AreEqual("some news content", result.Content);
        }