public async Task TestTwitterStorage()
        {
            IDataParser Parser = DataParserFactory.CreateParser("Twitter", "#freebandnames");

            Assert.IsNotNull(Parser);

            Assert.IsInstanceOfType(Parser, typeof(IDataParser), $"{nameof(Parser)} must inherit {nameof(IDataParser)}");
            Assert.IsInstanceOfType(Parser, typeof(DataParserBase), $"{nameof(Parser)} must inherit {nameof(DataParserBase)}");
            Assert.IsInstanceOfType(Parser, typeof(TwitterParser), $"{nameof(Parser)} must be a {nameof(DataParser.DataParsers.TwitterParser)}");

            Assert.IsNotNull(Parser.ProviderName, $"{nameof(Parser.ProviderName)} must have a value assigned (\"Twitter\").");
            Assert.AreEqual(Parser.ProviderName, "Twitter", $"{nameof(Parser.ProviderName)} must have a value (\"Twitter\").");

            Assert.IsNotNull(Parser.SearchTerm, $"{nameof(Parser.SearchTerm)} must have a value assigned (\"#freebandnames\").");
            Assert.AreEqual("#freebandnames", Parser.SearchTerm, $"{Parser.SearchTerm} must have a value (\"#freebandnames\").");

            TwitterParser TwitterParser = (TwitterParser)Parser;

            DataModel Model = TwitterParser.ParseResult(Resources.SampleTwitterJson);

            Assert.IsNotNull(Model, $"{nameof(Model)} must not be null. This indicates that {nameof(TwitterParser.ParseResult)} failed.");

            using (HttpClient Client = new HttpClient())
            {
                string JsonModel = new JavaScriptSerializer().Serialize(Model);
                Assert.IsNotNull(JsonModel, $"{JsonModel} must be a valid JSON string.");

                StringContent       Content         = new StringContent(JsonModel, Encoding.UTF8, "application/json");
                HttpResponseMessage ResponseMessage = await Client.PostAsync("http://localhost:46778/News", Content);

                Assert.IsTrue(ResponseMessage.IsSuccessStatusCode, $"{ResponseMessage.IsSuccessStatusCode} must be true. Otherwise it indicates a failed REST POST request.");
            }
        }
