public void EditNews_WithCorrectData_ShouldReturn200OkModifiesTheNewsInCorrectWay() { var news = MockDb.News(); var mockRepo = new Mock <IRepository <News> >(); mockRepo.Setup(n => n.Update(It.IsAny <News>())).Callback((News n) => news[CorrectNewsId - 1] = n); var controller = new NewsController(mockRepo.Object); SetupController(controller, "news"); var bindigModel = new NewsBindingModel() { Title = "Vremeto", Content = "...", PublishedDate = DateTime.Now.ToString("D") }; var result = controller.EditMock(CorrectNewsId, bindigModel).ExecuteAsync(new CancellationToken()).Result; Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); Assert.AreEqual(bindigModel.Title, news.First().Title); Assert.AreEqual("Moda", news.Last().Title); Assert.IsTrue(news.Count == 3); }
public void EditNews_WithIncorrectData_ShouldReturn400BadRequest() { var news = MockDb.News(); var mockRepo = new Mock <IRepository <News> >(); mockRepo.Setup(n => n.Update(It.IsAny <News>())).Callback((News n) => news[CorrectNewsId - 1] = n); var controller = new NewsController(mockRepo.Object); SetupController(controller, "news"); //Incorect data - empty BindigModel var bindigModel = new NewsBindingModel(); var result = controller.EditMock(CorrectNewsId, bindigModel).ExecuteAsync(new CancellationToken()).Result; Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); }
public void EditNews_ThatDoesNotExists_ShouldReturn400BadRequest() { var news = MockDb.News(); var mockRepo = new Mock <IRepository <News> >(); mockRepo.Setup(n => n.Update(It.IsAny <News>())).Callback((News n) => news[IncorrectNewsId - 1] = n); var controller = new NewsController(mockRepo.Object); SetupController(controller, "news"); var bindigModel = new NewsBindingModel() { Title = "Vremeto", Content = "...", PublishedDate = DateTime.Now.ToString("D") }; var result = controller.EditMock(IncorrectNewsId, bindigModel).ExecuteAsync(new CancellationToken()).Result; Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); }