コード例 #1
0
        public void getById_returns_404_NotFound_when_document_not_found(
            DocumentDetails document,
            [Frozen]Mock<IQuery<Guid, DocumentDetails>> getDocQuery,
            DocumentsController sut)
        {
            getDocQuery.Setup(q => q.Execute(It.Is<Envelope<Guid>>(r => r.Item == document.Id)))
                       .Throws<DocumentNotFoundException>();

            var result = sut.GetById(document.Id);

            result.Should().BeOfType<NotFoundResult>("because document not found exception is thrown");
        }
コード例 #2
0
        public void getById_returns_document_returned_by_query(
            DocumentDetails document,
            [Frozen]Mock<IQuery<Guid, DocumentDetails>> getDocQuery,
            DocumentsController sut)
        {
            getDocQuery.Setup(q => q.Execute(It.Is<Envelope<Guid>>(r => r.Item == document.Id)))
                       .Returns(document);

            var result = sut.GetById(document.Id);

            result
                .Should().BeOfType<OkNegotiatedContentResult<DocumentResponseModel>>()
                .Which.Content.Should().ShouldBeEquivalentTo(document, options => options.ExcludingMissingMembers());
        }
コード例 #3
0
        public void execute_throws_exception_when_document_is_locked_by_another_user(
            string userName,
            string anotherUserName,
            Guid documentId,
            DocumentDetails document,
            Mock<IQuery<Guid, DocumentDetails>> docQuery,
            Mock<ICommand<LockInfo>> inner)
        {
            var lockInfo = new Envelope<LockInfo>(new LockInfo(documentId), userName);
            document.CheckedOutBy = anotherUserName;
            docQuery.Setup(q => q.Execute(It.Is<Envelope<Guid>>(r => r.Item == documentId))).Returns(document);

            var sut = new DocumentLockValidator<LockInfo>(inner.Object, docQuery.Object);

            sut.Invoking(cmd => cmd.Execute(lockInfo))
               .ShouldThrow<DocumentLockedException>();
        }
コード例 #4
0
        public void execute_calls_inner_implementation_when_document_is_not_locked(
            string userName,
            Guid documentId,
            DocumentDetails document,
            Mock<IQuery<Guid, DocumentDetails>> docQuery,
            Mock<ICommand<LockInfo>> inner)
        {
            var lockInfo = new Envelope<LockInfo>(new LockInfo(documentId), userName);
            document.CheckedOutBy = null;
            docQuery.Setup(q => q.Execute(It.Is<Envelope<Guid>>(r => r.Item == documentId))).Returns(document);

            var sut = new DocumentLockValidator<LockInfo>(inner.Object, docQuery.Object);

            sut.Execute(lockInfo);

            inner.Verify(cmd => cmd.Execute(lockInfo), Times.Once);
        }
コード例 #5
0
 private DocumentResponseModel MapDocument(DocumentDetails doc)
 {
     return new DocumentResponseModel()
                 {
                     Id = doc.Id.ToString(),
                     Title = doc.Title,
                     Content = doc.Content,
                     CheckedOutBy = doc.CheckedOutBy
                 };
 }