public async Task <TableLayoutPanel> GetLayoutPanelAsync(User i_LoggedInUser)
        {
            StateSettings    appConfigServiceStateSettings = AppConfigService.GetInstance().StateSettings;
            TableLayoutPanel panel = new TableLayoutPanel {
                ColumnCount = 1, AutoScroll = true
            };
            ILikeService likeService = new LikesService(i_LoggedInUser);

            // get data as defined in settings
            List <Task> getDataTasks = new List <Task>();
            Dictionary <string, int> allPostemItemsLikes = new Dictionary <string, int>();

            foreach (KeyValuePair <eLikedItem, bool> keyValuePair in appConfigServiceStateSettings.LikedItems.Where(i_Item => i_Item.Value))
            {
                Task getDataTask = Task.Run(
                    async() =>
                {
                    PropertyInfo propertyInfo = i_LoggedInUser.GetType()
                                                .GetProperty(keyValuePair.Key.ToString());
                    if (propertyInfo != null)
                    {
                        try
                        {
                            object prop = propertyInfo.GetValue(i_LoggedInUser, null);
                            IEnumerable collectionOfUnknownType = (IEnumerable)prop;
                            ObservableCollection <PostedItem> currentPostedItems =
                                new ObservableCollection <PostedItem>();
                            foreach (PostedItem o in collectionOfUnknownType)
                            {
                                currentPostedItems.Add(o);
                            }

                            Dictionary <string, int> currenLikes =
                                await likeService.GetLikesHistogram(currentPostedItems).ConfigureAwait(false);
                            allPostemItemsLikes.AddRange <string, int>(currenLikes);
                        }
                        catch (Exception)
                        {
                            Console.WriteLine(Resources.FailedToRretrieveDataLikesForErrorMessage + propertyInfo);
                        }
                    }
                });
                getDataTasks.Add(getDataTask);
            }

            await Task.WhenAll(getDataTasks);

            Chart likeMeTheMostChart = ChartsUtil.CreateChart("Who Likes me the most!", DockStyle.Top,
                                                              allPostemItemsLikes.OrderByDescending(i_L => i_L.Value).
                                                              Take(appConfigServiceStateSettings.NumberOfFriend));
            Chart likeMeTheLeastChart = ChartsUtil.CreateChart("Who Likes me the least!", DockStyle.Bottom,
                                                               allPostemItemsLikes.OrderBy(i_L => i_L.Value).
                                                               Take(appConfigServiceStateSettings.NumberOfFriend));

            panel.Controls.Add(likeMeTheMostChart, 0, 0);
            panel.Controls.Add(likeMeTheLeastChart, 0, 1);

            return(panel);
        }
Exemplo n.º 2
0
        public void RemoveImageLike_ValidLikeId_Test()
        {
            var init = new InitializeMockContext();
            var mock = init.mock;

            var controller = new LikesService(mock.Object);

            controller.RemoveImageLike(2, 1);
            mock.Verify(m => m.SaveChanges(), Times.Once());
        }
Exemplo n.º 3
0
        public async Task CreateLikeShouldReturnTrue()
        {
            ApplicationDbContext db = GetDb();

            var likesRepository = new EfRepository <Like>(db);

            var service = new LikesService(likesRepository);

            await service.LikeAsync(1, "userId");

            Assert.Equal(1, db.Likes.Count());
        }
Exemplo n.º 4
0
        public void GetPostLikes_ValidPostId_ReturnsTwo()
        {
            var init = new InitializeMockContext();
            var mock = init.mock;

            var controller = new LikesService(mock.Object);
            var result     = controller.GetPostLikes(1, 1);
            var expected   = 2;
            var expected2  = "wyrak";

            Assert.AreEqual(expected, result.Count());
            Assert.AreEqual(expected2, result.First().Name);
        }
Exemplo n.º 5
0
        public void AddImageLike_ValidLike_Test()
        {
            var init = new InitializeMockContext();
            var mock = init.mock;

            var controller = new LikesService(mock.Object);

            controller.AddImageLike(new PostLikes {
                UserId = 2, PostId = 3
            });
            init.mockSetPostLikes.Verify(m => m.Add(It.IsAny <PostLikes>()), Times.Once());
            mock.Verify(m => m.SaveChanges(), Times.Once());
        }
Exemplo n.º 6
0
        public void AddImageLike_DuplicateLike_ThrowEx()
        {
            var init = new InitializeMockContext();
            var mock = init.mock;

            var controller = new LikesService(mock.Object);

            Assert.Throws <NegotiatedContentResultException>(() =>
                                                             controller.AddImageLike(new PostLikes {
                UserId = 2, PostId = 1
            })
                                                             );
        }
