public void Change_Deleted_State_Of_Tag_When_Tweet_Exist_But_Deleted()
        {
            //Arrange
            var fakeUnit         = new Mock <IUnitOfWork>();
            var dateTimeProvider = new TestDateTimeProvider();
            var fakeTweetService = new Mock <ITweetService>();
            var sut = new UserTweetService(fakeUnit.Object, fakeTweetService.Object, dateTimeProvider);

            var fakeUserTweetRepo = new Mock <IGenericRepository <UserTweet> >();
            var fakeTweetRepo     = new Mock <IGenericRepository <Tweet> >();
            var fakeTweetTagRepo  = new Mock <IGenericRepository <TweetTag> >();

            var tweet = new Tweet {
                TweetId = "456", IsDeleted = true, DeletedOn = dateTimeProvider.DeletedOn
            };
            var tweetCollection = new List <Tweet> {
                tweet
            };
            var testTag1 = new Tag {
                Id = 1, IsDeleted = true, DeletedOn = dateTimeProvider.DeletedOn
            };
            var testTag2 = new Tag {
                Id = 2, IsDeleted = true, DeletedOn = dateTimeProvider.DeletedOn
            };
            var testTweetTag1 = new TweetTag {
                TweetId = tweet.TweetId, TagId = testTag1.Id, Tag = testTag1, IsDeleted = true, DeletedOn = dateTimeProvider.DeletedOn
            };
            var testTweetTag2 = new TweetTag {
                TweetId = tweet.TweetId, TagId = testTag2.Id, Tag = testTag2, IsDeleted = true, DeletedOn = dateTimeProvider.DeletedOn
            };
            var tweetTagCollection = new List <TweetTag> {
                testTweetTag1, testTweetTag2
            };

            fakeUnit.Setup(u => u.UserTweets).Returns(fakeUserTweetRepo.Object);
            fakeUnit.Setup(u => u.TweetTags).Returns(fakeTweetTagRepo.Object);
            fakeTweetRepo.Setup(r => r.AllAndDeleted).Returns(tweetCollection.AsQueryable());
            fakeTweetTagRepo.Setup(r => r.AllAndDeleted).Returns(tweetTagCollection.AsQueryable());
            fakeUnit.Setup(u => u.Tweets).Returns(fakeTweetRepo.Object);

            //Act
            sut.SaveSingleTweetToUserByTweetId("123", "456");

            //Assert
            Assert.IsFalse(testTag1.IsDeleted);
            Assert.IsNull(testTag1.DeletedOn);
            Assert.IsFalse(testTag2.IsDeleted);
            Assert.IsNull(testTag2.DeletedOn);
        }
Ejemplo n.º 2
0
        public void Invoke_AnyTweetSavedThisTagById_In_Same_Method_When_TweetTag_Found()
        {
            //Arrange
            var fakeUnit             = new Mock <IUnitOfWork>();
            var fakeDateTimeProvider = Mock.Of <IDateTimeProvider>();
            var fakeTagService       = Mock.Of <ITagService>();

            var sut = new FakeTweetTagService(fakeUnit.Object, fakeTagService, fakeDateTimeProvider);

            var fakeTweetTagRepo = new Mock <IGenericRepository <TweetTag> >();
            var tweetTag         = new TweetTag {
                TweetId = "TestTweetId1", TagId = 1
            };
            var tweetTagsCollection = new List <TweetTag> {
                tweetTag
            };

            fakeTweetTagRepo.Setup(r => r.All).Returns(tweetTagsCollection.AsQueryable());
            fakeUnit.Setup(u => u.TweetTags).Returns(fakeTweetTagRepo.Object);
            fakeUnit.Setup(s => s.SaveChanges()).Verifiable();

            //Act && Assert
            Assert.ThrowsException <FakeTestException>(() => sut.DeleteTweetTag(tweetTag.TagId, tweetTag.TweetId));
        }