Пример #1
0
        protected override void Process(UserBroker payload)
        {
            //TODO: get database url from application configs.
            var databaseUrl = "Server=127.0.0.1;Port=5432;User ID=postgres;Password=admin;Database=YouCourse.Library";
            var useCase     = new UpdateAuthorUseCase(payload.ToDomain(), NHibernateUnitOfWork.Create(databaseUrl));

            useCase.Execute();
        }
        public void Should_update_author()
        {
            var authorId = Guid.NewGuid();

            var author = Author.Create(authorId, "Marcos Harbs Updated", "http://marcos.harbs.com/imagem_01.jpeg");

            var authorDB = Author.Create(authorId, "Marcos Harbs", "http://marcos.harbs.com/imagem.jpeg");

            var mockAuthorRepository = new Mock <IAuthorRepository>();

            mockAuthorRepository.Setup(mock => mock.GetById(author.Id)).Returns(authorDB);
            mockAuthorRepository.Setup(mock => mock.AddOrUpdate(authorDB));

            var mockUnitOfWork = new Mock <LibraryUnitOfWork>();

            mockUnitOfWork.Setup(mock => mock.GetAuthorRepository()).Returns(mockAuthorRepository.Object);

            var useCase       = new UpdateAuthorUseCase(author, mockUnitOfWork.Object);
            var updatedAuthor = useCase.Execute();

            mockAuthorRepository.Verify(mock => mock.GetById(author.Id), Times.Exactly(1));
            mockAuthorRepository.Verify(mock => mock.AddOrUpdate(author), Times.Exactly(1));
            updatedAuthor.Should().Be(author);
        }