Exemple #2
0
        public void ParseReadableTests([ValueSource("_files")] string file)
        {
            var html = ReadFile(file);

            using (ApprovalResults.ForScenario(file))
            {
                var output = TwitterParser.MapResults(html);
                Approvals.Verify(output.String);
            }
        }
        public void can_parse_who_are_with_1_parameter_but_returning_nothing()
        {
            var ids = new long[] { 1 };
            var twitter = new Mock<ITwitter>();
            twitter.Setup(x => x.UserLookup(ids)).Returns(@"<users></users>");

            var parser = new TwitterParser(twitter.Object);
            parser.WhoAre(ids).Should().Be.Empty();

            twitter.VerifyAll();
        }
        public void can_parse_who_are_with_1_user_with_followers_count()
        {
            var ids = new long[] { 42 };
            var twitter = new Mock<ITwitter>();
            twitter.Setup(x => x.UserLookup(ids)).Returns(
                @"<users>
                    <user><id>42</id><name>Ford Prefect</name><screen_name>ford42</screen_name><followers_count>421</followers_count><friends_count>422</friends_count></user>
                </users>");

            var parser = new TwitterParser(twitter.Object);
            parser.WhoAre(ids).Should().Have.SameSequenceAs(new UserProfile(42, "Ford Prefect", "ford42", 421, 422));

            twitter.VerifyAll();
        }
        public void cannot_parse_who_are_with_4_users_using_max_per_request_equals_1_and_max_requests_per_call_equals_3()
        {
            var twitter = new Mock<ITwitter>();
            twitter.Setup(x => x.UserLookup(new long[] { 42 })).Returns(@"<users></users>");
            twitter.Setup(x => x.UserLookup(new long[] { 43 })).Returns(@"<users></users>");
            twitter.Setup(x => x.UserLookup(new long[] { 44 })).Returns(@"<users></users>");

            var parser = new TwitterParser(twitter.Object, 3);

            Executing.This(()=> {
                parser.WhoAre(new long[] { 42, 43, 44, 45 }, 1).ToList();
            }).Should().Throw<InvalidOperationException>();

            twitter.VerifyAll();
        }
Exemple #6
0
        private static void TestGuessing(int count)
        {
            var allQuestionsAndAnswers = TwitterParser.ParseQuestionsAndAnswerses();
            var questionsAndAnswersSet = allQuestionsAndAnswers.Take(count).ToList();

            var countCorrect = 0;

            foreach (var q in questionsAndAnswersSet)
            {
                var result = FigureOutRightAnswer(q.Question, q.Answer1, q.Answer2, q.Answer3);
                if (result.StartsWith(q.CorrectAnswer.ToString()))
                {
                    countCorrect++;
                }
            }
            Console.WriteLine("Success Rate = " + countCorrect + " of " + questionsAndAnswersSet.Count);
            Console.ReadKey();
        }
        public static void Update()
        {
            // make this a critical section to ensure that access is serial
            lock (locker)
            {
                UpdateStarted(null, EventArgs.Empty);

                TwitterParser <Tweet> _twitterParser = new TwitterParser <Tweet>(Constants.TwitterUrl);

                _isUpdating = true;
                _twitterParser.Refresh(delegate {
                    var tweets = _twitterParser.AllItems;

                    DAL.DataManager.DeleteTweets();
                    DAL.DataManager.SaveTweets(tweets);

                    UpdateFinished(null, EventArgs.Empty);
                    _isUpdating = false;
                });
            }
        }
		public static void Update()
		{
			// make this a critical section to ensure that access is serial
			lock(locker)
			{
				UpdateStarted (null, EventArgs.Empty);

				TwitterParser<Tweet> _twitterParser = new TwitterParser<Tweet>(Constants.TwitterUrl);

				_isUpdating = true;
				_twitterParser.Refresh(delegate {
					var tweets = _twitterParser.AllItems;	
					
					DAL.DataManager.DeleteTweets ();
					DAL.DataManager.SaveTweets (tweets);

					UpdateFinished (null, EventArgs.Empty);
					_isUpdating = false;
				});
			}
		}
        public void TestTwitterParser()
        {
            IDataParser Parser = DataParserFactory.CreateParser("Twitter", "#freebandnames");

            Assert.IsNotNull(Parser);

            Assert.IsInstanceOfType(Parser, typeof(IDataParser), $"{nameof(Parser)} must inherit {nameof(IDataParser)}");
            Assert.IsInstanceOfType(Parser, typeof(DataParserBase), $"{nameof(Parser)} must inherit {nameof(DataParserBase)}");
            Assert.IsInstanceOfType(Parser, typeof(TwitterParser), $"{nameof(Parser)} must be a {nameof(DataParsers.TwitterParser)}");

            Assert.IsNotNull(Parser.ProviderName, $"{nameof(Parser.ProviderName)} must have a value assigned (\"Twitter\").");
            Assert.AreEqual(Parser.ProviderName, "Twitter", $"{nameof(Parser.ProviderName)} must have a value (\"Twitter\").");

            Assert.IsNotNull(Parser.SearchTerm, $"{nameof(Parser.SearchTerm)} must have a value assigned (\"#freebandnames\").");
            Assert.AreEqual("#freebandnames", Parser.SearchTerm, $"{Parser.SearchTerm} must have a value (\"#freebandnames\").");

            TwitterParser TwitterParser = (TwitterParser)Parser;

            DataModel Model = TwitterParser.ParseResult(Resources.SampleTwitterJson);

            Assert.IsNotNull(Model, $"{nameof(Model)} must not be null. This indicates that {nameof(TwitterParser.ParseResult)} failed.");

            Assert.IsNotNull(Model.SearchTerm, $"{nameof(Model.SearchTerm)} must have a value assigned (\"#freebandnames\").");
            Assert.AreEqual(Model.SearchTerm, TwitterParser.SearchTerm, $"{nameof(Model.SearchTerm)} and {nameof(TwitterParser.SearchTerm)} must have equal values.");

            Assert.IsNotNull(Model.Message, $"{nameof(Model.Message)} must have a value (\"Aggressive Ponytail #freebandnames\").");
            Assert.AreEqual(Model.Message, "Aggressive Ponytail #freebandnames");

            Assert.IsNotNull(Model.Date, $"{nameof(Model.Date)} must have a value (Mon Sep 24 03:35:21 +0000 2012).");
            Assert.AreEqual(Model.Date,
                            DateTime.ParseExact("Mon Sep 24 03:35:21 +0000 2012", "ddd MMM dd HH:mm:ss +ffff yyyy",
                                                new CultureInfo("en-US")), $"{nameof(Model.Date)} must match the value (Mon Sep 24 03:35:21 +0000 2012).");

            Assert.AreEqual(Model.Provider, TwitterParser.ProviderName, $"{nameof(Model.Provider)} and {nameof(TwitterParser.ProviderName)} must have equal values.");

            Assert.IsNotNull(Model.Poster, $"{nameof(Model.Poster)} must have a value assigned (\"@sean_cummings\")");
            Assert.AreEqual("@sean_cummings", Model.Poster, $"{nameof(Model.Poster)} must have (\"@sean_cummings\") as its value.");
        }
        public void can_parse_who_are_with_2_users()
        {
            var ids = new long[] { 42, 43 };
            var twitter = new Mock<ITwitter>();
            twitter.Setup(x => x.UserLookup(ids)).Returns(
                @"<users>
                    <user><id>42</id><name>Ford Prefect</name><screen_name>ford42</screen_name></user>
                    <user><id>43</id><name>Arthur Dent</name><screen_name>arthur</screen_name></user>
                </users>");

            var parser = new TwitterParser(twitter.Object);
            parser.WhoAre(ids).Should().Have.SameSequenceAs(
                new UserProfile(42, "Ford Prefect", "ford42"),
                new UserProfile(43, "Arthur Dent", "arthur"));

            twitter.VerifyAll();
        }
 public void can_parse_who_are_with_no_parameter()
 {
     var ids = new long [] {  };
     var twitter = new Mock<ITwitter>();
     var parser = new TwitterParser(twitter.Object);
     parser.WhoAre(ids).Should().Be.Empty();
 }
        public void can_parse_who_are_with_4_users_using_max_per_request_equals_2()
        {
            var twitter = new Mock<ITwitter>();
            twitter.Setup(x => x.UserLookup(new long[] { 42, 43 })).Returns(
                @"<users>
                    <user><id>42</id><name>Ford Prefect</name><screen_name>ford42</screen_name></user>
                    <user><id>43</id><name>Arthur Dent</name><screen_name>arthur</screen_name></user>
                </users>");

            twitter.Setup(x => x.UserLookup(new long[] { 44, 45 })).Returns(
            @"<users>
                    <user><id>44</id><name>Ford Prefect</name><screen_name>ford42</screen_name></user>
                    <user><id>45</id><name>Arthur Dent</name><screen_name>arthur</screen_name></user>
                </users>");

            var parser = new TwitterParser(twitter.Object);
            parser.WhoAre(new long [] { 42, 43, 44, 45 }, 2).Should().Have.SameSequenceAs(
                new UserProfile(42, "Ford Prefect", "ford42"),
                new UserProfile(43, "Arthur Dent", "arthur"),
                new UserProfile(44, "Ford Prefect", "ford42"),
                new UserProfile(45, "Arthur Dent", "arthur"));

            twitter.VerifyAll();
        }