Exemplo n.º 7
0
        public async Task CreateLikeShouldAddInDatabase()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);

            var likesService = new LikesService(db);

            await likesService.CreateLikeAsync("userId", 1, true);

            Assert.Single(db.Likes);
        }
Exemplo n.º 8
0
        public void RemoveCommentLike_Counting_Test()
        {
            var init                 = new InitializeMockContext();
            var mock                 = init.mock;
            var commentId            = 1;
            var expectedLikeCountInt = mock.Object.PostComments.Where(x => x.Id == commentId).First().LikeCount;

            var controller = new LikesService(mock.Object);

            controller.RemoveCommentLike(2, 1);
            mock.Verify(m => m.SaveChanges(), Times.Once());

            Assert.AreEqual(expectedLikeCountInt - 1, mock.Object.PostComments.Where(x => x.Id == commentId).First().LikeCount);
        }
Exemplo n.º 9
0
        public void GetPostLikes_NoLoggedUser_ReturnsTwoNoFollowed()
        {
            var init = new InitializeMockContext();
            var mock = init.mock;

            var controller = new LikesService(mock.Object);
            var result     = controller.GetPostLikes(1, 1);
            var expected   = 2;
            var expected2  = "wyrak";
            var expected3  = false;

            Assert.AreEqual(expected, result.Count());
            Assert.AreEqual(expected2, result.First().Name);
            Assert.AreEqual(expected3, result.First().Followed);
        }
Exemplo n.º 10
0
        public async Task LikeAsyncShouldReturnTrue()
        {
            this.likesRepository
            .Setup(x => x.All())
            .Returns(new List <Like>()
            {
                new Like
                {
                },
            }.AsQueryable());

            var service = new LikesService(this.likesRepository.Object);
            var result  = await service.LikeAsync(10, "userId");

            Assert.True(result);
        }
Exemplo n.º 11
0
        public void AddImageLike_Counting_Test()
        {
            var init    = new InitializeMockContext();
            var mock    = init.mock;
            var imageId = 2;
            var expectedLikeCountInt = mock.Object.Posts.Where(x => x.Id == imageId).First().LikeCount;

            var controller = new LikesService(mock.Object);

            controller.AddImageLike(new PostLikes {
                UserId = 2, PostId = imageId
            });
            mock.Verify(m => m.SaveChanges(), Times.Once());

            Assert.AreEqual(expectedLikeCountInt + 1, mock.Object.Posts.Where(x => x.Id == imageId).First().LikeCount);
        }
Exemplo n.º 12
0
        public async Task IsPostLikedByUserAsync_WithInvalidUserId_ShouldReturnFalse()
        {
            // Arrange
            var context         = InMemoryDbContext.Initiliaze();
            var likesRepository = new EfRepository <Like>(context);
            var usersRepository = new EfRepository <ApplicationUser>(context);
            var postsRepository = new EfRepository <Post>(context);
            var service         = new LikesService(likesRepository, usersRepository, postsRepository);

            await this.SeedUserAndPost(context);

            await this.SeedLikes(context);

            // Act
            bool isLiked = await service.IsPostLikedByUserAsync("InvalidUserId", 52); // UserId is non-existent

            // Assert
            Assert.False(isLiked);
        }
Exemplo n.º 13
0
        public async Task DoesUserLikeReviewShouldReturnFalseWhenItIsntLiked()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);
            await db.Likes.AddRangeAsync(
                new Like { UserId = "user1", ReviewId = 1, IsLiked = false },
                new Like { UserId = "user2", ReviewId = 2, IsLiked = true });

            await db.SaveChangesAsync();

            var likesService = new LikesService(db);

            var result = await likesService.DoesUserLikeReviewAsync("user1", 1);

            Assert.False(result);
        }
Exemplo n.º 14
0
        public async Task GetPostLikesAsync_WithValidPostId_ShouldReturnTotalCountOfLikes()
        {
            // Arrange
            var context         = InMemoryDbContext.Initiliaze();
            var likesRepository = new EfRepository <Like>(context);
            var usersRepository = new EfRepository <ApplicationUser>(context);
            var postsRepository = new EfRepository <Post>(context);
            var service         = new LikesService(likesRepository, usersRepository, postsRepository);

            await this.SeedUserAndPost(context);

            await likesRepository.AddAsync(new Like { Id = 1, PostId = 52, UserId = "userId" });

            // Act
            int expectedCount = context.Likes.Count();
            int actualCount   = await service.GetPostLikesAsync(52);

            // Assert
            Assert.Equal(expectedCount, actualCount);
        }
