{"action":"created","comment":{"url":"https://api.github.com/repos/justeat/JustFakeIt/pulls/comments/26864845","id":26864845,"diff_hunk":"@@ -1,17 +1,40 @@\n-﻿using System.Net;\r\n-using System.Net.Sockets;\r\n+﻿using System;\r\n+using System.Net;\r\n+using System.Net.NetworkInformation;\r\n \r\n namespace JustFakeIt\r\n {\r\n     public class Ports\r\n     {\r\n+        private static readonly Random Random = new Random();\r\n+\r\n         public static int GetFreeTcpPort()\r\n         {\r\n-            var listener = new TcpListener(IPAddress.Loopback, 0);\r\n-            listener.Start();\r\n-            var port = ((IPEndPoint)listener.LocalEndpoint).Port;\r\n-            listener.Stop();\r\n+            var port = 0;\r\n+            while (!IsAvailable(port))\r\n+                port = Random.Next(49152, IPEndPoint.MaxPort);\r\n+\r\n             return port;\r\n         }\r\n+\r\n+        private static bool IsAvailable(int port)\r","path":"JustFakeIt/Ports.cs","position":26,"original_position":26,"commit_id":"ffdcef6d5a8245be004876bd3fe39e57a1fc3f19","original_commit_id":"ffdcef6d5a8245be004876bd3fe39e57a1fc3f19","user":{"login":"petemounce","id":69720,"avatar_url":"https://avatars.githubusercontent.com/u/69720?v=3","gravatar_id":"","url":"https://api.github.com/users/petemounce","html_url":"https://github.com/petemounce","followers_url":"https://api.github.com/users/petemounce/followers","following_url":"https://api.github.com/users/petemounce/following{/other_user}","gists_url":"https://api.github.com/users/petemounce/gists{/gist_id}","starred_url":"https://api.github.com/users/petemounce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petemounce/subscriptions","organizations_url":"https://api.github.com/users/petemounce/orgs","repos_url":"https://api.github.com/users/petemounce/repos","events_url":"https://api.github.com/users/petemounce/events{/privacy}","received_events_url":"https://api.github.com/users/petemounce/received_events","type":"User","site_admin":false},"body":"Lovely; thanks for this. Feels much less caveman ;-)","created_at":"2015-03-20T18:36:17Z","updated_at":"2015-03-20T18:36:17Z","html_url":"https://github.com/justeat/JustFakeIt/pull/12#discussion_r26864845","pull_request_url":"https://api.github.com/repos/justeat/JustFakeIt/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/justeat/JustFakeIt/pulls/comments/26864845"},"html":{"href":"https://github.com/justeat/JustFakeIt/pull/12#discussion_r26864845"},"pull_request":{"href":"https://api.github.com/repos/justeat/JustFakeIt/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/justeat/JustFakeIt/pulls/12","id":31635572,"html_url":"https://github.com/justeat/JustFakeIt/pull/12","diff_url":"https://github.com/justeat/JustFakeIt/pull/12.diff","patch_url":"https://github.com/justeat/JustFakeIt/pull/12.patch","issue_url":"https://api.github.com/repos/justeat/JustFakeIt/issues/12","number":12,"state":"open","locked":false,"title":"Removed static references / Improved getting free tcp port","user":{"login":"oliversweb","id":1353060,"avatar_url":"https://avatars.githubusercontent.com/u/1353060?v=3","gravatar_id":"","url":"https://api.github.com/users/oliversweb","html_url":"https://github.com/oliversweb","followers_url":"https://api.github.com/users/oliversweb/followers","following_url":"https://api.github.com/users/oliversweb/following{/other_user}","gists_url":"https://api.github.com/users/oliversweb/gists{/gist_id}","starred_url":"https://api.github.com/users/oliversweb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oliversweb/subscriptions","organizations_url":"https://api.github.com/users/oliversweb/orgs","repos_url":"https://api.github.com/users/oliversweb/repos","events_url":"https://api.github.com/users/oliversweb/events{/privacy}","received_events_url":"https://api.github.com/users/oliversweb/received_events","type":"User","site_admin":false},"body":"When running tests in parallel the static refs would conflict with each test so removed these.\r\nImproved the way to get a free tcp port by checking the tcp table for ports in use rather than attempting to open the port.\r\nAdded a ctor that performs the process of getting a free tcp port under the hood.","created_at":"2015-03-20T17:42:03Z","updated_at":"2015-03-20T18:36:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"42c811b9c712c10e6070da3c3ff353ac4f3919a6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/justeat/JustFakeIt/pulls/12/commits","review_comments_url":"https://api.github.com/repos/justeat/JustFakeIt/pulls/12/comments","review_comment_url":"https://api.github.com/repos/justeat/JustFakeIt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/justeat/JustFakeIt/issues/12/comments","statuses_url":"https://api.github.com/repos/justeat/JustFakeIt/statuses/ffdcef6d5a8245be004876bd3fe39e57a1fc3f19","head":{"label":"oliversweb:RemovedStaticRefs","ref":"RemovedStaticRefs","sha":"ffdcef6d5a8245be004876bd3fe39e57a1fc3f19","user":{"login":"oliversweb","id":1353060,"avatar_url":"https://avatars.githubusercontent.com/u/1353060?v=3","gravatar_id":"","url":"https://api.github.com/users/oliversweb","html_url":"https://github.com/oliversweb","followers_url":"https://api.github.com/users/oliversweb/followers","following_url":"https://api.github.com/users/oliversweb/following{/other_user}","gists_url":"https://api.github.com/users/oliversweb/gists{/gist_id}","starred_url":"https://api.github.com/users/oliversweb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oliversweb/subscriptions","organizations_url":"https://api.github.com/users/oliversweb/orgs","repos_url":"https://api.github.com/users/oliversweb/repos","events_url":"https://api.github.com/users/oliversweb/events{/privacy}","received_events_url":"https://api.github.com/users/oliversweb/received_events","type":"User","site_admin":false},"repo":{"id":29966763,"name":"JustFakeIt","full_name":"oliversweb/JustFakeIt","owner":{"login":"oliversweb","id":1353060,"avatar_url":"https://avatars.githubusercontent.com/u/1353060?v=3","gravatar_id":"","url":"https://api.github.com/users/oliversweb","html_url":"https://github.com/oliversweb","followers_url":"https://api.github.com/users/oliversweb/followers","following_url":"https://api.github.com/users/oliversweb/following{/other_user}","gists_url":"https://api.github.com/users/oliversweb/gists{/gist_id}","starred_url":"https://api.github.com/users/oliversweb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oliversweb/subscriptions","organizations_url":"https://api.github.com/users/oliversweb/orgs","repos_url":"https://api.github.com/users/oliversweb/repos","events_url":"https://api.github.com/users/oliversweb/events{/privacy}","received_events_url":"https://api.github.com/users/oliversweb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/oliversweb/JustFakeIt","description":"HTTP server faking library","fork":true,"url":"https://api.github.com/repos/oliversweb/JustFakeIt","forks_url":"https://api.github.com/repos/oliversweb/JustFakeIt/forks","keys_url":"https://api.github.com/repos/oliversweb/JustFakeIt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/oliversweb/JustFakeIt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/oliversweb/JustFakeIt/teams","hooks_url":"https://api.github.com/repos/oliversweb/JustFakeIt/hooks","issue_events_url":"https://api.github.com/repos/oliversweb/JustFakeIt/issues/events{/number}","events_url":"https://api.github.com/repos/oliversweb/JustFakeIt/events","assignees_url":"https://api.github.com/repos/oliversweb/JustFakeIt/assignees{/user}","branches_url":"https://api.github.com/repos/oliversweb/JustFakeIt/branches{/branch}","tags_url":"https://api.github.com/repos/oliversweb/JustFakeIt/tags","blobs_url":"https://api.github.com/repos/oliversweb/JustFakeIt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/oliversweb/JustFakeIt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/oliversweb/JustFakeIt/git/refs{/sha}","trees_url":"https://api.github.com/repos/oliversweb/JustFakeIt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/oliversweb/JustFakeIt/statuses/{sha}","languages_url":"https://api.github.com/repos/oliversweb/JustFakeIt/languages","stargazers_url":"https://api.github.com/repos/oliversweb/JustFakeIt/stargazers","contributors_url":"https://api.github.com/repos/oliversweb/JustFakeIt/contributors","subscribers_url":"https://api.github.com/repos/oliversweb/JustFakeIt/subscribers","subscription_url":"https://api.github.com/repos/oliversweb/JustFakeIt/subscription","commits_url":"https://api.github.com/repos/oliversweb/JustFakeIt/commits{/sha}","git_commits_url":"https://api.github.com/repos/oliversweb/JustFakeIt/git/commits{/sha}","comments_url":"https://api.github.com/repos/oliversweb/JustFakeIt/comments{/number}","issue_comment_url":"https://api.github.com/repos/oliversweb/JustFakeIt/issues/comments{/number}","contents_url":"https://api.github.com/repos/oliversweb/JustFakeIt/contents/{+path}","compare_url":"https://api.github.com/repos/oliversweb/JustFakeIt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/oliversweb/JustFakeIt/merges","archive_url":"https://api.github.com/repos/oliversweb/JustFakeIt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/oliversweb/JustFakeIt/downloads","issues_url":"https://api.github.com/repos/oliversweb/JustFakeIt/issues{/number}","pulls_url":"https://api.github.com/repos/oliversweb/JustFakeIt/pulls{/number}","milestones_url":"https://api.github.com/repos/oliversweb/JustFakeIt/milestones{/number}","notifications_url":"https://api.github.com/repos/oliversweb/JustFakeIt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/oliversweb/JustFakeIt/labels{/name}","releases_url":"https://api.github.com/repos/oliversweb/JustFakeIt/releases{/id}","created_at":"2015-01-28T12:34:46Z","updated_at":"2015-01-28T12:34:46Z","pushed_at":"2015-03-20T17:38:03Z","git_url":"git://github.com/oliversweb/JustFakeIt.git","ssh_url":"git@github.com:oliversweb/JustFakeIt.git","clone_url":"https://github.com/oliversweb/JustFakeIt.git","svn_url":"https://github.com/oliversweb/JustFakeIt","homepage":null,"size":133,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"justeat:master","ref":"master","sha":"5cb54f1a5f34331d004ffbce62d5155582af238a","user":{"login":"justeat","id":1516790,"avatar_url":"https://avatars.githubusercontent.com/u/1516790?v=3","gravatar_id":"","url":"https://api.github.com/users/justeat","html_url":"https://github.com/justeat","followers_url":"https://api.github.com/users/justeat/followers","following_url":"https://api.github.com/users/justeat/following{/other_user}","gists_url":"https://api.github.com/users/justeat/gists{/gist_id}","starred_url":"https://api.github.com/users/justeat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justeat/subscriptions","organizations_url":"https://api.github.com/users/justeat/orgs","repos_url":"https://api.github.com/users/justeat/repos","events_url":"https://api.github.com/users/justeat/events{/privacy}","received_events_url":"https://api.github.com/users/justeat/received_events","type":"Organization","site_admin":false},"repo":{"id":22870298,"name":"JustFakeIt","full_name":"justeat/JustFakeIt","owner":{"login":"justeat","id":1516790,"avatar_url":"https://avatars.githubusercontent.com/u/1516790?v=3","gravatar_id":"","url":"https://api.github.com/users/justeat","html_url":"https://github.com/justeat","followers_url":"https://api.github.com/users/justeat/followers","following_url":"https://api.github.com/users/justeat/following{/other_user}","gists_url":"https://api.github.com/users/justeat/gists{/gist_id}","starred_url":"https://api.github.com/users/justeat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justeat/subscriptions","organizations_url":"https://api.github.com/users/justeat/orgs","repos_url":"https://api.github.com/users/justeat/repos","events_url":"https://api.github.com/users/justeat/events{/privacy}","received_events_url":"https://api.github.com/users/justeat/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/justeat/JustFakeIt","description":"HTTP server faking library","fork":false,"url":"https://api.github.com/repos/justeat/JustFakeIt","forks_url":"https://api.github.com/repos/justeat/JustFakeIt/forks","keys_url":"https://api.github.com/repos/justeat/JustFakeIt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/justeat/JustFakeIt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/justeat/JustFakeIt/teams","hooks_url":"https://api.github.com/repos/justeat/JustFakeIt/hooks","issue_events_url":"https://api.github.com/repos/justeat/JustFakeIt/issues/events{/number}","events_url":"https://api.github.com/repos/justeat/JustFakeIt/events","assignees_url":"https://api.github.com/repos/justeat/JustFakeIt/assignees{/user}","branches_url":"https://api.github.com/repos/justeat/JustFakeIt/branches{/branch}","tags_url":"https://api.github.com/repos/justeat/JustFakeIt/tags","blobs_url":"https://api.github.com/repos/justeat/JustFakeIt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/justeat/JustFakeIt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/justeat/JustFakeIt/git/refs{/sha}","trees_url":"https://api.github.com/repos/justeat/JustFakeIt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/justeat/JustFakeIt/statuses/{sha}","languages_url":"https://api.github.com/repos/justeat/JustFakeIt/languages","stargazers_url":"https://api.github.com/repos/justeat/JustFakeIt/stargazers","contributors_url":"https://api.github.com/repos/justeat/JustFakeIt/contributors","subscribers_url":"https://api.github.com/repos/justeat/JustFakeIt/subscribers","subscription_url":"https://api.github.com/repos/justeat/JustFakeIt/subscription","commits_url":"https://api.github.com/repos/justeat/JustFakeIt/commits{/sha}","git_commits_url":"https://api.github.com/repos/justeat/JustFakeIt/git/commits{/sha}","comments_url":"https://api.github.com/repos/justeat/JustFakeIt/comments{/number}","issue_comment_url":"https://api.github.com/repos/justeat/JustFakeIt/issues/comments{/number}","contents_url":"https://api.github.com/repos/justeat/JustFakeIt/contents/{+path}","compare_url":"https://api.github.com/repos/justeat/JustFakeIt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/justeat/JustFakeIt/merges","archive_url":"https://api.github.com/repos/justeat/JustFakeIt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/justeat/JustFakeIt/downloads","issues_url":"https://api.github.com/repos/justeat/JustFakeIt/issues{/number}","pulls_url":"https://api.github.com/repos/justeat/JustFakeIt/pulls{/number}","milestones_url":"https://api.github.com/repos/justeat/JustFakeIt/milestones{/number}","notifications_url":"https://api.github.com/repos/justeat/JustFakeIt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/justeat/JustFakeIt/labels{/name}","releases_url":"https://api.github.com/repos/justeat/JustFakeIt/releases{/id}","created_at":"2014-08-12T08:29:26Z","updated_at":"2015-02-06T14:25:37Z","pushed_at":"2015-03-20T17:42:05Z","git_url":"git://github.com/justeat/JustFakeIt.git","ssh_url":"git@github.com:justeat/JustFakeIt.git","clone_url":"https://github.com/justeat/JustFakeIt.git","svn_url":"https://github.com/justeat/JustFakeIt","homepage":null,"size":334,"stargazers_count":4,"watchers_count":4,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":3,"forks":7,"open_issues":3,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/justeat/JustFakeIt/pulls/12"},"html":{"href":"https://github.com/justeat/JustFakeIt/pull/12"},"issue":{"href":"https://api.github.com/repos/justeat/JustFakeIt/issues/12"},"comments":{"href":"https://api.github.com/repos/justeat/JustFakeIt/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/justeat/JustFakeIt/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/justeat/JustFakeIt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/justeat/JustFakeIt/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/justeat/JustFakeIt/statuses/ffdcef6d5a8245be004876bd3fe39e57a1fc3f19"}}}}