public void ListAllItemsReturnOkAndItemsAreSortedDescByPublishDate() { //Arrange TestUtils testUtils = new TestUtils(); TestUtils.InitializeMapper(); var db = testUtils.GetDbContext(); this.PopulateDb(db); INewsService newsService = new NewsService(db); var sut = new NewsController(newsService); //Act var result = sut.All(); //Assert result.GetType().Should() .Match(r => r == typeof(OkObjectResult)); var returnedData = (sut.All() as OkObjectResult).Value as IEnumerable <NewsInfoModel>; returnedData.Should() .HaveCount(5) .And .Match(r => r.ElementAt(0).Id == 3 && r.ElementAt(4).Id == 2); }
public void AllActionShouldReturnCorrectPageSizeIfInvalidNumber() { var controller = new NewsController(this.EmptyOjsData); var result = controller.All(1, -50) as ViewResult; var model = result.Model as AllNewsViewModel; Assert.AreEqual(10, model.PageSize); }
public void AllActionShouldReturnCorrectNewsCountInLastPageWithCustomPageSize() { var controller = new NewsController(this.EmptyOjsData); var result = controller.All(3, 20) as ViewResult; var model = result.Model as AllNewsViewModel; Assert.AreEqual(19, model.AllNews.Count()); }
public void AllActionShouldReturnCorrectNewsCountWithSetInitialPage() { var controller = new NewsController(this.EmptyOjsData); var result = controller.All(2) as ViewResult; var model = result.Model as AllNewsViewModel; Assert.AreEqual(10, model.AllNews.Count()); }
public void AllActionShouldReturnLastPageIfPassesParameterIsTooBig() { var controller = new NewsController(this.EmptyOjsData); var result = controller.All(100) as ViewResult; var model = result.Model as AllNewsViewModel; Assert.AreEqual(4, model.CurrentPage); }
public void AllActionShouldReturnCorrectNewsCountAndFirstPageIfInvalidPage() { var controller = new NewsController(this.EmptyOjsData); var result = controller.All(-2) as ViewResult; var model = result.Model as AllNewsViewModel; Assert.AreEqual(10, model.AllNews.Count()); Assert.AreEqual(1, model.CurrentPage); }
public void AllActionShouldReturnViewModel() { var controller = new NewsController(this.EmptyOjsData); var result = controller.All() as ViewResult; var model = result.Model as AllNewsViewModel; Assert.AreEqual(10, model.AllNews.Count()); Assert.AreEqual(1, model.CurrentPage); Assert.AreEqual(10, model.PageSize); Assert.AreEqual(4, model.AllPages); }
public void AllActionShouldReturnCorrectNewsTitles() { var controller = new NewsController(this.EmptyOjsData); var result = controller.All() as ViewResult; var model = result.Model as AllNewsViewModel; foreach (var news in model.AllNews) { Assert.AreEqual("News Title ", news.Title.Substring(0, 11)); } }
public void GetAllShouldWorkCorrectly() { var fakeNewsService = A.Fake <INewsService>(); A.CallTo(() => fakeNewsService.GetAllInList <NewsInListViewModel>(1, 3)) .Returns(A.CollectionOfFake <NewsInListViewModel>(10)); var newsController = new NewsController(fakeNewsService); var result = newsController.All(); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <NewsListViewModel>(viewResult.Model); Assert.Equal(10, model.News.Count()); }
public void _Call_NewsService_GetAll_Method() { //Arrange var mockedAuthProvider = new Mock <IAuthenticationProvider>(); var mockedNewsService = new Mock <INewsService>(); var mockedViewModelFactory = new Mock <IViewModelFactory>(); var fakeAcc = new CloudinaryDotNet.Account("fake", "fake", "fake"); var mockedCloudinary = new Mock <Cloudinary>(fakeAcc); var newsControllerSUT = new NewsController(mockedAuthProvider.Object, mockedNewsService.Object, mockedViewModelFactory.Object, mockedCloudinary.Object); //Act newsControllerSUT.All(); //Assert mockedNewsService.Verify(m => m.GetAll(), Times.Once); }
public void _Return_PartialView() { //Arrange var expectedPartialName = "_PagedNewsListPartial"; var mockedAuthProvider = new Mock <IAuthenticationProvider>(); var mockedNewsService = new Mock <INewsService>(); var mockedViewModelFactory = new Mock <IViewModelFactory>(); var fakeAcc = new CloudinaryDotNet.Account("fake", "fake", "fake"); var mockedCloudinary = new Mock <Cloudinary>(fakeAcc); var newsControllerSUT = new NewsController(mockedAuthProvider.Object, mockedNewsService.Object, mockedViewModelFactory.Object, mockedCloudinary.Object); //Act var res = newsControllerSUT.All() as PartialViewResult; //Assert Assert.AreEqual(expectedPartialName, res.ViewName); }