public void LikeExistsFalseTest()
        {
            var like1 = new MessageLike {
                Id = 1, MessageId = 1, UserId = 1
            };
            var like2 = new MessageLike {
                Id = 2, MessageId = 1, UserId = 2
            };
            var like3 = new MessageLike {
                Id = 3, MessageId = 2, UserId = 1
            };

            _messageLikeRepositoryMock.SetupRepositoryMock(options =>
            {
                options.Insert(like1);
                options.Insert(like2);
                options.Insert(like3);
            });

            var messageLikeService = new MessageLikeService(_messageLikeRepositoryMock.Object);

            var exists = messageLikeService.LikeExists(7, 8);

            Assert.False(exists);
        }
        public void LikeMessageTest()
        {
            var like1 = new MessageLike {
                Id = 1, MessageId = 1, UserId = 1
            };
            var like2 = new MessageLike {
                Id = 2, MessageId = 1, UserId = 2
            };
            var like3 = new MessageLike {
                Id = 3, MessageId = 2, UserId = 1
            };

            _messageLikeRepositoryMock.SetupRepositoryMock(options =>
            {
                options.Insert(like1);
                options.Insert(like2);
                options.Insert(like3);
            });

            var messageLikeService = new MessageLikeService(_messageLikeRepositoryMock.Object);

            var likeCountBefore = messageLikeService.GetMessageLikeCount(1);

            messageLikeService.LikeMessage(1, 3);

            var likeCountAfter = messageLikeService.GetMessageLikeCount(1);

            Assert.Equal(2, likeCountBefore);
            Assert.Equal(3, likeCountAfter);
        }
Beispiel #3
0
        public async Task <IActionResult> LikeMessage(int messageId)
        {
            var message = await _context.Messages.Where(m => m.Id == messageId).FirstOrDefaultAsync();

            if (message == null)
            {
                return(NotFound());
            }

            var newMsgLike = new MessageLike()
            {
                MessageId = messageId, UserId = 3
            };


            var msgLike = _context.MessageLikes.FirstOrDefault(ml => ml.MessageId == newMsgLike.MessageId && ml.UserId == 3);

            if (msgLike == null)
            {
                await _context.MessageLikes.AddAsync(newMsgLike);
            }
            else
            {
                _context.MessageLikes.Remove(msgLike);
            }

            await _context.SaveChangesAsync();

            return(Ok());
        }
Beispiel #4
0
        public IActionResult RemoveLikeFromMessage(int id)
        {
            int?    IntVariable  = HttpContext.Session.GetInt32("LoggedInId");
            RegUser LoggedInUser = dbContext.Users
                                   .FirstOrDefault(u => u.RegUserId == Convert.ToInt32(IntVariable));

            MessageLike deadlike = dbContext.MessageLikes
                                   .FirstOrDefault(i => i.MessageId == id && i.RegUserId == LoggedInUser.RegUserId);

            dbContext.MessageLikes.Remove(deadlike);
            dbContext.SaveChanges();

            return(RedirectToAction("Wall"));
        }
Beispiel #5
0
        public IActionResult AddLikeToMessage(int id)
        {
            int?    IntVariable  = HttpContext.Session.GetInt32("LoggedInId");
            RegUser LoggedInUser = dbContext.Users
                                   .Include(user => user.MessagesLiked)
                                   .FirstOrDefault(u => u.RegUserId == Convert.ToInt32(IntVariable));

            Message mess = dbContext.Messages
                           .FirstOrDefault(i => i.MessageId == id);

            MessageLike like = new MessageLike();

            like.RegUserId = LoggedInUser.RegUserId;
            like.MessageId = id;
            dbContext.MessageLikes.Add(like);
            dbContext.SaveChanges();

            return(RedirectToAction("Wall"));
        }