예제 #1
0
        public void GetAuthors_GetAuthorsByPublicationId_Authors()
        {
            // Arrange
            _allPublications.AddRange(_publicationsWithAuthor);
            _publicationsWithAuthor.FirstOrDefault().Favorites.Add(_author);

            var getablePublication = new Mock <IGetablePublication>();
            var getableUser        = new Mock <IGetableUser>();

            var getFavorite = new GetFavorite(
                getablePublication.Object,
                getableUser.Object);

            getablePublication.Setup(p => p.GetById(_publicationsWithAuthor.FirstOrDefault().Id))
            .Returns(_publicationsWithAuthor.FirstOrDefault());

            getableUser.Setup(p => p.GetAll())
            .Returns(new List <UserEntity>()
            {
                _author, new UserEntity()
            });

            // Act
            var result = getFavorite.GetAuthors(_publicationsWithAuthor.FirstOrDefault().Id);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(_author, result.FirstOrDefault());
        }
예제 #2
0
        public void GetAuthors_GetAuthorsIfPublicationDontHaveFavorites_FavoritesNotFoundException()
        {
            // Arrange
            var getablePublication = new Mock <IGetablePublication>();
            var getableUser        = new Mock <IGetableUser>();

            var getFavorite = new GetFavorite(
                getablePublication.Object,
                getableUser.Object);

            getablePublication.Setup(p => p.GetById(_publications.FirstOrDefault().Id))
            .Returns(_publications.FirstOrDefault());

            // Act
            Action act = () => getFavorite.GetAuthors(_publications.FirstOrDefault().Id);

            // Assert
            Assert.Throws <FavoritesNotFoundException>(act);
        }