Exemplo n.º 15
0
        public async Task LikeAsyncShouldReturnFalse()
        {
            ApplicationDbContext db = GetDb();

            this.likesRepository.Setup(x => x.All())
            .Returns(new List <Like>()
            {
                new Like
                {
                    CommentId = 10,
                    UserId    = "userId",
                },
            }.AsQueryable());

            var service = new LikesService(this.likesRepository.Object);
            var result  = await service.LikeAsync(10, "userId");

            Assert.False(result);
            Assert.Equal(0, db.Likes.Count());
        }
Exemplo n.º 16
0
        public async Task GetLikesCountShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);
            await db.Likes.AddRangeAsync(
                new Like { UserId = "user1", ReviewId = 1, IsLiked = true },
                new Like { UserId = "user2", ReviewId = 2, IsLiked = true },
                new Like { UserId = "user2", ReviewId = 1, IsLiked = true },
                new Like { UserId = "user2", ReviewId = 1, IsLiked = false });

            await db.SaveChangesAsync();

            var likesService = new LikesService(db);

            var result = await likesService.GetLikesCountByReviewIdAsync(1);

            Assert.Equal(2, result);
        }
Exemplo n.º 17
0
        public async Task GetLikesShouldReturnLikesCount()
        {
            ApplicationDbContext db = GetDb();

            var repository = new EfRepository <Like>(db);

            var service = new LikesService(repository);

            var like = new Like
            {
                CommentId = 34,
                UserId    = "userId",
            };

            await db.AddAsync(like);

            await db.SaveChangesAsync();

            var count = service.GetLikes(34);

            Assert.Equal(1, count);
        }
Exemplo n.º 18
0
        public async Task AddAsync_WithValidData_ShouldReturnPostCreatorId()
        {
            // Arrange
            var context         = InMemoryDbContext.Initiliaze();
            var likesRepository = new EfRepository <Like>(context);
            var usersRepository = new EfRepository <ApplicationUser>(context);
            var postsRepository = new EfRepository <Post>(context);
            var service         = new LikesService(likesRepository, usersRepository, postsRepository);

            await this.SeedUserAndPost(context);

            var model = new AddLikeModel {
                UserId = "userId", PostId = 52
            };

            // Act
            string expectedPostCreatorId = context.Posts.FirstOrDefault().CreatorId;
            string actualPostCreatorId   = await service.AddAsync(model);

            // Assert
            Assert.Equal(expectedPostCreatorId, actualPostCreatorId);
        }
Exemplo n.º 19
0
        public async Task CreateLikeShouldNotAddInDatabaseIfExists(string userId, int reviewId, bool liked)
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);
            await db.AddAsync(new Like { UserId = "userId", ReviewId = 1 });

            await db.SaveChangesAsync();

            var likesService = new LikesService(db);

            await likesService.CreateLikeAsync(userId, reviewId, liked);

            var result = await db.Likes.FirstOrDefaultAsync();

            Assert.Equal(userId, result.UserId);
            Assert.Equal(reviewId, result.ReviewId);
            Assert.Equal(liked, result.IsLiked);
            Assert.Single(db.Likes);
        }
Exemplo n.º 20
0
        public async Task ExistsAsync_WithValidLikeId_ShouldReturnTrue()
        {
            // Arrange
            var context         = InMemoryDbContext.Initiliaze();
            var likesRepository = new EfRepository <Like>(context);
            var usersRepository = new EfRepository <ApplicationUser>(context);
            var postsRepository = new EfRepository <Post>(context);
            var service         = new LikesService(likesRepository, usersRepository, postsRepository);

            await this.SeedUserAndPost(context);

            await this.SeedLikes(context);

            // Act
            bool likeExists = await service.ExistsAsync(26);       // Valid id.

            bool likeExistsTwo = await service.ExistsAsync(59135); // Invalid id.

            // Assert
            Assert.True(likeExists);
            Assert.False(likeExistsTwo);
        }
Exemplo n.º 21
0
        public async Task RemoveAsync_WithValidData_ShouldReturnTrue()
        {
            // Arrange
            var context         = InMemoryDbContext.Initiliaze();
            var likesRepository = new EfRepository <Like>(context);
            var usersRepository = new EfRepository <ApplicationUser>(context);
            var postsRepository = new EfRepository <Post>(context);
            var service         = new LikesService(likesRepository, usersRepository, postsRepository);

            await this.SeedUserAndPost(context);

            await this.SeedLikes(context);

            var model = new AddLikeModel {
                UserId = "userId", PostId = 52
            };

            // Act
            bool isLikeDeleted = await service.RemoveAsync(model);

            // Assert
            Assert.True(isLikeDeleted);
        }
