public void Detail_MustReturnBadRequesStatusCodeIfWePassNull() { //Mock repository var mockedArticles = new Mock <IRepository <Article> >(); mockedArticles.Setup(repo => repo.All()).Returns(_articles.AsQueryable()); //Mock data var mockedUow = new Mock <IUowData>(); mockedUow.Setup(uow => uow.Articles).Returns(() => { return(mockedArticles.Object); }); // Act ArticlesController articlesController = new ArticlesController(mockedUow.Object); var results = articlesController.Detail(null) as HttpStatusCodeResult; Assert.AreEqual(results.StatusCode, (int)HttpStatusCode.BadRequest); }
public void Detail_MustReturnNotFoundStatusCodeIfThereIsNoArticleWithThisId() { //Mock repository var mockedArticles = new Mock <IRepository <Article> >(); mockedArticles.Setup(repo => repo.All()).Returns(_articles.AsQueryable()); //Mock data var mockedUow = new Mock <IUowData>(); mockedUow.Setup(uow => uow.Articles).Returns(() => { return(mockedArticles.Object); }); // Act ArticlesController articlesController = new ArticlesController(mockedUow.Object); var results = articlesController.Detail(222) as HttpStatusCodeResult; Assert.AreEqual(results.StatusCode, (int)HttpStatusCode.NotFound); }
public void Detail_MustReturnArticleIfWePassCorrectId() { //Mock repository var mockedArticles = new Mock <IRepository <Article> >(); mockedArticles.Setup(repo => repo.All()).Returns(_articles.AsQueryable()); //Mock data var mockedUow = new Mock <IUowData>(); mockedUow.Setup(uow => uow.Articles).Returns(() => { return(mockedArticles.Object); }); // Act ArticlesController articlesController = new ArticlesController(mockedUow.Object); var results = articlesController.Detail(1) as ViewResult; var model = results.Model as ArticleViewModel; Assert.IsNotNull(model); Assert.AreEqual(1, model.Id); }