Пример #1
0
        public void ShouldNotRegisterWhenBookIsInvalid()
        {
            BookRequest bookRequest = _bookFixtures.GetValidBookInsertRequest();
            var         bookFactory = new Mock <IBookFactory>(MockBehavior.Strict);

            bookFactory
            .Setup(factory => factory.FromRequest(bookRequest))
            .Returns(_bookFixtures.GetInvalidBook);
            var bookService = new Mock <IBookServices>(MockBehavior.Strict);
            var repository  = new Mock <IBookRepository>();

            IBookRegister bookRegister = new BookRegister(
                bookFactory.Object,
                bookService.Object,
                repository.Object);

            bookRegister.Execute(bookRequest);

            bookRegister.IsValid.Should().BeFalse();
            bookService.VerifyAll();
            bookFactory.VerifyAll();
        }
Пример #2
0
        public void ShouldRegisterABook()
        {
            BookRequest bookRequest = _bookFixtures.GetValidBookInsertRequest();
            var         validBook   = _bookFixtures.GetValidBook();
            var         bookFactory = new Mock <IBookFactory>(MockBehavior.Strict);

            bookFactory
            .Setup(factory => factory.FromRequest(bookRequest))
            .Returns(validBook);
            bookFactory
            .Setup(factory => factory.FromEntityToResponse(validBook))
            .Returns(new BookResponse());
            var bookService = new Mock <IBookServices>(MockBehavior.Strict);

            bookService
            .Setup(bs => bs.Register(validBook));
            bookService
            .Setup(bs => bs.IsValid)
            .Returns(true);
            var repository = new Mock <IBookRepository>(MockBehavior.Strict);

            repository
            .Setup(repo => repo.GetByISBN(It.IsAny <ISBN>()))
            .Returns(validBook);
            IBookRegister bookRegister = new BookRegister(
                bookFactory.Object,
                bookService.Object,
                repository.Object);

            bookRegister.Execute(bookRequest);

            bookRegister.IsValid.Should().BeTrue();
            bookService.VerifyAll();
            bookFactory.VerifyAll();
            repository.VerifyAll();
        }