GitHub PullRequestReviewCommentEvent at 2014-08-20 20:32:24
Repository: DCrank
Actor: mikary
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/SignalR/DCrank/pulls/comments/16502896","id":16502896,"diff_hunk":"@@ -0,0 +1,245 @@\n+﻿using System.IO;\n+using System.Threading;\n+using Moq;\n+using Newtonsoft.Json;\n+using Newtonsoft.Json.Linq;\n+using Xunit;\n+\n+namespace Microsoft.AspNet.SignalR.DCrank.Crank\n+{\n+    public class WorkerReceiverUnitTests\n+    {\n+        [Fact]\n+        public void CallsPingMethodWhenPingMessageIsWrittenToStream()\n+        {\n+            // arrange\n+            var pingObject = new\n+            {\n+                Value = 40\n+            };\n+\n+            var message = new Message()\n+            {\n+                Command = \"ping\",\n+                Value = JToken.FromObject(pingObject)\n+            };\n+\n+            var stream = new MemoryStream();\n+            var streamWriter = new StreamWriter(stream);\n+\n+            streamWriter.WriteLine(JsonConvert.SerializeObject(message));\n+            streamWriter.Flush();\n+            stream.Position = 0;\n+\n+            var pingValue = 0;\n+            var pingWaitHandle = new ManualResetEventSlim();\n+\n+            var worker = new Mock<IWorker>();\n+            worker\n+                .Setup(instance => instance.Ping(It.IsAny<int>()))\n+                .Callback<int>(value =>\n+                {\n+                    pingValue = value;\n+                    pingWaitHandle.Set();\n+                });\n+\n+            var streamReader = new StreamReader(stream);\n+            var workerReceiver = new WorkerReceiver(streamReader, worker.Object);\n+\n+            // act\n+            workerReceiver.Start();\n+\n+            // assert\n+            Assert.True(pingWaitHandle.Wait(1000));\n+            Assert.Equal(pingObject.Value, pingValue);\n+        }\n+\n+        [Fact]\n+        public void CallsConnectMethodWhenConnectMessageIsWrittenToStream()\n+        {\n+            // arrange\n+            var connectObject = new\n+            {\n+                TargetAddress = \"http://localhost\",\n+                NumberOfConnections = 10\n+            };\n+\n+            var message = new Message()\n+            {\n+                Command = \"connect\",\n+                Value = JToken.FromObject(connectObject)\n+            };\n+\n+            var stream = new MemoryStream();\n+            var streamWriter = new StreamWriter(stream);\n+\n+            streamWriter.WriteLine(JsonConvert.SerializeObject(message));\n+            streamWriter.Flush();\n+            stream.Position = 0;\n+\n+            string connectTargetAddress = null;\n+            var connectNumberOfConnections = 0;\n+\n+            var connectWaitHandle = new ManualResetEventSlim();\n+            var worker = new Mock<IWorker>();\n+            worker\n+                .Setup(instance => instance.Connect(It.IsAny<string>(), It.IsAny<int>()))\n+                .Callback<string, int>((targetAddress, numberOfConnections) =>\n+                {\n+                    connectTargetAddress = targetAddress;\n+                    connectNumberOfConnections = numberOfConnections;\n+                    connectWaitHandle.Set();\n+                });\n+\n+            var streamReader = new StreamReader(stream);\n+            var workerReceiver = new WorkerReceiver(streamReader, worker.Object);\n+\n+            // act\n+            workerReceiver.Start();\n+\n+            // assert\n+            Assert.True(connectWaitHandle.Wait(1000));\n+            Assert.Equal(connectObject.TargetAddress, connectTargetAddress);\n+            Assert.Equal(connectObject.NumberOfConnections, connectNumberOfConnections);\n+        }\n+\n+        [Fact]\n+        public void CallsStartTestMethodWhenStartTestMessageIsWrittenToStream()\n+        {\n+            // arrange\n+            var startTestObject = new\n+            {\n+                SendInterval = 20,\n+                SendBytes = 30\n+            };\n+\n+            var message = new Message()\n+            {\n+                Command = \"starttest\",\n+                Value = JToken.FromObject(startTestObject)\n+            };\n+\n+            var stream = new MemoryStream();\n+            var streamWriter = new StreamWriter(stream);\n+\n+            streamWriter.WriteLine(JsonConvert.SerializeObject(message));\n+            streamWriter.Flush();\n+            stream.Position = 0;\n+\n+            var startTestSendInterval = 0;\n+            var startTestSendBytes = 0;\n+\n+            var startTestWaitHandle = new ManualResetEventSlim();\n+            var worker = new Mock<IWorker>();\n+            worker\n+                .Setup(instance => instance.StartTest(It.IsAny<int>(), It.IsAny<int>()))\n+                .Callback<int, int>((sendInterval, sendBytes) =>\n+                {\n+                    startTestSendInterval = sendInterval;\n+                    startTestSendBytes = sendBytes;\n+                    startTestWaitHandle.Set();\n+                });\n+\n+            var streamReader = new StreamReader(stream);\n+            var workerReceiver = new WorkerReceiver(streamReader, worker.Object);\n+\n+            // act\n+            workerReceiver.Start();\n+\n+            // assert\n+            Assert.True(startTestWaitHandle.Wait(1000));\n+            Assert.Equal(startTestObject.SendInterval, startTestSendInterval);\n+            Assert.Equal(startTestObject.SendBytes, startTestSendBytes);\n+        }\n+\n+        [Fact]\n+        public void CallsStopMethodWhenStopMessageIsWrittenToStream()\n+        {\n+            // arrange\n+            var message = new Message()\n+            {\n+                Command = \"stop\",\n+                Value = null\n+            };\n+\n+            var stream = new MemoryStream();\n+            var streamWriter = new StreamWriter(stream);\n+\n+            streamWriter.WriteLine(JsonConvert.SerializeObject(message));\n+            streamWriter.Flush();\n+            stream.Position = 0;\n+\n+            var stopWaitHandle = new ManualResetEventSlim();\n+            var worker = new Mock<IWorker>();\n+            worker\n+                .Setup(instance => instance.Stop())\n+                .Callback(stopWaitHandle.Set);\n+\n+            var streamReader = new StreamReader(stream);\n+            var workerReceiver = new WorkerReceiver(streamReader, worker.Object);\n+\n+            // act\n+            workerReceiver.Start();\n+\n+            // assert\n+            Assert.True(stopWaitHandle.Wait(1000));\n+        }\n+\n+        [Fact]\n+        public void StopsReadingWhenStopIsCalled()\n+        {\n+            // arrange\n+            var stopMessage = new Message()\n+            {\n+                Command = \"stop\",\n+                Value = null\n+            };\n+\n+            var pingObject = new\n+            {\n+                Value = 40\n+            };\n+\n+            var pingMessage = new Message()\n+            {\n+                Command = \"ping\",\n+                Value = JToken.FromObject(pingObject)\n+            };\n+\n+            var stream = new MemoryStream();\n+            var streamWriter = new StreamWriter(stream);\n+\n+            streamWriter.WriteLine(JsonConvert.SerializeObject(stopMessage));\n+            streamWriter.WriteLine(JsonConvert.SerializeObject(pingMessage));\n+            streamWriter.Flush();\n+            stream.Position = 0;\n+\n+            var stopWaitHandle = new ManualResetEventSlim();\n+            var pingWaitHandle = new ManualResetEventSlim();\n+\n+            var worker = new Mock<IWorker>();\n+\n+            var streamReader = new StreamReader(stream);\n+            var workerReceiver = new WorkerReceiver(streamReader, worker.Object);\n+\n+            worker","path":"tests/Microsoft.AspNet.SignalR.DCrank.Crank.Tests/WorkerReceiverUnitTests.cs","position":225,"original_position":225,"commit_id":"cef40550d3f49c7cbcd6bc7edf92cf3e45dbaf89","original_commit_id":"cef40550d3f49c7cbcd6bc7edf92cf3e45dbaf89","user":{"login":"mikary","id":6787717,"avatar_url":"https://avatars.githubusercontent.com/u/6787717?v=2","gravatar_id":"a0da43128dd1e14ca81c21930fc87034","url":"https://api.github.com/users/mikary","html_url":"https://github.com/mikary","followers_url":"https://api.github.com/users/mikary/followers","following_url":"https://api.github.com/users/mikary/following{/other_user}","gists_url":"https://api.github.com/users/mikary/gists{/gist_id}","starred_url":"https://api.github.com/users/mikary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikary/subscriptions","organizations_url":"https://api.github.com/users/mikary/orgs","repos_url":"https://api.github.com/users/mikary/repos","events_url":"https://api.github.com/users/mikary/events{/privacy}","received_events_url":"https://api.github.com/users/mikary/received_events","type":"User","site_admin":false},"body":"Could you be more specific about how you would like to see the formatting changed?","created_at":"2014-08-20T20:32:24Z","updated_at":"2014-08-20T20:32:24Z","html_url":"https://github.com/SignalR/DCrank/pull/53#discussion_r16502896","pull_request_url":"https://api.github.com/repos/SignalR/DCrank/pulls/53","_links":{"self":{"href":"https://api.github.com/repos/SignalR/DCrank/pulls/comments/16502896"},"html":{"href":"https://github.com/SignalR/DCrank/pull/53#discussion_r16502896"},"pull_request":{"href":"https://api.github.com/repos/SignalR/DCrank/pulls/53"}}},"pull_request":{"url":"https://api.github.com/repos/SignalR/DCrank/pulls/53","id":19947615,"html_url":"https://github.com/SignalR/DCrank/pull/53","diff_url":"https://github.com/SignalR/DCrank/pull/53.diff","patch_url":"https://github.com/SignalR/DCrank/pull/53.patch","issue_url":"https://api.github.com/repos/SignalR/DCrank/issues/53","number":53,"state":"open","locked":false,"title":"Worker io refactor2","user":{"login":"mikary","id":6787717,"avatar_url":"https://avatars.githubusercontent.com/u/6787717?v=2","gravatar_id":"a0da43128dd1e14ca81c21930fc87034","url":"https://api.github.com/users/mikary","html_url":"https://github.com/mikary","followers_url":"https://api.github.com/users/mikary/followers","following_url":"https://api.github.com/users/mikary/following{/other_user}","gists_url":"https://api.github.com/users/mikary/gists{/gist_id}","starred_url":"https://api.github.com/users/mikary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikary/subscriptions","organizations_url":"https://api.github.com/users/mikary/orgs","repos_url":"https://api.github.com/users/mikary/repos","events_url":"https://api.github.com/users/mikary/events{/privacy}","received_events_url":"https://api.github.com/users/mikary/received_events","type":"User","site_admin":false},"body":"Implementation of the receiving (worker) side of the Json over standard IO refactor to use the IWorker interface.\r\n@intern-felicco @abnanda1 @davidfowl \r\n","created_at":"2014-08-18T21:55:05Z","updated_at":"2014-08-20T20:32:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"85e1614cc1dd2d4e2fee5866888c68ab8d6fea2c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SignalR/DCrank/pulls/53/commits","review_comments_url":"https://api.github.com/repos/SignalR/DCrank/pulls/53/comments","review_comment_url":"https://api.github.com/repos/SignalR/DCrank/pulls/comments/{number}","comments_url":"https://api.github.com/repos/SignalR/DCrank/issues/53/comments","statuses_url":"https://api.github.com/repos/SignalR/DCrank/statuses/cef40550d3f49c7cbcd6bc7edf92cf3e45dbaf89","head":{"label":"SignalR:workerIORefactor2","ref":"workerIORefactor2","sha":"cef40550d3f49c7cbcd6bc7edf92cf3e45dbaf89","user":{"login":"SignalR","id":931666,"avatar_url":"https://avatars.githubusercontent.com/u/931666?v=2","gravatar_id":"be398863814310a4644089aebc8cd4af","url":"https://api.github.com/users/SignalR","html_url":"https://github.com/SignalR","followers_url":"https://api.github.com/users/SignalR/followers","following_url":"https://api.github.com/users/SignalR/following{/other_user}","gists_url":"https://api.github.com/users/SignalR/gists{/gist_id}","starred_url":"https://api.github.com/users/SignalR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SignalR/subscriptions","organizations_url":"https://api.github.com/users/SignalR/orgs","repos_url":"https://api.github.com/users/SignalR/repos","events_url":"https://api.github.com/users/SignalR/events{/privacy}","received_events_url":"https://api.github.com/users/SignalR/received_events","type":"Organization","site_admin":false},"repo":{"id":20748419,"name":"DCrank","full_name":"SignalR/DCrank","owner":{"login":"SignalR","id":931666,"avatar_url":"https://avatars.githubusercontent.com/u/931666?v=2","gravatar_id":"be398863814310a4644089aebc8cd4af","url":"https://api.github.com/users/SignalR","html_url":"https://github.com/SignalR","followers_url":"https://api.github.com/users/SignalR/followers","following_url":"https://api.github.com/users/SignalR/following{/other_user}","gists_url":"https://api.github.com/users/SignalR/gists{/gist_id}","starred_url":"https://api.github.com/users/SignalR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SignalR/subscriptions","organizations_url":"https://api.github.com/users/SignalR/orgs","repos_url":"https://api.github.com/users/SignalR/repos","events_url":"https://api.github.com/users/SignalR/events{/privacy}","received_events_url":"https://api.github.com/users/SignalR/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SignalR/DCrank","description":"The new stuff","fork":false,"url":"https://api.github.com/repos/SignalR/DCrank","forks_url":"https://api.github.com/repos/SignalR/DCrank/forks","keys_url":"https://api.github.com/repos/SignalR/DCrank/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SignalR/DCrank/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SignalR/DCrank/teams","hooks_url":"https://api.github.com/repos/SignalR/DCrank/hooks","issue_events_url":"https://api.github.com/repos/SignalR/DCrank/issues/events{/number}","events_url":"https://api.github.com/repos/SignalR/DCrank/events","assignees_url":"https://api.github.com/repos/SignalR/DCrank/assignees{/user}","branches_url":"https://api.github.com/repos/SignalR/DCrank/branches{/branch}","tags_url":"https://api.github.com/repos/SignalR/DCrank/tags","blobs_url":"https://api.github.com/repos/SignalR/DCrank/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SignalR/DCrank/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SignalR/DCrank/git/refs{/sha}","trees_url":"https://api.github.com/repos/SignalR/DCrank/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SignalR/DCrank/statuses/{sha}","languages_url":"https://api.github.com/repos/SignalR/DCrank/languages","stargazers_url":"https://api.github.com/repos/SignalR/DCrank/stargazers","contributors_url":"https://api.github.com/repos/SignalR/DCrank/contributors","subscribers_url":"https://api.github.com/repos/SignalR/DCrank/subscribers","subscription_url":"https://api.github.com/repos/SignalR/DCrank/subscription","commits_url":"https://api.github.com/repos/SignalR/DCrank/commits{/sha}","git_commits_url":"https://api.github.com/repos/SignalR/DCrank/git/commits{/sha}","comments_url":"https://api.github.com/repos/SignalR/DCrank/comments{/number}","issue_comment_url":"https://api.github.com/repos/SignalR/DCrank/issues/comments/{number}","contents_url":"https://api.github.com/repos/SignalR/DCrank/contents/{+path}","compare_url":"https://api.github.com/repos/SignalR/DCrank/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SignalR/DCrank/merges","archive_url":"https://api.github.com/repos/SignalR/DCrank/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SignalR/DCrank/downloads","issues_url":"https://api.github.com/repos/SignalR/DCrank/issues{/number}","pulls_url":"https://api.github.com/repos/SignalR/DCrank/pulls{/number}","milestones_url":"https://api.github.com/repos/SignalR/DCrank/milestones{/number}","notifications_url":"https://api.github.com/repos/SignalR/DCrank/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SignalR/DCrank/labels{/name}","releases_url":"https://api.github.com/repos/SignalR/DCrank/releases{/id}","created_at":"2014-06-12T00:00:47Z","updated_at":"2014-08-19T07:51:53Z","pushed_at":"2014-08-20T19:28:54Z","git_url":"git://github.com/SignalR/DCrank.git","ssh_url":"git@github.com:SignalR/DCrank.git","clone_url":"https://github.com/SignalR/DCrank.git","svn_url":"https://github.com/SignalR/DCrank","homepage":null,"size":2524,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":1,"mirror_url":null,"open_issues_count":16,"forks":1,"open_issues":16,"watchers":4,"default_branch":"dev"}},"base":{"label":"SignalR:dev","ref":"dev","sha":"72dc4ae2f1922a0648969cb11d3db429cb289f25","user":{"login":"SignalR","id":931666,"avatar_url":"https://avatars.githubusercontent.com/u/931666?v=2","gravatar_id":"be398863814310a4644089aebc8cd4af","url":"https://api.github.com/users/SignalR","html_url":"https://github.com/SignalR","followers_url":"https://api.github.com/users/SignalR/followers","following_url":"https://api.github.com/users/SignalR/following{/other_user}","gists_url":"https://api.github.com/users/SignalR/gists{/gist_id}","starred_url":"https://api.github.com/users/SignalR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SignalR/subscriptions","organizations_url":"https://api.github.com/users/SignalR/orgs","repos_url":"https://api.github.com/users/SignalR/repos","events_url":"https://api.github.com/users/SignalR/events{/privacy}","received_events_url":"https://api.github.com/users/SignalR/received_events","type":"Organization","site_admin":false},"repo":{"id":20748419,"name":"DCrank","full_name":"SignalR/DCrank","owner":{"login":"SignalR","id":931666,"avatar_url":"https://avatars.githubusercontent.com/u/931666?v=2","gravatar_id":"be398863814310a4644089aebc8cd4af","url":"https://api.github.com/users/SignalR","html_url":"https://github.com/SignalR","followers_url":"https://api.github.com/users/SignalR/followers","following_url":"https://api.github.com/users/SignalR/following{/other_user}","gists_url":"https://api.github.com/users/SignalR/gists{/gist_id}","starred_url":"https://api.github.com/users/SignalR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SignalR/subscriptions","organizations_url":"https://api.github.com/users/SignalR/orgs","repos_url":"https://api.github.com/users/SignalR/repos","events_url":"https://api.github.com/users/SignalR/events{/privacy}","received_events_url":"https://api.github.com/users/SignalR/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SignalR/DCrank","description":"The new stuff","fork":false,"url":"https://api.github.com/repos/SignalR/DCrank","forks_url":"https://api.github.com/repos/SignalR/DCrank/forks","keys_url":"https://api.github.com/repos/SignalR/DCrank/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SignalR/DCrank/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SignalR/DCrank/teams","hooks_url":"https://api.github.com/repos/SignalR/DCrank/hooks","issue_events_url":"https://api.github.com/repos/SignalR/DCrank/issues/events{/number}","events_url":"https://api.github.com/repos/SignalR/DCrank/events","assignees_url":"https://api.github.com/repos/SignalR/DCrank/assignees{/user}","branches_url":"https://api.github.com/repos/SignalR/DCrank/branches{/branch}","tags_url":"https://api.github.com/repos/SignalR/DCrank/tags","blobs_url":"https://api.github.com/repos/SignalR/DCrank/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SignalR/DCrank/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SignalR/DCrank/git/refs{/sha}","trees_url":"https://api.github.com/repos/SignalR/DCrank/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SignalR/DCrank/statuses/{sha}","languages_url":"https://api.github.com/repos/SignalR/DCrank/languages","stargazers_url":"https://api.github.com/repos/SignalR/DCrank/stargazers","contributors_url":"https://api.github.com/repos/SignalR/DCrank/contributors","subscribers_url":"https://api.github.com/repos/SignalR/DCrank/subscribers","subscription_url":"https://api.github.com/repos/SignalR/DCrank/subscription","commits_url":"https://api.github.com/repos/SignalR/DCrank/commits{/sha}","git_commits_url":"https://api.github.com/repos/SignalR/DCrank/git/commits{/sha}","comments_url":"https://api.github.com/repos/SignalR/DCrank/comments{/number}","issue_comment_url":"https://api.github.com/repos/SignalR/DCrank/issues/comments/{number}","contents_url":"https://api.github.com/repos/SignalR/DCrank/contents/{+path}","compare_url":"https://api.github.com/repos/SignalR/DCrank/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SignalR/DCrank/merges","archive_url":"https://api.github.com/repos/SignalR/DCrank/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SignalR/DCrank/downloads","issues_url":"https://api.github.com/repos/SignalR/DCrank/issues{/number}","pulls_url":"https://api.github.com/repos/SignalR/DCrank/pulls{/number}","milestones_url":"https://api.github.com/repos/SignalR/DCrank/milestones{/number}","notifications_url":"https://api.github.com/repos/SignalR/DCrank/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SignalR/DCrank/labels{/name}","releases_url":"https://api.github.com/repos/SignalR/DCrank/releases{/id}","created_at":"2014-06-12T00:00:47Z","updated_at":"2014-08-19T07:51:53Z","pushed_at":"2014-08-20T19:28:54Z","git_url":"git://github.com/SignalR/DCrank.git","ssh_url":"git@github.com:SignalR/DCrank.git","clone_url":"https://github.com/SignalR/DCrank.git","svn_url":"https://github.com/SignalR/DCrank","homepage":null,"size":2524,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":1,"mirror_url":null,"open_issues_count":16,"forks":1,"open_issues":16,"watchers":4,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/SignalR/DCrank/pulls/53"},"html":{"href":"https://github.com/SignalR/DCrank/pull/53"},"issue":{"href":"https://api.github.com/repos/SignalR/DCrank/issues/53"},"comments":{"href":"https://api.github.com/repos/SignalR/DCrank/issues/53/comments"},"review_comments":{"href":"https://api.github.com/repos/SignalR/DCrank/pulls/53/comments"},"review_comment":{"href":"https://api.github.com/repos/SignalR/DCrank/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/SignalR/DCrank/pulls/53/commits"},"statuses":{"href":"https://api.github.com/repos/SignalR/DCrank/statuses/cef40550d3f49c7cbcd6bc7edf92cf3e45dbaf89"}}}}