11using System ;
22using System . Threading . Tasks ;
3+ using GitHub . Exports ;
4+ using GitHub . Primitives ;
5+ using GitHub . App . Services ;
36using GitHub . Services ;
47using GitHub . VisualStudio . Commands ;
58using Microsoft . VisualStudio ;
@@ -25,7 +28,7 @@ public async Task NothingInClipboard()
2528 [ Test ]
2629 public async Task NoLocalRepository ( )
2730 {
28- var context = new GitHubContext ( ) ;
31+ var context = CreateGitHubContext ( ) ;
2932 var repositoryDir = null as string ;
3033 var vsServices = Substitute . For < IVSServices > ( ) ;
3134 var target = CreateOpenFromClipboardCommand ( vsServices : vsServices , contextFromClipboard : context , repositoryDir : repositoryDir ) ;
@@ -35,13 +38,27 @@ public async Task NoLocalRepository()
3538 vsServices . Received ( 1 ) . ShowMessageBoxInfo ( OpenFromClipboardCommand . NoActiveRepositoryMessage ) ;
3639 }
3740
41+ [ Test ]
42+ public async Task UnknownLinkType ( )
43+ {
44+ var context = new GitHubContext { LinkType = LinkType . Unknown } ;
45+ var expectMessage = string . Format ( OpenFromClipboardCommand . UnknownLinkTypeMessage , context . Url ) ;
46+ var activeRepositoryDir = "activeRepositoryDir" ;
47+ var vsServices = Substitute . For < IVSServices > ( ) ;
48+ var target = CreateOpenFromClipboardCommand ( vsServices : vsServices , contextFromClipboard : context , repositoryDir : activeRepositoryDir ) ;
49+
50+ await target . Execute ( null ) ;
51+
52+ vsServices . Received ( 1 ) . ShowMessageBoxInfo ( expectMessage ) ;
53+ }
54+
3855 [ TestCase ( "targetRepositoryName" , "activeRepositoryName" , OpenFromClipboardCommand . DifferentRepositoryMessage ) ]
3956 [ TestCase ( "SameRepositoryName" , "SameRepositoryName" , null ) ]
4057 [ TestCase ( "same_repository_name" , "SAME_REPOSITORY_NAME" , null ) ]
4158 public async Task DifferentLocalRepository ( string targetRepositoryName , string activeRepositoryName , string expectMessage )
4259 {
4360 var activeRepositoryDir = "activeRepositoryDir" ;
44- var context = new GitHubContext { RepositoryName = targetRepositoryName } ;
61+ var context = CreateGitHubContext ( repositoryName : targetRepositoryName ) ;
4562 var resolveBlobResult = ( "commitish" , "path" , "SHA" ) ;
4663 var vsServices = Substitute . For < IVSServices > ( ) ;
4764 var target = CreateOpenFromClipboardCommand ( vsServices : vsServices ,
@@ -64,12 +81,13 @@ public async Task DifferentLocalRepository(string targetRepositoryName, string a
6481 [ TestCase ( "sameowner" , "SAMEOWNER" , OpenFromClipboardCommand . NoResolveSameOwnerMessage ) ]
6582 public async Task CouldNotResolve ( string targetOwner , string currentOwner , string expectMessage )
6683 {
67- var context = new GitHubContext { Owner = targetOwner } ;
6884 var repositoryDir = "repositoryDir" ;
85+ var repositoryName = "repositoryName" ;
86+ var context = CreateGitHubContext ( repositoryName : repositoryName , owner : targetOwner ) ;
6987 ( string , string , string ) ? resolveBlobResult = null ;
7088 var vsServices = Substitute . For < IVSServices > ( ) ;
7189 var target = CreateOpenFromClipboardCommand ( vsServices : vsServices ,
72- contextFromClipboard : context , repositoryDir : repositoryDir , repositoryOwner : currentOwner , resolveBlobResult : resolveBlobResult ) ;
90+ contextFromClipboard : context , repositoryDir : repositoryDir , repositoryOwner : currentOwner , repositoryName : repositoryName , resolveBlobResult : resolveBlobResult ) ;
7391
7492 await target . Execute ( null ) ;
7593
@@ -79,12 +97,13 @@ public async Task CouldNotResolve(string targetOwner, string currentOwner, strin
7997 [ Test ]
8098 public async Task CouldResolve ( )
8199 {
82- var context = new GitHubContext ( ) ;
100+ var repositoryName = "repositoryName" ;
101+ var context = CreateGitHubContext ( repositoryName : repositoryName ) ;
83102 var repositoryDir = "repositoryDir" ;
84103 var resolveBlobResult = ( "master" , "foo.cs" , "" ) ;
85104 var vsServices = Substitute . For < IVSServices > ( ) ;
86105 var target = CreateOpenFromClipboardCommand ( vsServices : vsServices ,
87- contextFromClipboard : context , repositoryDir : repositoryDir , resolveBlobResult : resolveBlobResult ) ;
106+ contextFromClipboard : context , repositoryDir : repositoryDir , repositoryName : repositoryName , resolveBlobResult : resolveBlobResult ) ;
88107
89108 await target . Execute ( null ) ;
90109
@@ -94,13 +113,14 @@ public async Task CouldResolve()
94113 [ Test ]
95114 public async Task NoChangesInWorkingDirectory ( )
96115 {
97- var gitHubContextService = Substitute . For < IGitHubContextService > ( ) ;
98- var context = new GitHubContext ( ) ;
99116 var repositoryDir = "repositoryDir" ;
117+ var repositoryName = "repositoryName" ;
118+ var context = CreateGitHubContext ( repositoryName : repositoryName ) ;
119+ var gitHubContextService = Substitute . For < IGitHubContextService > ( ) ;
100120 var resolveBlobResult = ( "master" , "foo.cs" , "" ) ;
101121 var vsServices = Substitute . For < IVSServices > ( ) ;
102122 var target = CreateOpenFromClipboardCommand ( gitHubContextService : gitHubContextService , vsServices : vsServices ,
103- contextFromClipboard : context , repositoryDir : repositoryDir , resolveBlobResult : resolveBlobResult , hasChanges : false ) ;
123+ contextFromClipboard : context , repositoryDir : repositoryDir , repositoryName : repositoryName , resolveBlobResult : resolveBlobResult , hasChanges : false ) ;
104124
105125 await target . Execute ( null ) ;
106126
@@ -113,15 +133,17 @@ public async Task NoChangesInWorkingDirectory()
113133 public async Task HasChangesInWorkingDirectory ( bool annotateFileSupported , string message ,
114134 int receivedTryAnnotateFile , int receivedTryOpenFile )
115135 {
136+ var repositoryDir = "repositoryDir" ;
137+ var repositoryName = "repositoryName" ;
138+ var targetBranch = "targetBranch" ;
139+ var context = CreateGitHubContext ( repositoryName : repositoryName , branch : targetBranch ) ;
116140 var gitHubContextService = Substitute . For < IGitHubContextService > ( ) ;
117141 gitHubContextService . TryAnnotateFile ( null , null , null ) . ReturnsForAnyArgs ( annotateFileSupported ) ;
118- var context = new GitHubContext ( ) ;
119- var repositoryDir = "repositoryDir" ;
120142 var currentBranch = "currentBranch" ;
121- var resolveBlobResult = ( "master" , "foo.cs" , "" ) ;
143+ var resolveBlobResult = ( targetBranch , "foo.cs" , "" ) ;
122144 var vsServices = Substitute . For < IVSServices > ( ) ;
123145 var target = CreateOpenFromClipboardCommand ( gitHubContextService : gitHubContextService , vsServices : vsServices ,
124- contextFromClipboard : context , repositoryDir : repositoryDir , currentBranch : currentBranch , resolveBlobResult : resolveBlobResult , hasChanges : true ) ;
146+ contextFromClipboard : context , repositoryDir : repositoryDir , repositoryName : repositoryName , currentBranch : currentBranch , resolveBlobResult : resolveBlobResult , hasChanges : true ) ;
125147
126148 await target . Execute ( null ) ;
127149
@@ -138,6 +160,14 @@ public async Task HasChangesInWorkingDirectory(bool annotateFileSupported, strin
138160 gitHubContextService . Received ( receivedTryOpenFile ) . TryOpenFile ( repositoryDir , context ) ;
139161 }
140162
163+ static GitHubContext CreateGitHubContext ( UriString uri = null , string owner = "github" , string repositoryName = "VisualStudio"
164+ string branch = "master" )
165+ {
166+ uri = uri ?? new UriString ( $ "https://github.com/{ owner } /{ repositoryName } /blob/{ branch } /README.md") ;
167+
168+ return new GitHubContextService ( null , null ) . FindContextFromUrl ( uri ) ;
169+ }
170+
141171 static OpenFromClipboardCommand CreateOpenFromClipboardCommand (
142172 IGitHubContextService gitHubContextService = null ,
143173 ITeamExplorerContext teamExplorerContext = null ,
0 commit comments