Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        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());
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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));
            }
        }
Ejemplo n.º 9
0
        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());
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }