Пример #1
0
        public void CreateLike_CommentDoesNotExist_Test()
        {
            _mockRepository.Expect(x => x.Comments).Return(new FakeObjectSet<Comment>());
            _mockRepository.Expect(x => x.CommentLikes).Return(new FakeObjectSet<CommentLike>());
         
            var commentLike = new CommentLike();

            commentLike.UserInfoId = 1;
            commentLike.CommentId = 1;

            _socialService.CreateLike(commentLike);

            Assert.Fail("The unit test should never get here.");
        }
Пример #2
0
        /// <summary>
        /// Gets an instance of a commentlike object through parameter of the function, if the object isn't null persist it to the datasource.
        /// </summary>
        /// <param name="commentLike">Instance of commentlike object.</param>
        /// <exception cref="GameSchoolException"></exception>
        public void CreateLike(CommentLike commentLike)
        {
            if (commentLike != null)
            {
                if (GameSchoolEntities.Comments.Where(x=>x.CommentId == commentLike.CommentId).Count() != 1)
                {
                    throw new GameSchoolException(string.Format("Comment does not exist. CommentId = {0}",commentLike.CommentId));
                }

                if (GameSchoolEntities.UserInfoes.Where(x => x.UserInfoId == commentLike.UserInfoId).Count() != 1)
                {
                    throw new GameSchoolException(string.Format("User does not exist. UserInfoId = {0}", commentLike.UserInfoId));
                }

                if (GameSchoolEntities.CommentLikes.Where(x => x.CommentId == commentLike.CommentId && x.UserInfoId == commentLike.UserInfoId).Count() > 0)
                {
                    //throw new GameSchoolException(string.Format("Notandi hefur nú þegar líkað við þetta comment. UserInfoId = {0}", commentLike.UserInfoId));

                }

                else
                {
                    Comment likeComment = GameSchoolEntities.Comments.Where(x => x.CommentId == commentLike.CommentId).FirstOrDefault();
                    UserInfo commentUser = GameSchoolEntities.UserInfoes.Where(x => x.UserInfoId == likeComment.UserInfoId).FirstOrDefault();
                    UserInfo likeUser = GameSchoolEntities.UserInfoes.Where(x => x.UserInfoId == commentLike.UserInfoId).FirstOrDefault();
                    LevelMaterial commentLevelMaterial = GameSchoolEntities.LevelMaterials.Where(x => x.LevelMaterialId == likeComment.LevelMaterialId).FirstOrDefault();

                    GameSchoolEntities.CommentLikes.AddObject(commentLike);
                    Save();



                    if (likeUser.UserTypeId == (int)Enums.UserType.Teacher && commentUser.UserTypeId != (int)Enums.UserType.Teacher)
                    {
                        int userId = likeComment.UserInfoId;
                        int levelId = commentLevelMaterial.LevelId;
                        int points = 5;
                        string pointtype = "Þú hefur fengið {0} stig fyrir ummælum um {1}";

                        ExternalPointContainer.AddPointsToLevel(userId,levelId,points,pointtype);
                        ExternalNotificationContainer.CreateNotification("Þú hefur fengið 5 stig fyrir að kennara hefur líkað við ummæli þin við: "+ commentLevelMaterial.Title,"/Material/Get/" + commentLevelMaterial.LevelMaterialId,userId);
                    
                    }
                }
            }
        }
Пример #3
0
        public void CreateLike_UserDoesNotExist_Test()
        {
            var commentData = new FakeObjectSet<Comment>();

            var comment = new Comment();
            comment.CreateDateTime = DateTime.Now;
            comment.Deleted = false;
            comment.CommentId = 1;
            comment.DeletedByUser = null;
            comment.LevelMaterialId = 0;
            comment.UserInfoId = 1;

            commentData.AddObject(comment);

            _mockRepository.Expect(x => x.Comments).Return(commentData);
            _mockRepository.Expect(x => x.CommentLikes).Return(new FakeObjectSet<CommentLike>());
            _mockRepository.Expect(x => x.UserInfoes).Return(new FakeObjectSet<UserInfo>());

            var commentLike = new CommentLike();

            commentLike.UserInfoId = 100;
            commentLike.CommentId = 1;

            _socialService.CreateLike(commentLike);

            Assert.Fail("The unit test should never get here.");
        }
Пример #4
0
        public void DeleteLikeTest()
        {
            // Push dummy data to our database.
            var commentLikeData = new FakeObjectSet<CommentLike>();

            var commentLike = new CommentLike();
            commentLike.CommentLikeId = 1;
            commentLike.UserInfoId = 1;
            commentLike.CommentId = 1;

            commentLikeData.AddObject(commentLike);

            // Setup the mock expectations.
            _mockRepository.Expect(x => x.CommentLikes).Return(commentLikeData);
            _mockRepository.Expect(x => x.SaveChanges()).Return(1);

            // Call the service.
            _socialService.DeleteLike(1);

            // Check if everything was correctly called.
            _mockRepository.VerifyAllExpectations();
        }
Пример #5
0
        public ActionResult LikeComment(int? id)
        {
            if (id.HasValue)
            {
                var cUser = MembershipHelper.GetUser();
                CommentLike c = new CommentLike();
                c.UserInfoId = cUser.UserInfoId;
                c.CommentId = id.Value;
                SocialService.CreateLike(c);

                return Json(true, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(false, JsonRequestBehavior.AllowGet);
            }
        }