Пример #1
0
        public void FavouritesCreate2_1()
        {
            IToken token = TokenSingleton.Instance;

            ITweet newTweet = new Tweet(String.Format("Favouriting tweet {0}", DateTime.Now), token);

            Assert.AreEqual(newTweet.Favourited, false);
            newTweet.Publish();
            Assert.AreEqual(newTweet.Favourited, false);
            newTweet.Destroy();
            Assert.AreEqual(newTweet.Favourited, false);
            newTweet.SetFavourite(true);
            Assert.AreEqual(newTweet.Favourited, false);

            newTweet.Destroy();
        }
Пример #2
0
        public void Tweet_PublishReply()
        {
            IToken token = TokenSingleton.Instance;

            // Create Tweet locally
            ITweet tweet = new Tweet(String.Format("Hello Tweetinvi {0}", DateTime.Now), token);

            // Send the Tweet
            bool result = tweet.Publish();

            Assert.AreEqual(result, true);

            ITweet reply = null;

            if (result)
            {
                reply = new Tweet(String.Format("Nice speech Tweetinvi {0}", DateTime.Now), token);

                result &= reply.PublishInReplyTo(tweet);
            }

            Assert.AreEqual(result, true);

            if (reply == null)
            {
                Assert.Fail();
            }

            Assert.AreEqual(reply.IsTweetPublished, true);

            tweet.Destroy();
            reply.Destroy();
        }
Пример #3
0
        public void Tweet_PublishWithBigURL()
        {
            IToken    token       = TokenSingleton.Instance;
            TokenUser currentUser = new TokenUser(token);

            string messageWithoutUrl = "Hello Tweetinvi! I believe that your API is great at this date of ("
                                       + DateTime.Now + ") - ";

            string messageUrl = "https://maps.google.com/?ie=UTF8&ll=51.502759,-0.13278&spn=" +
                                "0.03211,0.084543&t=h&z=14&vpsrc=6&iwloc=A" +
                                "&q=Saint+James+Park&cid=18398735506960162143";

            string bigString = messageWithoutUrl + messageUrl;

            Assert.AreEqual(messageWithoutUrl.Length < 140 - 22, true);
            Assert.AreEqual(messageUrl.Length > 22, true);
            Assert.AreEqual(bigString.Length > 140, true);

            // Create Tweet locally
            ITweet tweet = new Tweet(bigString, token);

            // Send the Tweet
            tweet.Publish();

            Assert.AreNotEqual(tweet.Id, null);
            Assert.AreEqual(currentUser.Equals(tweet.Creator), true);
            Assert.AreEqual(tweet.IsTweetPublished, true);

            tweet.Destroy();
        }
Пример #4
0
        public void Tweet_PublishReplyWithGeo2()
        {
            IToken token = TokenSingleton.Instance;

            // Create Tweet locally
            ITweet tweet = new Tweet(String.Format("Hello Tweetinvi {0}", DateTime.Now), token);

            // Send the Tweet
            bool result = tweet.Publish();

            Assert.AreEqual(result, true);

            ITweet reply = null;

            if (result)
            {
                reply = new Tweet(String.Format("Nice speech Tweetinvi {0}", DateTime.Now), token);
                const double latitude  = 37.7821120598956;
                const double longitude = -122.400612831116;

                result &= reply.PublishWithGeoInReplyTo(latitude, longitude, tweet.Id);
            }

            Assert.AreEqual(result, true);

            if (reply == null)
            {
                Assert.Fail();
            }

            Assert.AreEqual(reply.IsTweetPublished, true);

            tweet.Destroy();
            reply.Destroy();
        }
Пример #5
0
        public void FavouritesDefault()
        {
            IToken token = TokenSingleton.Instance;

            string text     = string.Format("Favouriting tweet {0}", DateTime.Now);
            ITweet newTweet = new Tweet(text, token);

            // When a Tweet has not been published it is not favourited
            Assert.AreEqual(newTweet.Favourited, false);
            newTweet.Publish();
            // This tweet is a published tweet
            Assert.AreEqual(newTweet.Favourited, false);

            // This tweet won't be able to get published
            ITweet newTweetCopy = new Tweet(text, token);

            newTweetCopy.Publish();
            Assert.AreEqual(newTweet.Favourited, false);

            ITweet existingTweet = new Tweet(newTweet.Id);

            // We currently don't know the value of favourite of this tweet
            // because no query has been performed
            Assert.AreEqual(existingTweet.Favourited, null);

            newTweet.Destroy();
        }
Пример #6
0
        public void Tweet_PublishTweet3()
        {
            // Create Tweet locally
            ITweet tweet = new Tweet(String.Format("Hello Tweetinvi {0}", DateTime.Now));

            // Send the Tweet
            tweet.Publish();

            Assert.AreEqual(tweet.Id, null);
            Assert.AreEqual(tweet.IsTweetPublished, true);

            tweet.Destroy();
        }
Пример #7
0
        public void Tweet_Destroy2()
        {
            IToken token = TokenSingleton.Instance;
            ITweet tweet = new Tweet(String.Format("Hello Tweetinvi {0}", DateTime.Now), token);

            Assert.AreEqual(tweet.IsTweetPublished, false);
            Assert.AreEqual(tweet.IsTweetDestroyed, false);

            tweet.Publish();

            Assert.AreEqual(tweet.IsTweetPublished, true);
            Assert.AreEqual(tweet.IsTweetDestroyed, false);

            bool result = tweet.Destroy();

            Assert.AreNotEqual(tweet.Id, null);
            Assert.AreEqual(result, true);
            Assert.AreEqual(tweet.IsTweetPublished, true);
            // Even if the Tweet has been destroyed the Tweet is still being published
            Assert.AreEqual(tweet.IsTweetDestroyed, true);

            result = tweet.Destroy();
            Assert.AreEqual(result, false);
        }
Пример #8
0
        public void GetFavourites1()
        {
            IToken token = TokenSingleton.Instance;

            string text = String.Format("Favouriting tweet {0}", DateTime.Now);

            // Create and favourite a first tweet
            ITweet newTweet = new Tweet(text, token);

            newTweet.Publish();
            newTweet.Favourited = true;

            IUser creator = newTweet.Creator;

            List <ITweet> favourites = creator.GetFavourites();

            Assert.AreEqual(favourites.Count, 1);
            Assert.AreEqual(favourites[0].Equals(newTweet), true);

            // Create and favourite a second tweet
            ITweet newTweet2 = new Tweet(text + " - bis", token);

            newTweet2.Publish();
            newTweet2.Favourited = true;

            favourites = creator.GetFavourites();

            Assert.AreEqual(favourites.Count, 2);
            Assert.AreEqual(favourites[0].Equals(newTweet2), true);
            Assert.AreEqual(favourites[1].Equals(newTweet), true);

            // Remove Favourite from first tweet
            newTweet.Favourited = false;

            favourites = creator.GetFavourites();
            Assert.AreEqual(favourites.Count, 1);
            Assert.AreEqual(favourites[0].Equals(newTweet2), true);

            // Destroy Second Tweet
            newTweet2.Destroy();

            favourites = creator.GetFavourites();
            Assert.AreEqual(favourites.Count, 0);

            // Cleanup test
            newTweet.Destroy();
        }
Пример #9
0
        public void FavouritesCreate5()
        {
            IToken token = TokenSingleton.Instance;

            ITweet newTweet = new Tweet(String.Format("Favouriting tweet {0}", DateTime.Now), token);

            Assert.AreEqual(newTweet.Favourited, false);
            newTweet.Publish();

            // Setting the value without token specified
            ITweet existingTweet = new Tweet(newTweet.Id);

            existingTweet.Favourited = true;
            Assert.AreEqual(existingTweet.Favourited, null);

            newTweet.Destroy();
        }
Пример #10
0
        public void Tweet_PublishTweet1()
        {
            IToken    token       = TokenSingleton.Instance;
            TokenUser currentUser = new TokenUser(token);

            // Create Tweet locally
            ITweet tweet = new Tweet(String.Format("Hello Tweetinvi {0}", DateTime.Now), token);

            // Send the Tweet
            tweet.Publish();

            Assert.AreNotEqual(tweet.Id, null);
            Assert.AreEqual(currentUser.Equals(tweet.Creator), true);
            Assert.AreEqual(tweet.IsTweetPublished, true);

            tweet.Destroy();
        }
Пример #11
0
        public void Tweet_RePublish()
        {
            IToken token = TokenSingleton.Instance;

            // Create Tweet locally
            ITweet tweet  = new Tweet(String.Format("Hello Tweetinvi {0}", DateTime.Now), token);
            bool   result = tweet.Publish();

            Assert.AreEqual(result, true);

            // Republishing a tweet is not allowed
            result &= tweet.Publish();
            Assert.AreEqual(result, false);
            Assert.AreEqual(tweet.IsTweetPublished, true);

            tweet.Destroy();
        }
Пример #12
0
        public void StartStreamTrackRandomUniqueWord()
        {
            // Arrange
            var  randomWord      = String.Format("Tweetinvi{0}", new Random().Next());
            var  expectedMessage = String.Format("Hello {0}", randomWord);
            bool result          = false;

            Thread t = new Thread(() =>
            {
                IFilteredStream stream = new FilteredStream();

                stream.AddTrack(randomWord);

                Func <ITweet, bool> listen = delegate(ITweet tweet)
                {
                    if (tweet != null)
                    {
                        result = tweet.Text == expectedMessage;
                    }

                    // End the stream
                    return(false);
                };

                stream.StartStream(TokenSingleton.Token, listen);
            });

            t.Start();

            // Act
            ITweet newTweet = new Tweet(expectedMessage, TokenTestSingleton.Instance);

            newTweet.Publish();

            Thread.Sleep(500);
            t.Join();

            // Assert
            Assert.AreEqual(result, true);

            // Cleanup
            newTweet.Destroy();
        }
Пример #13
0
        public void Tweet_Destroy3()
        {
            IToken token = TokenSingleton.Instance;
            ITweet tweet = new Tweet(String.Format("Hello Tweetinvi {0}", DateTime.Now), token);

            Assert.AreEqual(tweet.IsTweetPublished, false);
            Assert.AreEqual(tweet.IsTweetDestroyed, false);

            tweet.Publish();
            long?currentTweetId = tweet.Id;

            Assert.AreEqual(tweet.IsTweetPublished, true);
            Assert.AreEqual(tweet.IsTweetDestroyed, false);

            bool result = tweet.Destroy();

            Assert.AreNotEqual(tweet.Id, null);
            Assert.AreEqual(result, true);
            Assert.AreEqual(tweet.IsTweetPublished, true);
            // Even if the Tweet has been destroyed the Tweet is still being published
            Assert.AreEqual(tweet.IsTweetDestroyed, true);

            bool objectExist = true;

            try
            {
                // ReSharper disable UnusedVariable
                ITweet destroyedTweet = new Tweet(currentTweetId, token);
                // ReSharper restore UnusedVariable

                Assert.Fail();
            }
            catch (Exception ex)
            {
                if (ex.Message == String.Format("Tweet[{0}] does not exist!", currentTweetId))
                {
                    objectExist = false;
                }
            }

            Assert.AreEqual(objectExist, false);
        }
Пример #14
0
        // [TestMethod]
        public void ClearFavourites()
        {
            Tweet t = new Tweet("hello", TokenSingleton.Instance);

            t.Publish();
            IUser u = t.Creator;

            t.Destroy();

            List <ITweet> favourites = u.GetFavourites(200);

            do
            {
                foreach (var favourite in favourites)
                {
                    favourite.Destroy();
                }

                favourites = u.GetFavourites(200);
            } while (favourites.Count != 0);
        }
Пример #15
0
        public void FavouritesCreate3()
        {
            IToken token = TokenSingleton.Instance;

            ITweet newTweet = new Tweet(String.Format("Favouriting tweet {0}", DateTime.Now), token);

            Assert.AreEqual(newTweet.Favourited, false);
            newTweet.Publish();
            Assert.AreEqual(newTweet.Favourited, false);
            newTweet.Favourited = true;
            Assert.AreEqual(newTweet.Favourited, true);
            newTweet.Favourited = false;
            Assert.AreEqual(newTweet.Favourited, false);

            // Getting the item we have just created
            ITweet existingTweet = new Tweet(newTweet.Id, token);

            existingTweet.Favourited = true;
            Assert.AreEqual(existingTweet.Favourited, true);

            newTweet.Destroy();
        }
Пример #16
0
        public void FavouritesCreate4()
        {
            IToken token = TokenSingleton.Instance;

            ITweet newTweet = new Tweet(String.Format("Favouriting tweet {0}", DateTime.Now), token);

            Assert.AreEqual(newTweet.Favourited, false);
            newTweet.Publish();
            Assert.AreEqual(newTweet.Favourited, false);
            newTweet.Favourited = true;
            Assert.AreEqual(newTweet.Favourited, true);
            newTweet.Favourited = false;
            Assert.AreEqual(newTweet.Favourited, false);

            // Setting the value even though we don't know what is the current value
            ITweet existingTweet = new Tweet(newTweet.Id);

            existingTweet.ObjectToken = token;
            existingTweet.Favourited  = true;
            Assert.AreEqual(existingTweet.Favourited, true);

            newTweet.Destroy();
        }
Пример #17
0
        public void Tweet_PublishTweetWithGeo2()
        {
            // Create Tweet locally
            ITweet tweet = new Tweet(String.Format("Hello Tweetinvi With Geo {0}", DateTime.Now), TokenSingleton.Instance);

            double latitude  = 37.7821120598956;
            double longitude = -122.400612831116;

            // Send the Tweet
            tweet.PublishWithGeo(latitude, longitude, true);

            // Twitter stores a location to a precision of 8
            double latitude_result  = Math.Round(latitude, 8);
            double longitude_result = Math.Round(longitude, 8);

            Assert.AreNotEqual(tweet.Id, null);
            Assert.AreEqual(tweet.IsTweetPublished, true);
            Assert.AreEqual(tweet.Location.GeoCoordinates.Lattitude, latitude_result);
            Assert.AreEqual(tweet.Location.GeoCoordinates.Longitude, longitude_result);
            Assert.AreEqual(tweet.LocationCoordinates.Lattitude, latitude_result);
            Assert.AreEqual(tweet.LocationCoordinates.Longitude, longitude_result);

            tweet.Destroy();
        }
Пример #18
0
        public void FavouritesBetweenIds1()
        {
            IToken token = TokenSingleton.Instance;

            string text = String.Format("Favouriting tweet {0}", DateTime.Now);

            // Create and favourite a first tweet
            ITweet tweet1 = new Tweet(text, token);

            tweet1.Publish();
            tweet1.Favourited = true;

            ITweet tweet2 = new Tweet(text + " - 2", token);

            tweet2.Publish();
            tweet2.Favourited = true;

            ITweet tweet3 = new Tweet(text + " - 3", token);

            tweet3.Publish();
            tweet3.Favourited = true;

            IUser creator = tweet1.Creator;

            // Checking that the 2 functions return the same thing
            List <ITweet> favouritesIncludingBothTweet   = creator.GetFavouritesBetweenIds(tweet1, tweet3, 20, true, true);
            List <ITweet> favouritesIncludingBothTweetId = creator.GetFavouritesBetweenIds(tweet1.Id, tweet3.Id, 20, true, true);

            Assert.AreEqual(favouritesIncludingBothTweet.Count, 3);
            Assert.AreEqual(favouritesIncludingBothTweetId.Count, 3);

            for (int i = 0; i < favouritesIncludingBothTweet.Count; ++i)
            {
                Assert.AreEqual(favouritesIncludingBothTweet[i].Equals(favouritesIncludingBothTweetId[i]), true);
            }

            // Checking the result of until and since
            List <ITweet> favouritesIncludingSourceTweet = creator.GetFavouritesBetweenIds(tweet1, tweet3, 20, true, false);
            List <ITweet> favouritesIncludingUntilTweet  = creator.GetFavouritesBetweenIds(tweet1, tweet3, 20, false, true);

            Assert.AreEqual(favouritesIncludingSourceTweet.Count, 2);
            Assert.AreEqual(favouritesIncludingUntilTweet.Count, 2);

            Assert.AreEqual(favouritesIncludingSourceTweet[0].Equals(tweet2), true);
            Assert.AreEqual(favouritesIncludingSourceTweet[1].Equals(tweet1), true);

            Assert.AreEqual(favouritesIncludingUntilTweet[0].Equals(tweet3), true);
            Assert.AreEqual(favouritesIncludingUntilTweet[1].Equals(tweet2), true);

            // Analyzing the result
            List <ITweet> favouritesSinceTweet = creator.GetFavouritesBetweenIds(tweet1, tweet3);
            List <ITweet> favouritesSinceId    = creator.GetFavouritesBetweenIds(tweet1.Id, tweet3.Id);

            Assert.AreEqual(favouritesSinceTweet.Count, favouritesSinceId.Count);

            for (int i = 0; i < favouritesSinceTweet.Count; ++i)
            {
                Assert.AreEqual(favouritesSinceTweet[i].Equals(favouritesSinceId[i]), true);
            }

            Assert.AreEqual(favouritesSinceTweet.Count, 1);
            Assert.AreEqual(favouritesSinceTweet[0].Equals(tweet2), true);

            // Checking after Tweet1 deletion
            tweet3.Destroy();

            favouritesSinceTweet = creator.GetFavouritesBetweenIds(tweet1, tweet3);

            Assert.AreEqual(favouritesSinceTweet.Count, 1);
            Assert.AreEqual(favouritesSinceTweet[0].Equals(tweet2), true);

            tweet1.Destroy();

            favouritesSinceTweet = creator.GetFavouritesBetweenIds(tweet1, tweet3);

            Assert.AreEqual(favouritesSinceTweet.Count, 1);
            Assert.AreEqual(favouritesSinceTweet[0].Equals(tweet2), true);

            tweet2.Destroy();

            favouritesSinceTweet = creator.GetFavouritesBetweenIds(tweet1, tweet3);

            Assert.AreEqual(favouritesSinceTweet.Count, 0);
        }
Пример #19
0
        public void StartStreamTrackWord1ORWord2InTheSameTweet()
        {
            // Arrange
            var randomWord1 = String.Format("Tweetinvi{0}", new Random().Next());
            var randomWord2 = String.Format("Tweetinvi2{0}", new Random().Next());

            var expectedMessage1 = String.Format("Hello {0}", randomWord1);
            var expectedMessage2 = String.Format("Hello {0}", randomWord2);
            var expectedMessage3 = String.Format("Hello {0} {1}", randomWord1, randomWord2);

            int i = 0;

            Thread t = new Thread(() =>
            {
                IFilteredStream stream = new FilteredStream();

                stream.AddTrack(randomWord1);
                stream.AddTrack(randomWord2);

                Func <ITweet, bool> listen = delegate(ITweet tweet)
                {
                    if (tweet != null)
                    {
                        bool result = tweet.Text == expectedMessage1 ||
                                      tweet.Text == expectedMessage2 ||
                                      tweet.Text == expectedMessage3;

                        if (result)
                        {
                            Debug.WriteLine(tweet.Text);
                            ++i;
                        }
                    }

                    // End the stream
                    return(true);
                };

                Timer timer    = new Timer(5000);
                timer.Elapsed += (sender, args) =>
                {
                    timer.Stop();
                    stream.StopStream();
                };

                timer.Start();

                stream.StartStream(TokenSingleton.Token, listen);
            });

            t.Start();

            // Act
            ITweet newTweet1 = new Tweet(expectedMessage1, TokenTestSingleton.Instance);

            newTweet1.Publish();

            ITweet newTweet2 = new Tweet(expectedMessage2, TokenTestSingleton.Instance);

            newTweet2.Publish();

            ITweet newTweet3 = new Tweet(expectedMessage3, TokenTestSingleton.Instance);

            newTweet3.Publish();

            t.Join();

            // Cleanup
            newTweet1.Destroy();
            newTweet2.Destroy();
            newTweet3.Destroy();

            // Assert
            Assert.AreEqual(i, 3);
        }