Пример #1
0
        public async Task GetByIdShouldReturnCorrectPost()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var applicationUser        = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var pictureRepository      = new EfRepository <UserProfilePicture>(dbContext);
            var repositoryComment      = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext);
            var friendRepository       = new EfDeletableEntityRepository <Friend>(dbContext);

            var post = new NewsFeedPost
            {
                Id      = 1,
                Content = "test",
                UserId  = "1",
            };

            await repositoryNewsFeedPost.AddAsync(post);

            await repositoryNewsFeedPost.SaveChangesAsync();

            var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository);

            AutoMapperConfig.RegisterMappings(typeof(GetByIdTestViewModel).GetTypeInfo().Assembly);

            var postResult = await service.GetByIdAsync <GetByIdTestViewModel>(post.Id);

            Assert.Equal(post.Id, postResult.Id);
        }
Пример #2
0
        public async Task CreateCoverPictureAsyncShouldCreateCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var applicationUser        = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var pictureRepository      = new EfRepository <UserProfilePicture>(dbContext);
            var repositoryComment      = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext);
            var friendRepository       = new EfDeletableEntityRepository <Friend>(dbContext);

            var userPicture = new UserCoverPicture
            {
                PictureURL        = "mountain.jpg",
                ApplicationUserId = "1",
            };

            var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository);

            var createResult = service.CreateCoverPictureAsync(userPicture.ApplicationUserId, userPicture.PictureURL);

            Assert.Equal(1, coverPictureRepository.All().Count());
        }
Пример #3
0
        public async Task GetAllNewsFeedPostPerPageShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var applicationUser        = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var pictureRepository      = new EfRepository <UserProfilePicture>(dbContext);
            var repositoryComment      = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext);
            var friendRepository       = new EfDeletableEntityRepository <Friend>(dbContext);

            var posts = this.NewsFeedPostSeeder(5, DateTime.UtcNow);

            foreach (var post in posts)
            {
                await repositoryNewsFeedPost.AddAsync(post);
            }

            await repositoryNewsFeedPost.SaveChangesAsync();

            var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository);

            AutoMapperConfig.RegisterMappings(typeof(GetAllNewsFeedPostPerPageTestViewModel).GetTypeInfo().Assembly);

            var postResult = service.GetAllSocialPosts <GetAllNewsFeedPostPerPageTestViewModel>(1);

            Assert.Equal(4, postResult.Count());
        }
Пример #4
0
        public async Task <List <BlogDescription> > FetchBlog(string url)
        {
            var blogList         = new List <BlogDescription>();
            var newsFeedService  = new NewsFeedService(url);
            var syndicationItems = await newsFeedService.GetNewsFeed();

            foreach (var syndicationItem in syndicationItems)
            {
                var description =
                    syndicationItem.Description.Substring(0, Math.Min(200, syndicationItem.Description.Length));
                var time = syndicationItem.Published;
                var uri  = syndicationItem.Links.FirstOrDefault()?.Uri;

                if (time < syndicationItem.LastUpdated)
                {
                    time = syndicationItem.LastUpdated;
                }

                blogList.Add(new BlogDescription()
                {
                    Title       = syndicationItem.Title,
                    Description = description,
                    Time        = time.DateTime,
                    Url         = uri?.AbsoluteUri
                });
            }

            return(blogList);
        }
Пример #5
0
        public ActionResult NewsFeed(int id)
        {
            NewsFeedService newsFeedService = new NewsFeedService();
            var             items           = newsFeedService.GetNewsFeedItems(id);

            return(View(items));
        }
Пример #6
0
        public void GetPostsCountByUserShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var applicationUser        = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var pictureRepository      = new EfRepository <UserProfilePicture>(dbContext);
            var repositoryComment      = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext);
            var friendRepository       = new EfDeletableEntityRepository <Friend>(dbContext);

            var post = new NewsFeedPost
            {
                Content = "test",
                UserId  = "1",
            };

            var secondPost = new NewsFeedPost
            {
                Content = "testTwo",
                UserId  = "1",
            };

            var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository);

            var postResult = service.CreateAsync(post.Content, post.UserId);

            var secondPostResult = service.CreateAsync(secondPost.Content, secondPost.UserId);

            var postCount = service.GetPostsCountByUser(post.UserId);

            Assert.Equal(2, postCount);
        }