Exemplo n.º 22
0
        public async Task GetLastThreeAsync_WithValidData_ShouldReturnLast3Likes()
        {
            // Arrange
            this.InitilaizeMapper();
            var context         = InMemoryDbContext.Initiliaze();
            var likesRepository = new EfRepository <Like>(context);
            var usersRepository = new EfRepository <ApplicationUser>(context);
            var postsRepository = new EfRepository <Post>(context);
            var service         = new LikesService(likesRepository, usersRepository, postsRepository);

            await this.SeedUserAndPost(context);

            await this.SeedLikes(context);

            // Act
            var likes = await service.GetLastThreeAsync(52);

            bool firstLikeRetrieved  = likes.Any(x => x.Id == 26); // Should return false, since we require only the latest 3 likes.
            bool fourthLikeRetrieved = likes.Any(x => x.Id == 29); // Should return true.

            // Assert
            Assert.False(firstLikeRetrieved);
            Assert.True(fourthLikeRetrieved);
        }
Exemplo n.º 23
0
        public async Task AddAsync_WithValidData_ShouldAddLikeToDatabase()
        {
            // Arrange
            var context         = InMemoryDbContext.Initiliaze();
            var likesRepository = new EfRepository <Like>(context);
            var usersRepository = new EfRepository <ApplicationUser>(context);
            var postsRepository = new EfRepository <Post>(context);
            var service         = new LikesService(likesRepository, usersRepository, postsRepository);

            await this.SeedUserAndPost(context);

            var model = new AddLikeModel {
                UserId = "userId", PostId = 52
            };

            // Act
            int expectedCount = context.Likes.Count() + 1;
            await service.AddAsync(model);

            int actualCount = context.Likes.Count();

            // Assert
            Assert.Equal(expectedCount, actualCount);
        }
        public async Task <TableLayoutPanel> GetLayoutPanelAsync(User i_LoggedInUser)
        {
            ILikeService likeService = new LikesService(i_LoggedInUser);
            ObservableCollection <PostedItem> items           = new ObservableCollection <PostedItem>(i_LoggedInUser.PhotosTaggedIn);
            Dictionary <string, int>          userLikesPhotos = await likeService.GetLikesHistogram(items);

            items = new ObservableCollection <PostedItem>(i_LoggedInUser.Posts);
            Dictionary <string, int> userLikesPosts = await likeService.GetLikesHistogram(items);

            items = new ObservableCollection <PostedItem>(i_LoggedInUser.Albums);
            Dictionary <string, int> userLikesAlbums = await likeService.GetLikesHistogram(items);

            TableLayoutPanel panel = new TableLayoutPanel {
                ColumnCount = 3, AutoScroll = true
            };

            panel.RowStyles.Add(new RowStyle(SizeType.AutoSize, 40F));

            fillLikeToTable("Photos", userLikesPhotos, panel, 0, 0);
            fillLikeToTable("Posts", userLikesPosts, panel, 0, 1);
            fillLikeToTable("Albums", userLikesAlbums, panel, 0, 2);

            return(panel);
        }
Exemplo n.º 25
0
        public async Task WhenUserLikeTwoTimesSamePetTheTotalLikesShoudBeCorrectAndDelete()
        {
            var list     = new List <Like>();
            var mockRepo = new Mock <IRepository <Like> >();

            mockRepo.Setup(x => x.All()).Returns(list.AsQueryable());
            mockRepo.Setup(x => x.AddAsync(It.IsAny <Like>())).Callback(
                (Like like) => list.Add(like));
            var service = new LikesService(mockRepo.Object);

            await service.SetLikeAsync(2, "Pesho", 1);

            await service.SetLikeAsync(2, "Pesho", 1);

            await service.SetLikeAsync(2, "Gosho", 1);

            await service.DeleteLikeAsync(2, "Gosho", 1);

            mockRepo.Verify(x => x.AddAsync(It.IsAny <Like>()), Times.Exactly(2));

            Assert.Equal(2, list.Count);
            Assert.Equal(2, service.GetTotalLikes(2));
            Assert.False(service.IsUserLikedIt("Pesho", 2));
        }
Exemplo n.º 26
0
 public ConferenceController(LikesService likesService)
 {
     this.likesService = likesService;
 }
Exemplo n.º 27
0
 public LikesServiceTests()
 {
     _likesService = new LikesService(_uowMock.Object);
 }
Exemplo n.º 28
0
 public ArticleController()
 {
     this.articlesService = new ArticlesService();
     this.likesService    = new LikesService();
 }
Exemplo n.º 29
0
 public SessionController(LikesService likesService)
 {
     this.likesService = likesService;
 }
Exemplo n.º 30
0
 public LikesController(LikesService likesService, UsersService usersService)
 {
     _likesService = likesService;
     _usersService = usersService;
 }