public async Task TrackTopEmojiMetric()
        {
            List <Tweet> list = new List <Tweet>();

            for (int x = 0; x < _emojis.Count(); x++)
            {
                list.Add(new Tweet {
                    text = $"this is a tweet {_emojis.ElementAt(x).unified}!", created_at = DateTime.Now
                });
            }
            _repository.Setup(x => x.GetAll <Tweet>()).Returns(Task.FromResult((IEnumerable <Tweet>)list));

            var emojis = list.SelectMany(t => GetEmojis(t.text)).GroupBy(e => e.unified).GroupBy(g => (Text: g.Key, Count: g.Count())).OrderByDescending(h => h.Key.Count).Take(10).Select(h => h.Key).ToList();

            var expected = emojis.Select(h => new Metric {
                Key = h.Text, Value = h.Count
            }).ToList();

            var result = (IEnumerable <Metric>) await topEmojiMetric.GetMetric();

            Assert.AreEqual(expected.Count(), result.Count());
            for (var x = 0; x < expected.Count(); x++)
            {
                Assert.AreEqual(expected.ElementAt(x).Key, result.ElementAt(x).Key);
                Assert.AreEqual(expected.ElementAt(x).Value, result.ElementAt(x).Value);
            }
        }
        public async Task TrackPhotoPercentageMetric()
        {
            decimal picDomainCount = _url.Where(u => _settings.Object.Value.PhotoDomains.Split(",").Any(d => u.display_url.Contains(d))).Count();
            var     percentage     = (picDomainCount / _list.Count());

            Assert.AreEqual(percentage.ToString("p"), await photoPercentageMetric.GetMetric());
        }
        public async Task TrackTweetsPerHour()
        {
            _metricSource.Setup(x => x.Tweets).Returns(_list);
            var duration = _list.Where(t => t.created_at >= _list.Max(t => t.created_at).AddHours(-1)).Count();

            Assert.AreEqual(duration, await tweetsPerHourMetric.GetMetric());
        }
        public async Task TrackEmojiPercentageMetric()
        {
            List <Tweet> list = new List <Tweet>();

            for (int x = 0; x < _emojis.Count(); x++)
            {
                list.Add(new Tweet {
                    text = $"this is a tweet {_emojis.ElementAt(x).unified}!", created_at = DateTime.Now
                });
            }
            _repository.Setup(x => x.GetAll <Tweet>()).Returns(Task.FromResult((IEnumerable <Tweet>)list));
            decimal percentage = ((decimal)_emojis.Count() / list.Count());

            Assert.AreEqual(percentage.ToString("p"), await emojiPercentageMetric.GetMetric());
        }
        public async Task TrackTopHashtagMetric()
        {
            var hashtags = _hashtags.GroupBy(h => h.tag).GroupBy(group => new { Text = System.Web.HttpUtility.HtmlDecode(group.Key), Count = group.Count() }).OrderByDescending(h => h.Key.Count).Take(10).Select(h => h.Key);
            var expected = hashtags.Select(h => new Metric {
                Key = h.Text, Value = h.Count
            }).ToList();

            var result = (IEnumerable <Metric>) await topHashtagMetric.GetMetric();

            Assert.AreEqual(expected.Count(), result.Count());
            for (var x = 0; x < expected.Count(); x++)
            {
                Assert.AreEqual(expected.ElementAt(x).Key, result.ElementAt(x).Key);
                Assert.AreEqual(expected.ElementAt(x).Value, result.ElementAt(x).Value);
            }
        }
        public async Task TrackTopDomainMetric()
        {
            var domains  = _url.Where(u => { return(Uri.IsWellFormedUriString(u.expanded_url, UriKind.Absolute)); }).GroupBy(u => new Uri(u.expanded_url).Host).GroupBy(g => new { Text = g.Key, Count = g.Count() }).OrderByDescending(h => h.Key.Count).Take(10).Select(h => h.Key);
            var expected = domains.Select(h => new Metric {
                Key = h.Text, Value = h.Count
            });
            var result = (IEnumerable <Metric>) await topDomainMetric.GetMetric();


            Assert.AreEqual(expected.Count(), result.Count());
            for (var x = 0; x < expected.Count(); x++)
            {
                Assert.AreEqual(expected.ElementAt(x).Key, result.ElementAt(x).Key);
                Assert.AreEqual(expected.ElementAt(x).Value, result.ElementAt(x).Value);
            }
        }
        public async Task TrackPhotoPercentageMetric_NoSettings()
        {
            IEnumerable <Tweet> list = new List <Tweet>();

            _settings.Reset();
            photoPercentageMetric = new PhotoPercentageMetric(_metricSource.Object, _settings.Object);
            Assert.AreEqual(null, await photoPercentageMetric.GetMetric());
        }
        public async Task TrackUrlsPercentageMetric()
        {
            decimal percentage = ((decimal)_url.Count() / _list.Count());

            Assert.AreEqual(percentage.ToString("p"), await urlsPercentageMetric.GetMetric());
        }
 public async Task TrackNumberOfTweets()
 {
     Assert.AreEqual(_list.Count(), await totalTweetsMetric.GetMetric());
 }