コード例 #1
0
ファイル: CommentTests.cs プロジェクト: rodown/funwithoiky
        public void ShouldGetTheRightPersonWhoMadeTheComment()
        {
            const int personId = 1;
            const int roleId = 1;
            var commentsToDelete = Context.Comments.Where(c => c.AboutPersonId == personId).ToList();
            foreach (var commentToDelete in commentsToDelete)
                Context.DeleteObject(commentToDelete);

            ICommentRepository commentsRepo = new CommentRepository(Context);
            var currentPerson = new Person { PersonId = personId, RoleId = roleId };

            const string testComment = "Test Comment";

            var newComment = new CommentDto
            {
                Comment       = testComment,
                AboutPersonId = personId,
                CommentDate   = DateTime.Now
            };

            var commentId = commentsRepo.SaveItem(currentPerson, newComment);
            var sut       = commentsRepo.GetListOfComments(currentPerson, personId).ToList();

            Assert.That(sut[0].CreatedByPerson, Is.EqualTo("Peter Munnings"));
        }
コード例 #2
0
        public void ShouldGetTheRightNumberOfComments()
        {
            const int personId   = 1;
            const int roleId     = 4;
            var commentsToDelete = _context.Comments.Where(c => c.AboutPersonId == personId).ToList();
            foreach(var commentToDelete in commentsToDelete)
                _context.DeleteObject(commentToDelete);

            _context.SaveChanges();

            ICommentRepository commentsRepo = new CommentRepository();
            var currentPerson = new Person {PersonId = personId, RoleId = roleId};

            const string testComment = "Test Comment";

            var newComment = new CommentDto
            {
                Comment       = testComment,
                AboutPersonId = personId,
                CommentDate   = DateTime.Now
            };

            var commentId = commentsRepo.SaveItem(currentPerson, newComment);

            var sut = commentsRepo.GetListOfComments(currentPerson, personId);

            Assert.That(sut.Count(), Is.EqualTo(1));
        }
コード例 #3
0
 public int SaveItem(Person currentPerson, CommentDto newCommentDto)
 {
     var newComment            = new Comment();
     Mapper.Map(newCommentDto, newComment);
     newComment.MadeByPersonId = currentPerson.PersonId;
     newComment.MadeByRoleId   = currentPerson.RoleId;
     Context.AddToComments(newComment);
     Context.SaveChanges();
     return newComment.CommentId;
 }
コード例 #4
0
        public void CanSaveNewComment()
        {
            var commentRepository = MockRepository.GenerateStub<ICommentRepository>();

            ICommentService commentService = new CommentService(commentRepository);
            var currentPerson = new Person();
            var newCommentDto = new CommentDto();
            const int commentId = 1;
            commentRepository
                .Expect(c => c.SaveItem(currentPerson, newCommentDto))
                .Return(commentId);

            var sut = commentService.SaveComment(currentPerson, newCommentDto);

            Assert.That(sut, Is.EqualTo(commentId));
        }
コード例 #5
0
 public int SaveComment(Person currentPerson, CommentDto newCommentDto)
 {
     return _commentRepository.SaveItem(currentPerson, newCommentDto);
 }