public void DetailsExistsTest()
        {
            // Act
            controller.db.News.Add(new News {
                ID = 1, Date = DateTime.Now, Text = "txt", Title = "title"
            });
            ViewResult result = controller.Details(1) as ViewResult;

            // Assert
            Assert.NotNull(result);
        }
        public async Task ReturnNewsByUrl()
        {
            // Assign
            var url             = "news-title-1";
            var news            = GetFakeNews();
            var dateTimeFactory = new DateTimeFactory();
            var fileServiceMock = new Mock <IFileStorageService>();

            var newsToFind = news.SingleOrDefault(n => n.Url == url);

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(news), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = new NewsController(context, dateTimeFactory, fileServiceMock.Object);

                // Act
                var response = await newsController.Details(newsToFind.Created.Year, newsToFind.Created.Month, newsToFind.Created.Day, url);

                var newsContent = response.GetModelAs <NewsViewModel>();

                // Assert
                Assert.Equal(url, newsContent.Url);
                Assert.IsType <ViewResult>(response);
            }
        }
Exemple #3
0
        public void _Return_View_With_Model(string cloud, string apiKey, string apiSecret, int newsId)
        {
            //Arrange
            var model = new NewsDetailsViewModel();
            var news  = new Models.News();

            var mockedAuthProvider = new Mock <IAuthenticationProvider>();

            var mockedNewsService = new Mock <INewsService>();

            mockedNewsService.Setup(n => n.GetNewsById(newsId)).Returns(news);

            var mockedViewModelFactory = new Mock <IViewModelFactory>();

            mockedViewModelFactory.Setup(v => v.CreateNewsDetailsViewModel(It.IsAny <Models.News>())).Returns(model);

            var fakeAcc          = new CloudinaryDotNet.Account(cloud, apiKey, apiSecret);
            var mockedCloudinary = new Mock <Cloudinary>(fakeAcc);

            var newsControllerSUT = new NewsController(mockedAuthProvider.Object, mockedNewsService.Object, mockedViewModelFactory.Object, mockedCloudinary.Object);

            //Act
            var res = newsControllerSUT.Details(newsId) as ViewResult;

            //Assert
            Assert.AreEqual(model, res.Model);
        }
        public async Task DetailsShouldReturnSingleNews()
        {
            int newsId   = 102;
            var mockRepo = new Mock <INewsRepository>();

            mockRepo.Setup(repo => repo.GetNewsById(newsId)).Returns(Task.FromResult(new News {
                NewsId = 102, Title = "2020 FIFA U-17 Women World Cup", Content = "The tournament will be held in India between 2 and 21 November 2020.", PublishedAt = DateTime.Now, UrlToImage = null, UserId = "Jack"
            }));

            var newsController = new NewsController(mockRepo.Object);

            var actual = await newsController.Details(newsId);

            var actionResult = Assert.IsType <ViewResult>(actual);

            Assert.NotNull(actionResult.Model);
            Assert.IsAssignableFrom <News>(actionResult.Model);
        }
Exemple #5
0
        public async Task ReturnCorrectViewModel_OnGet()
        {
            // Arrange
            var newsServiceMock = new Mock <INewsService>();

            string newsTitle = "More marvel movies will be producted";

            var newsViewModel = new NewsViewModel();

            newsServiceMock
            .Setup(g => g.GetNewsByNameAsync(newsTitle))
            .ReturnsAsync(newsViewModel);

            var sut = new NewsController(newsServiceMock.Object);

            // Act
            var result = await sut.Details(newsTitle) as ViewResult;

            // Assert
            Assert.IsInstanceOfType(result.Model, typeof(NewsViewModel));
        }
Exemple #6
0
        public async Task CallNewsServiceOnce_OnGet()
        {
            // Arrange
            var newsServiceMock = new Mock <INewsService>();

            string newsTitle = "More marvel movies will be producted";

            var newsViewModel = new NewsViewModel();

            newsServiceMock
            .Setup(g => g.GetNewsByNameAsync(newsTitle))
            .ReturnsAsync(newsViewModel);

            var sut = new NewsController(newsServiceMock.Object);

            // Act
            await sut.Details(newsTitle);

            // Assert
            newsServiceMock.Verify(g => g.GetNewsByNameAsync(newsTitle), Times.Once);
        }
        public async Task ReturnNotFoundResultWhenSearchByUrl()
        {
            // Assign
            var url             = "news-title-2";
            var news            = GetFakeNews();
            var dateTimeFactory = new DateTimeFactory();
            var fileServiceMock = new Mock <IFileStorageService>();

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(news), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = new NewsController(context, dateTimeFactory, fileServiceMock.Object);

                // Act
                var result = await newsController.Details(2017, 7, 21, url);

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
Exemple #8
0
        public void _Call_NewsService_GetNewsById(string cloud, string apiKey, string apiSecret, int newsId)
        {
            //Arrange
            var model = new AddNewsViewModel();

            var mockedAuthProvider = new Mock <IAuthenticationProvider>();
            var mockedNewsService  = new Mock <INewsService>();

            var mockedViewModelFactory = new Mock <IViewModelFactory>();

            mockedViewModelFactory.Setup(v => v.CreateAddNewsViewModel(It.IsAny <Cloudinary>())).Returns(model);

            var fakeAcc          = new CloudinaryDotNet.Account(cloud, apiKey, apiSecret);
            var mockedCloudinary = new Mock <Cloudinary>(fakeAcc);

            var newsControllerSUT = new NewsController(mockedAuthProvider.Object, mockedNewsService.Object, mockedViewModelFactory.Object, mockedCloudinary.Object);

            //Act
            var res = newsControllerSUT.Details(newsId) as ViewResult;

            //Assert
            mockedNewsService.Verify(n => n.GetNewsById(newsId), Times.Once);
        }
        public async Task ReturnOkObjectResultWhenSearchById()
        {
            // Assign
            int id              = 1;
            var news            = GetFakeNews();
            var dateTimeFactory = new DateTimeFactory();
            var fileServiceMock = new Mock <IFileStorageService>();

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(news), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = new NewsController(context, dateTimeFactory, fileServiceMock.Object);

                // Act
                var response = await newsController.Details(id);

                var result = response.GetModelAs <NewsViewModel>();

                // Assert
                Assert.IsType <ViewResult>(response);
                Assert.Equal(1, result.Id);
            }
        }