示例#1
0
 /// <summary>
 /// Gets an instance of a comment object through parameter of the function, if the object isn't null persist it to the datasource.
 /// </summary>
 /// <param name="comment">Instance of comment object.</param>
 public void CreateComment(Comment comment)
 {
     if (comment != null)
     {
         GameSchoolEntities.Comments.AddObject(comment);
         Save();
     }
 }
        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.");
        }
        public void GetCommentsTest()
        {
            var commentData = new FakeObjectSet<Comment>();

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

            commentData.AddObject(comment);

            _mockRepository.Expect(x => x.Comments).Return(commentData);

            //IObjectSet<Comment> commentDataMock = MockRepository.GenerateMock<IObjectSet<Comment>>();

            //commentDataMock.Expect(x=>x.)

            var list = _socialService.GetComments(1);
                        //IObjectSet<Comment> commentDataMock = MockRepository.GenerateMock<IObjectSet<Comment>>();

            //commentDataMock.Expect(x=>x.)

            Assert.AreEqual(commentData.Count() , list.Count());

            _mockRepository.VerifyAllExpectations();
        }
示例#4
0
        public ActionResult CreateComment(Comment comment, int? id)
        {

            String strComment = comment.Comment1;
            

            if (!String.IsNullOrEmpty(strComment) && id.HasValue)
            { 
                Comment c = new Comment();
                  var  cUser = MembershipHelper.GetUser();
                  c.UserInfoId = cUser.UserInfoId;
                  c.Comment1 = strComment;
                  c.CreateDateTime = DateTime.Now;
                  c.LevelMaterialId = id.Value;
                  c.DeletedByUser = "";
                  SocialService.CreateComment(c);
                  return Json(true, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(false, JsonRequestBehavior.AllowGet);
            }

            
        }
示例#5
0
     private void FixupComment(Comment previousValue)
     {
         if (previousValue != null && previousValue.CommentLikes.Contains(this))
         {
             previousValue.CommentLikes.Remove(this);
         }
 
         if (Comment != null)
         {
             if (!Comment.CommentLikes.Contains(this))
             {
                 Comment.CommentLikes.Add(this);
             }
             if (CommentId != Comment.CommentId)
             {
                 CommentId = Comment.CommentId;
             }
         }
     }