예제 #1
0
        public void AssignAuthorTest()
        {
            // Arrange
            var expected = new BookDto()
            {
                Id          = "1",
                Title       = "Fname",
                Description = "Lname"
            };
            var repository = new Mock <IRepository <Book> >();

            repository.Setup(r => r.Get(It.IsAny <Expression <Func <Book, bool> > >(), null, ""))
            .Returns(new [] {
                new Book
                {
                    Id           = "1",
                    Title        = "Fname",
                    Description  = "Lname",
                    AuthorsBooks = new List <AuthorBook>()
                }
            });
            var mapper = new Mock <IMapper>();

            mapper.Setup(m => m.Map <Book, BookDto>(It.IsAny <Book>())).Returns(expected);
            var svc = new BookService(repository.Object, mapper.Object, _config.Object);

            // Act
            svc.AssignAuthor("1", "1");

            // Assert
            repository.Verify(i => i.Update(It.IsAny <Book>()), Times.Once());
            repository.Verify(i => i.Save(), Times.Once());
        }