Example #1
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);
        }
Example #2
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);
        }
Example #3
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);
        }