Beispiel #1
0
        public void CanCreate_should_throw_exception_if_text_not_defined()
        {
            var command = new CreateComment();

            ValidationAssert.Throws(() => GuardComments.CanCreate(command),
                                    new ValidationError("Text is required.", "Text"));
        }
Beispiel #2
0
        public void CanCreate_should_not_throw_exception_if_text_defined()
        {
            var command = new CreateComment {
                Text = "text"
            };

            GuardComments.CanCreate(command);
        }
Beispiel #3
0
        public void CanUpdate_should_throw_exception_if_comment_not_found()
        {
            var commentId = DomainId.NewGuid();
            var command   = new UpdateComment {
                CommentId = commentId, Actor = user1
            };

            var events = new List <Envelope <CommentsEvent> >();

            Assert.Throws <DomainObjectNotFoundException>(() => GuardComments.CanUpdate(command, commentsId, events));
        }
Beispiel #4
0
        public void CanUpdate_should_throw_exception_if_comment_from_another_user()
        {
            var commentId = DomainId.NewGuid();
            var command   = new UpdateComment {
                CommentId = commentId, Actor = user2, Text = "text2"
            };

            var events = new List <Envelope <CommentsEvent> >
            {
                Envelope.Create <CommentsEvent>(new CommentCreated {
                    CommentId = commentId, Actor = user1
                }).To <CommentsEvent>()
            };

            Assert.Throws <DomainException>(() => GuardComments.CanUpdate(command, commentsId, events));
        }
Beispiel #5
0
        public void CanDelete_should_not_throw_exception_if_comment_from_same_user()
        {
            var commentId = DomainId.NewGuid();
            var command   = new DeleteComment {
                CommentId = commentId, Actor = user1
            };

            var events = new List <Envelope <CommentsEvent> >
            {
                Envelope.Create <CommentsEvent>(new CommentCreated {
                    CommentId = commentId, Actor = user1
                }).To <CommentsEvent>()
            };

            GuardComments.CanDelete(command, commentsId, events);
        }
Beispiel #6
0
        public void CanUpdate_should_not_throw_exception_if_comment_is_own_notification()
        {
            var commentId = DomainId.NewGuid();
            var command   = new UpdateComment {
                CommentId = commentId, Actor = user1, Text = "text2"
            };

            var events = new List <Envelope <CommentsEvent> >
            {
                Envelope.Create <CommentsEvent>(new CommentCreated {
                    CommentId = commentId, Actor = user1
                }).To <CommentsEvent>()
            };

            GuardComments.CanUpdate(command, user1.Identifier, events);
        }
Beispiel #7
0
        public void CanUpdate_should_throw_exception_if_text_not_defined()
        {
            var commentId = DomainId.NewGuid();
            var command   = new UpdateComment {
                CommentId = commentId, Actor = user1
            };

            var events = new List <Envelope <CommentsEvent> >
            {
                Envelope.Create <CommentsEvent>(new CommentCreated {
                    CommentId = commentId, Actor = user1
                }).To <CommentsEvent>()
            };

            ValidationAssert.Throws(() => GuardComments.CanUpdate(command, commentsId, events),
                                    new ValidationError("Text is required.", "Text"));
        }
Beispiel #8
0
        public void CanUpdate_should_throw_exception_if_comment_deleted_found()
        {
            var commentId = DomainId.NewGuid();
            var command   = new UpdateComment {
                CommentId = commentId, Actor = user1
            };

            var events = new List <Envelope <CommentsEvent> >
            {
                Envelope.Create <CommentsEvent>(new CommentCreated {
                    CommentId = commentId, Actor = user1
                }).To <CommentsEvent>(),
                Envelope.Create <CommentsEvent>(new CommentDeleted {
                    CommentId = commentId
                }).To <CommentsEvent>()
            };

            Assert.Throws <DomainObjectNotFoundException>(() => GuardComments.CanUpdate(command, commentsId, events));
        }