예제 #1
0
        public void GetAuthorCount_GetAuthorCount_AuthorCount()
        {
            // Arrange
            _allPublications.AddRange(_publicationsWithAuthor);
            _publicationsWithAuthor.FirstOrDefault().Favorites = new List <UserEntity>();
            _publicationsWithAuthor.FirstOrDefault().Favorites.Add(_author);
            var validPublicationCount   = 1;
            var inValidPublicationCount = 0;

            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.GetAuthorCount(_publicationsWithAuthor.FirstOrDefault().Id);

            // Assert
            Assert.NotEqual(inValidPublicationCount, result);
            Assert.Equal(validPublicationCount, result);
        }
예제 #2
0
        public void GetPublicationsWithFavorites_GetPublicationsByAuthorId_Publications()
        {
            // Arrange
            _allPublications.AddRange(_publicationsWithAuthor);
            foreach (var publication in _publicationsWithAuthor)
            {
                _author.Favorites.Add(publication);
            }

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

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

            getableUser.Setup(u => u.GetById(_author.Id))
            .Returns(_author);

            getablePublication.Setup(p => p.GetAllByAuthorId(_author.Id))
            .Returns(_publicationsWithAuthor);

            // Act
            var result = getFavorite.GetPublicationsWithFavorites(_author.Id);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(_publicationsWithAuthor, result);
            Assert.NotEqual(_allPublications, result);
            Assert.NotEqual(4, result.Count());
        }
예제 #3
0
        public void GetIsFavorite_GetIsFavoriteIfPublicationHaveNotFavoriteByAuthorId_False()
        {
            // Arrange
            var getablePublication = new Mock <IGetablePublication>();
            var getableUser        = new Mock <IGetableUser>();

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

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

            var favoriteDTO = new FavoriteDTO()
            {
                PublicationId = _publicationsWithAuthor.FirstOrDefault().Id,
                UserId        = Guid.NewGuid(),
            };

            // Act
            var result = getFavorite.GetIsFavorite(favoriteDTO);

            // Assert
            Assert.False(result);
        }
예제 #4
0
        public void GetIsFavorite_GetIsFavoriteIfPublicationContainFavoriteByAuthorId_True()
        {
            // Arrange
            _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(gp => gp.GetById(_publicationsWithAuthor.FirstOrDefault().Id))
            .Returns(_publicationsWithAuthor.FirstOrDefault());

            var favoriteDTO = new FavoriteDTO()
            {
                PublicationId = _publicationsWithAuthor.FirstOrDefault().Id,
                UserId        = _author.Id,
            };

            // Act
            var result = getFavorite.GetIsFavorite(favoriteDTO);

            // Assert
            Assert.True(result);
        }
예제 #5
0
        public void GetIsFavorite_GetIsFavoriteIfPublicationNotFound_ObjectNotFoundException()
        {
            // Arrange
            var getablePublication = new Mock <IGetablePublication>();
            var getableUser        = new Mock <IGetableUser>();

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

            getablePublication.Setup(gp => gp.GetById(_favoriteDTO.PublicationId))
            .Throws(new ObjectNotFoundException("Publication not found"));

            //Act
            Action act = () => getFavorite.GetIsFavorite(_favoriteDTO);

            // Assert
            Assert.Throws <ObjectNotFoundException>(act);
        }
예제 #6
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);
        }
예제 #7
0
        public void GetPublicationsWithFavorites_GetPublicationsByAuthorIdIfAuthorDontHaveFavorites_FavoritesNotFoundException()
        {
            // Arrange
            var getablePublication = new Mock <IGetablePublication>();
            var getableUser        = new Mock <IGetableUser>();

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

            getableUser.Setup(u => u.GetById(_author.Id))
            .Returns(_author);

            // Act
            Action act = () => getFavorite.GetPublicationsWithFavorites(_author.Id);

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