Ejemplo n.º 1
0
        public void AddBookCopy_RepositoryAcceptsInput_AddsBookCopy()
        {
            _dataService = new DataService(_repoMock.Object, _dateProviderMock.Object);

            _dataService.AddBookCopy(_books[0], BookCopy.States.New, 10.0);

            Predicate <BookCopy> validator = e =>
                                             e.Book == _books[0] &&
                                             e.State == BookCopy.States.New &&
                                             e.BasePrice == 10.0;

            _repoMock.Verify(
                repo => repo.AddBookCopy(Match.Create <BookCopy>(validator)),
                Times.Once()
                );
        }
Ejemplo n.º 2
0
        public void AddBookCopy_RepositoryThrowsException_ThrowsException()
        {
            _repoMock
            .Setup(repo => repo.AddBookCopy(It.IsAny <BookCopy>()))
            .Throws(new DataException("Test data exception!"));

            _dataService = new DataService(_repoMock.Object, _dateProviderMock.Object);

            var exception = Assert.ThrowsException <DataServiceException>(
                () => _dataService.AddBookCopy(_books[0], BookCopy.States.New, 10.0)
                );

            Assert.IsInstanceOfType(exception.InnerException, typeof(DataException));

            Predicate <BookCopy> validator = e =>
                                             e.Book == _books[0] &&
                                             e.State == BookCopy.States.New &&
                                             e.BasePrice == 10.0;

            _repoMock.Verify(
                repo => repo.AddBookCopy(Match.Create <BookCopy>(validator)),
                Times.Once()
                );
        }