public void WebIsCorrectlyRecognized() { // Arrange var url = "web"; // Act var source = new TweetSource(url); // Assert Assert.AreEqual("web", source.Name); Assert.AreEqual(new Uri("https://twitter.com"), source.Url); }
public void AppIsCorrectlyRecognized() { // Arrange var url = "<a href=\"http://example.com\" rel=\"nofollow\">ExampleApp</a>"; // Act var source = new TweetSource(url); // Assert Assert.AreEqual("ExampleApp", source.Name); Assert.AreEqual(new Uri("http://example.com"), source.Url); }
public void EmptySourceUsesWebAsFallback() { // Arrange var url = string.Empty; // Act var source = new TweetSource(url); // Assert Assert.AreEqual("web", source.Name); Assert.AreEqual(new Uri("https://twitter.com"), source.Url); }
public void StrangeFormattedAppsAreRecognized() { // Arrange var wrongOrderUrl = "<a rel=\"nofollow\" href=\"http://example.com\">ExampleApp</a>"; var noRelUrl = "<a href=\"http://example.com\">ExampleApp</a>"; // Act var wrongOrderSource = new TweetSource(wrongOrderUrl); var noRelSource = new TweetSource(noRelUrl); // Assert Assert.AreEqual("ExampleApp", wrongOrderSource.Name); Assert.AreEqual(new Uri("http://example.com"), wrongOrderSource.Url); Assert.AreEqual("ExampleApp", noRelSource.Name); Assert.AreEqual(new Uri("http://example.com"), noRelSource.Url); }
static void Main(string[] args) { var handler1 = new TweetHandler(TweetHandleMethod1); var handler2 = new TweetHandler(TweetHandleMethod2); var source = new TweetSource(); source.NewTweetEvent += handler1.AddTweetToQueue; source.NewTweetEvent += handler2.AddTweetToQueue; // start up the task threads (2 of them)! var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; var taskFactory = new TaskFactory(token); var task1 = taskFactory.StartNew(() => handler1.HandleTweets(token)); var task2 = taskFactory.StartNew(() => handler2.HandleTweets(token)); // fire up the source source.Start(); Thread.Sleep(10000); tokenSource.Cancel(); }