Пример #7
0
        public ActionResult Index()
        {
            ViewBag.Message = "Your application description page.";
            NewsFeedService newsFeedService = new NewsFeedService();
            var             newsFeedAboDto  = newsFeedService.GetNewsFeeds();

            return(View(newsFeedAboDto));
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EmailScheduler"/> class.
 /// </summary>
 public EmailScheduler(NewsFeedService newsFeedService, UserService userService, IUsersContextFactory usersContextFactory, NewsLetterNotification notification)
     : base(Name)
 {
     this.newsFeedService     = newsFeedService;
     this.userService         = userService;
     this.usersContextFactory = usersContextFactory;
     this.notification        = notification;
 }
Пример #9
0
        public void HavingACurrentCultureDifferentThanEnglishShouldNotThrows()
        {
            CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("es-AR");

            NewsFeedService newsFeedService = new NewsFeedService();

            Thread.CurrentThread.CurrentCulture = currentCulture;
        }
Пример #10
0
        public void CreateClass_ObjectConstructing_ObjectConstructedOK()
        {
            //Arrange

            //Act
            var target = new NewsFeedService(_discordMock, _settings, _webClient);

            //Assert
            Assert.NotNull(target);
        }
Пример #11
0
        public void SelectElementText_SelectingCssElement_ElementContentReturned()
        {
            //Arrange
            var targetContent = "Target content";
            var target        = new NewsFeedService(_discordMock, _settings, _webClient);
            var html          = $"<div>Test<ul><li>Nest</li><li>Bar</li></ul><footer>{targetContent}</footer></div>";

            //Act
            var selectedContent = target.SelectElementText(html, "footer");

            //Assert
            Assert.Equal(targetContent, selectedContent);
        }
Пример #12
0
        static void Main(string[] args)
        {
            var newsFeedService = new NewsFeedService();
            var feeds           = newsFeedService.GetNewsFeeds();

            foreach (var feed in feeds)
            {
                var rss          = FeedLoader(feed.FeedUrl);
                var parser       = new RdfParser();
                var newsfeedItem = parser.Parse(feed, rss);
                newsFeedService.StoreFeedItems(newsfeedItem);
                newsFeedService.UpdateAbo(feed);
            }
        }
Пример #13
0
        public void GetNewContent_ExtractingNewContent_NewContentReturned()
        {
            //Arrange
            var target = new NewsFeedService(_discordMock, _settings, _webClient);

            //Act
            var content = target.GetNewsItem();

            //Assert
            Assert.NotNull(content);
            Assert.Equal("Fresh Prince", content.Header);
            Assert.Equal("https://www.vg.no/test/img/fresh.jpg", content.ImageUrl);
            Assert.Equal("This is a story all about how my life got flipped right upside down.", content.Text);
            Assert.Equal("https://www.vg.no/test", content.LinkUrl);
        }
Пример #14
0
        public void RaiseChangeEvent_HandlingChangeEvent_ChangeEventHandled()
        {
            //Arrange
            var target = new NewsFeedService(_discordMock, _settings, _webClient);

            //Act
            // ((MockWebClientWrapper)_webClient.UpsertUrlContent("https://www.vg.no", _newsListPage.Replace("Value to check", "Changed value"));
            Thread.Sleep(_settings.CheckInterval + 100);
            var channelMock = _discordMock.GetChannel(1);
            var message     = ((IMessageChannel)channelMock).GetMessageAsync(1).GetAwaiter().GetResult();

            //Assert
            Assert.NotNull(message);
            Assert.Equal(1, message.Embeds.Count);
        }
Пример #15
0
        public async Task UserInfoUpdateShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var applicationUser        = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var pictureRepository      = new EfRepository <UserProfilePicture>(dbContext);
            var repositoryComment      = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext);
            var friendRepository       = new EfDeletableEntityRepository <Friend>(dbContext);

            var user = new ApplicationUser
            {
                Id        = "1",
                FirstName = "Ventsi",
                LastName  = "Ignatov",
                Email     = "*****@*****.**",
                UserName  = "******",
                BirthDay  = DateTime.UtcNow,
                Town      = "Barcelona",
            };

            var userWithUpdatedInfo = new ApplicationUser
            {
                Id        = "1",
                FirstName = "Ventsislav",
                LastName  = "Ignatov",
                Email     = "*****@*****.**",
                UserName  = "******",
                BirthDay  = DateTime.UtcNow,
                Town      = "Madrid",
            };


            await applicationUser.AddAsync(user);

            await applicationUser.SaveChangesAsync();

            var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository);

            var result = service.EditProfileAsync(userWithUpdatedInfo, user.Id);
        }
