public void DeleteNews_ThatDoesNotExists_ShouldReturn400BadRequest() { var news = MockDb.News(); var mockRepo = new Mock <IRepository <News> >(); mockRepo.Setup(n => n.Delete(It.IsAny <News>())).Callback((News n) => news.RemoveAt(3)); var controller = new NewsController(mockRepo.Object); SetupController(controller, "news"); var result = controller.DeleteMock(IncorrectNewsId).ExecuteAsync(new CancellationToken()).Result; Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); Assert.IsTrue(news.Count == 3); }
public void DeleteNews_ThatExists_ShouldReturn200OkAndDeleteTheNews() { var news = MockDb.News(); var mockRepo = new Mock <IRepository <News> >(); mockRepo.Setup(n => n.Delete(It.IsAny <News>())).Callback((News n) => news.RemoveAt(CorrectNewsId - 1)); var controller = new NewsController(mockRepo.Object); SetupController(controller, "news"); var result = controller.DeleteMock(CorrectNewsId).ExecuteAsync(new CancellationToken()).Result; Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); Assert.AreEqual("Sport", news.First().Title); Assert.IsTrue(news.Count == 2); }