Exemple #1
0
        public async Task <IActionResult> Index(CancellationToken cancellationToken)
        {
            List <News> news = await _newsManagementService.GetAllNews(CurrentCookiesToken, cancellationToken);

            if (news == null)
            {
                return(View());
            }

            foreach (var n in news)
            {
                if (!string.IsNullOrEmpty(n.ImageUrl))
                {
                    try
                    {
                        var downloadedImg = _filesManagementService.DownloadImage(_appSettings.Value.BaseUrl + n.ImageUrl);

                        if (downloadedImg != null)
                        {
                            var thumbnail = _filesManagementService.GetThumbnail(downloadedImg);
                            n.Photo = _filesManagementService.ImageToByteArray(thumbnail);
                        }
                    }
                    catch (HttpRequestException)
                    {
                        n.Photo = null;
                    }
                    catch (AggregateException)
                    {
                        n.Photo = null;
                    }
                }
            }
            return(View(news.OrderByDescending(x => x.Published ?? DateTime.MaxValue).ThenByDescending(x => x.Title).ToList()));
        }
Exemple #2
0
        public async void NewsFunctionalityTest()
        {
            _token = await _accountManagementService.SignIn(TestingObjectProvider.Instance.Login);

            Assert.NotNull(_token);

            var news = TestingObjectProvider.Instance.News;

            Assert.NotNull(await _newsManagementService.GetAllNews(_token.Jwt));
            Assert.NotNull(await _newsManagementService.GetNews(news.Id, _token.Jwt));
            Assert.True(await _newsManagementService.CreateNews(news, _token.Jwt));
            Assert.True(await _newsManagementService.DeleteNews(news, _token.Jwt));

            var exception = Record.Exception(() => _newsManagementService.UpdateNews(null, _token.Jwt).Result);

            Assert.IsType(typeof(NullReferenceException), exception?.InnerException);

            Assert.False(await _newsManagementService.CreateNews(null, _token.Jwt));
        }
 public async void TestOfGettingAllNews()
 {
     Assert.NotNull(await _newsManagementService.GetAllNews(_token.Jwt));
 }