Пример #16
0
        public async Task GetLastCoverPictureShouldReturnLastPicture()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var applicationUser        = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var pictureRepository      = new EfRepository <UserProfilePicture>(dbContext);
            var repositoryComment      = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext);
            var friendRepository       = new EfDeletableEntityRepository <Friend>(dbContext);

            var firstUserPicture = new UserCoverPicture
            {
                PictureURL        = "mountain.jpg",
                ApplicationUserId = "1",
            };

            var secondUserPicture = new UserCoverPicture
            {
                PictureURL        = "mountain2.jpg",
                ApplicationUserId = "1",
            };

            await coverPictureRepository.AddAsync(firstUserPicture);

            await coverPictureRepository.AddAsync(secondUserPicture);

            await coverPictureRepository.SaveChangesAsync();

            var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository);

            var result = await service.LastCoverPictureAsync("1");

            var resultWhenIsNull = await service.LastCoverPictureAsync("2");

            Assert.Equal(secondUserPicture.PictureURL, result);
            Assert.Null(resultWhenIsNull);
        }
Пример #17
0
        public void BuildDiscordEmbed_BuildingFromNewsItem_DiscordEmbedReturned()
        {
            //Arrange
            var target   = new NewsFeedService(_discordMock, _settings, _webClient);
            var newsItem = new NewsItem
            {
                Header   = "Test header",
                LinkUrl  = "https://www.neon.gg/",
                Text     = "Neon is a guild on Karazhan EU. We are brand new, and looking for members to clear the first wing in ICC. We only do 10 man raiding and stuff.",
                ImageUrl = "https://www.neon.gg/exampleimage.png"
            };

            //Act
            var embed = target.BuildDiscordEmbed(newsItem);

            //Assert
            Assert.NotNull(embed);
            Assert.Equal(newsItem.Header, embed.Title);
            Assert.Equal(newsItem.ImageUrl, embed.Image.ToString());
            Assert.Equal(newsItem.LinkUrl, embed.Url);
            Assert.Equal(newsItem.Text, embed.Description);
        }
Пример #18
0
        public async Task GetFriendsForUserShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var applicationUser        = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var pictureRepository      = new EfRepository <UserProfilePicture>(dbContext);
            var repositoryComment      = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext);
            var friendRepository       = new EfDeletableEntityRepository <Friend>(dbContext);

            var firstFiend = new Friend
            {
                SenderId   = "1",
                ReceiverId = "2",
            };

            var secondFriend = new Friend
            {
                SenderId   = "1",
                ReceiverId = "4",
            };

            await friendRepository.AddAsync(firstFiend);

            await friendRepository.AddAsync(secondFriend);

            await friendRepository.SaveChangesAsync();

            var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository);

            var result = await service.GetFriendCountAsync(firstFiend.SenderId);

            Assert.Equal(2, result);
        }
Пример #19
0
        public async Task GetAllCoverPicturesAsyncShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var applicationUser        = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var pictureRepository      = new EfRepository <UserProfilePicture>(dbContext);
            var repositoryComment      = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext);
            var friendRepository       = new EfDeletableEntityRepository <Friend>(dbContext);

            var userPicture = new UserCoverPicture
            {
                PictureURL        = "mountain.jpg",
                ApplicationUserId = "1",
            };

            var secondUserPicture = new UserCoverPicture
            {
                PictureURL        = "mountainTwo.jpg",
                ApplicationUserId = "1",
            };

            var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository);

            var firstPictureResult  = service.CreateCoverPictureAsync(userPicture.ApplicationUserId, userPicture.PictureURL);
            var secondPictureResult = service.CreateCoverPictureAsync(secondUserPicture.ApplicationUserId, secondUserPicture.PictureURL);

            AutoMapperConfig.RegisterMappings(typeof(GetAllCoverPictureForUserViewModel).GetTypeInfo().Assembly);

            var resultCount = await service.GetAllCoverPicturesAsync <GetAllCoverPictureForUserViewModel>(userPicture.ApplicationUserId);

            Assert.Equal(2, resultCount.Count());
        }
 public HomeController(ILogger <HomeController> logger, NewsFeedService newsService)
 {
     _logger      = logger;
     _newsService = newsService;
 }
Пример #21
0
        public object Get(bool?onlySubscribed, int?providerId)
        {
            NewsFeedService service = new NewsFeedService();

            return(service.getNewsFeeds(onlySubscribed, providerId));
        }
Пример #22
0
 public FeedController(NewsFeedService newsService)
 {
     _newsService = newsService;
 }
Пример #23
0
 public NewsViewComponent(NewsFeedService newsService)
 {
     this.newsService = newsService;
 }
Пример #24
0
 public NewsFeedFragment()
 {
     newsFeedService = new NewsFeedService();
 }