public async Task ReturnFalse_WhenTweetRepositoryTweetIsDeletedMethodReturnsFalse()
        {
            //Arrange
            var unitOfWorkMock      = new Mock <IUnitOfWork>();
            var mappingProviderMock = new Mock <IMappingProvider>();
            var userRepositoryMock  = new Mock <IUserRepository>();
            var tweetRepositoryMock = new Mock <ITweetRepository>();

            var userId  = "30";
            var tweetId = "1905";

            tweetRepositoryMock
            .Setup(x => x.UserTweetIsDeleted(userId, tweetId))
            .ReturnsAsync(false);

            var tweetService = new TweetService(
                unitOfWorkMock.Object,
                mappingProviderMock.Object,
                userRepositoryMock.Object,
                tweetRepositoryMock.Object);

            //Act
            var tweetIsDeleted = await tweetService.DeleteTweet(userId, tweetId);

            //Assert
            Assert.IsFalse(tweetIsDeleted);
        }
        public async Task CallSaveChangesOnce_WhenTweetSuccessfullyDeleted()
        {
            //Arrange
            var unitOfWorkMock      = new Mock <IUnitOfWork>();
            var mappingProviderMock = new Mock <IMappingProvider>();
            var userRepositoryMock  = new Mock <IUserRepository>();
            var tweetRepositoryMock = new Mock <ITweetRepository>();

            var userId  = "30";
            var tweetId = "1905";

            tweetRepositoryMock
            .Setup(x => x.UserTweetIsDeleted(userId, tweetId))
            .ReturnsAsync(true);

            var tweetService = new TweetService(
                unitOfWorkMock.Object,
                mappingProviderMock.Object,
                userRepositoryMock.Object,
                tweetRepositoryMock.Object);

            //Act
            var tweetIsDeleted = await tweetService.DeleteTweet(userId, tweetId);

            //Assert
            unitOfWorkMock.Verify(x => x.SaveChangesAsync(), Times.Once);
        }
 public ActionResult Delete([Bind(Include = "Id")] TweetViewModel model)
 {
     try {
         // TODO: Add delete logic here
         tweetService.DeleteTweet(model.Id);
         return(RedirectToAction("Index"));
     }
     catch {
         return(View());
     }
 }
        public void ThrowArgumentNullException_WhenInvokedWithInvalidEmptyTweetIdIdParameter()
        {
            //Arrange
            var unitOfWorkMock      = new Mock <IUnitOfWork>();
            var mappingProviderMock = new Mock <IMappingProvider>();
            var userRepositoryMock  = new Mock <IUserRepository>();
            var tweetRepositoryMock = new Mock <ITweetRepository>();

            var userId  = "30";
            var tweetId = "1905";

            tweetRepositoryMock
            .Setup(x => x.UserTweetIsDeleted(userId, tweetId))
            .ReturnsAsync(false);

            var tweetService = new TweetService(
                unitOfWorkMock.Object,
                mappingProviderMock.Object,
                userRepositoryMock.Object,
                tweetRepositoryMock.Object);

            //Act && Assert
            Assert.ThrowsExceptionAsync <ArgumentException>(() => tweetService.DeleteTweet(userId, string.Empty));
        }
Esempio n. 5
0
 public void Delete(string id)
 {
     _tweetService.DeleteTweet(id);
 }
Esempio n. 6
0
 public IHttpActionResult DeleteTweet(int id)
 {
     tweetService.DeleteTweet(id);
     return(Ok(id));
 }