public void Put_ShouldReturn400BadRequestOnNullContent() { var fakeNews = this.mocks.NewsRepositoryMock.Object.All(); int existingNewsId = 1; this.mocks.NewsRepositoryMock .Setup(r => r.Update(It.IsAny<NewsModel>())) .Callback((NewsModel newsModel) => { var news = fakeNews.FirstOrDefault(fn => fn.Id == existingNewsId); news.Title = newsModel.Title; news.Content = newsModel.Content; news.PublishDate = newsModel.PublishDate; }); var mockContext = new Mock<INewsData>(); mockContext .Setup(c => c.News) .Returns(this.mocks.NewsRepositoryMock.Object); var newsController = new NewsController(mockContext.Object); this.SetupController(newsController); var updateNews = new PutNewsBindingModel() { Title = "Null content", Content = null, PublishDate = new DateTime(2015, 9, 5) }; newsController.Validate(updateNews); var response = newsController.Put(existingNewsId, updateNews) .ExecuteAsync(CancellationToken.None).Result; Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void Post_ShouldReturn400BadRequestOnNullContent() { var news = new List<NewsModel>(); this.mocks.NewsRepositoryMock .Setup(r => r.Add(It.IsAny<NewsModel>())) .Callback((NewsModel newsModel) => { news.Add(newsModel); }); var mockContext = new Mock<INewsData>(); mockContext .Setup(c => c.News) .Returns(this.mocks.NewsRepositoryMock.Object); var newsController = new NewsController(mockContext.Object); this.SetupController(newsController); var newNews = new PostNewsBindingModel() { Title = "Null content", Content = null }; newsController.Validate(newNews); var response = newsController.Post(newNews) .ExecuteAsync(CancellationToken.None).Result; Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }