public void CanCountUserMentions()
        {
            var tweets = new Tweet[]
            {
                new Tweet { Name = "N1", Text = "@user1 @user2" },
                new Tweet { Name = "N2", Text = "test1" },
                new Tweet { Name = "N3", Text = "test1" },
                new Tweet { Name = "N1", Text = "@user3" },
                new Tweet { Name = "N1", Text = "test1" },
                new Tweet { Name = "N2", Text = "@user4" }
            }.AsQueryable();

            var accounts = from t in tweets
                           group t by t.Name into account
                           select new TweetAccount
                           {
                               Name = account.Key,
                               TotalNumberOfTweets = account.Count(),
                               TotalNumberOfOtherUserMentions = account.Sum(x => x.Text.Count(u => u == '@'))
                           };

            Assert.AreEqual(3, accounts.Single(x => x.Name == "N1").TotalNumberOfOtherUserMentions);
            Assert.AreEqual(1, accounts.Single(x => x.Name == "N2").TotalNumberOfOtherUserMentions);
            Assert.AreEqual(0, accounts.Single(x => x.Name == "N3").TotalNumberOfOtherUserMentions);
        }
        public void CanSetTextOnNewTweetEntity()
        {
            var tweet = new Tweet();
            tweet.Text = "testing tweet text";

            Assert.AreEqual("testing tweet text", tweet.Text);
        }
        public void CanSetNameOnNewTweetEntity()
        {
            var tweet = new Tweet();
            tweet.Name = "pay_by_phone";

            Assert.AreEqual("pay_by_phone", tweet.Name);
        }
        public void CanSetCreatedDateOnNewTweetEntity()
        {
            var tweet = new Tweet();

            tweet.CreatedDate = DateTime.UtcNow;

            Assert.AreEqual(DateTime.UtcNow.Date, tweet.CreatedDate.Date);
        }
        public void CanProvideNumberOfUserMentionsPerAccount()
        {
            var tweets = new Tweet[]
            {
                new Tweet { Name = "N1", Text = "@user1 @user2" },
                new Tweet { Name = "N2", Text = "test1" },
                new Tweet { Name = "N3", Text = "test1" },
                new Tweet { Name = "N1", Text = "@user3" },
                new Tweet { Name = "N1", Text = "test1" },
                new Tweet { Name = "N2", Text = "@user4" }
            }.AsQueryable();

            Mock<ITwitterService> mock = new Mock<ITwitterService>();
            mock.Setup(m => m.GetTweets()).Returns(tweets);

            var api = new DataController(mock.Object);
            var data = api.Get();

            Assert.AreEqual(3, data.Accounts.Single(x => x.Name == "N1").TotalNumberOfOtherUserMentions);
            Assert.AreEqual(1, data.Accounts.Single(x => x.Name == "N2").TotalNumberOfOtherUserMentions);
            Assert.AreEqual(0, data.Accounts.Single(x => x.Name == "N3").TotalNumberOfOtherUserMentions);
        }
        public void CanProvideTotalNumberOfTweetsPerAccount()
        {
            var tweets = new Tweet[]
            {
                new Tweet { Name = "N1" },
                new Tweet {  Name = "N2" },
                new Tweet {  Name = "N3" },
                new Tweet { Name = "N1" },
                new Tweet { Name = "N1" },
                new Tweet {  Name = "N2" }
            }.AsQueryable();

            //Mock<ITwitterService> mock = new Mock<ITwitterService>();
            //mock.Setup(m => m.GetTweets()).Returns(tweets);

            var api = new DataController(/*mock.Object*/ new FakeTwitterService());
            var data = api.Get();

            Assert.AreEqual(3, data.Accounts.Single(x => x.Name == "N1").TotalNumberOfTweets);
            Assert.AreEqual(2, data.Accounts.Single(x => x.Name == "N2").TotalNumberOfTweets);
            Assert.AreEqual(1, data.Accounts.Single(x => x.Name == "N3").TotalNumberOfTweets);
        }