public void AddAuthor() { // Arrange //var context = new BookRankingDbContext(DbConnectionFactory.CreateTransient()); var context = new Mock <IBookRankingDbContext>(); var mockMapper = new Mock <IMapper>(); var authorDTOMock = new Mock <AuthorDTO>(); var authorMock = new Mock <Author>(); mockMapper.Setup(m => m.Map <Author>(authorDTOMock.Object)).Returns(authorMock.Object); var authors = new FakeDbSet <Author>(); context.Setup(c => c.Authors).Returns(authors); var service = new AuthorService(context.Object, mockMapper.Object); // Act service.AddAuthor(authorDTOMock.Object); // Assert Assert.IsTrue(context.Object.Authors.Contains(authorMock.Object)); }