77using NSubstitute ;
88using Octokit ;
99using Xunit ;
10+ using Xunit . Extensions ;
1011
1112namespace GitReleaseNotes . Tests . IssueTrackers . GitHub
1213{
@@ -16,11 +17,13 @@ public class GitHubIssueTrackerTests
1617 private readonly GitHubIssueTracker _sut ;
1718 private readonly GitReleaseNotesArguments _gitReleaseNotesArguments ;
1819 private readonly IIssuesClient _issuesClient ;
20+ private readonly ILog _log ;
1921
2022 public GitHubIssueTrackerTests ( )
2123 {
24+ _log = Substitute . For < ILog > ( ) ;
2225 _gitHubClient = Substitute . For < IGitHubClient > ( ) ;
23- _sut = new GitHubIssueTracker ( new IssueNumberExtractor ( ) , _gitHubClient ) ;
26+ _sut = new GitHubIssueTracker ( new IssueNumberExtractor ( ) , ( ) => _gitHubClient , _log ) ;
2427 _gitReleaseNotesArguments = new GitReleaseNotesArguments
2528 {
2629 Repo = "Org/Repo" ,
@@ -55,6 +58,64 @@ public void CreatesReleaseNotesForClosedGitHubIssues()
5558 Assert . Equal ( "Issue Title" , releaseNotes . Releases [ 0 ] . ReleaseNoteItems [ 0 ] . Title ) ;
5659 }
5760
61+ [ Fact ]
62+ public void ErrorLoggedWhenRepoIsNotSpecified ( )
63+ {
64+ var result = _sut . VerifyArgumentsAndWriteErrorsToConsole ( new GitReleaseNotesArguments ( ) ) ;
65+
66+ Assert . False ( result ) ;
67+ _log . Received ( ) . WriteLine ( "GitHub repository name must be specified [/Repo .../...]" ) ;
68+ }
69+
70+ [ Theory ]
71+ [ InlineData ( "Foo" , false ) ]
72+ [ InlineData ( "Org/Repo" , true ) ]
73+ [ InlineData ( "Org/Repo/SomethingElse" , false ) ]
74+ public void RepositoryMustBeInCorrectFormat ( string repo , bool success )
75+ {
76+ var result = _sut . VerifyArgumentsAndWriteErrorsToConsole ( new GitReleaseNotesArguments
77+ {
78+ Repo = repo ,
79+ Token = "Foo"
80+ } ) ;
81+
82+ if ( success )
83+ {
84+ Assert . True ( result ) ;
85+ }
86+ else
87+ {
88+ Assert . False ( result ) ;
89+ _log . Received ( ) . WriteLine ( "GitHub repository name should be in format Organisation/RepoName" ) ;
90+ }
91+ }
92+
93+ [ Fact ]
94+ public void MustSpecifyToken ( )
95+ {
96+ var result = _sut . VerifyArgumentsAndWriteErrorsToConsole ( new GitReleaseNotesArguments
97+ {
98+ Repo = "Foo/Bar"
99+ } ) ;
100+
101+ Assert . False ( result ) ;
102+ _log . Received ( ) . WriteLine ( "You must specify a GitHub Authentication token with the /Token argument" ) ;
103+ }
104+
105+ [ Fact ]
106+ public void MustSpecifyVersionWhenPublishFlagIsSet ( )
107+ {
108+ var result = _sut . VerifyArgumentsAndWriteErrorsToConsole ( new GitReleaseNotesArguments
109+ {
110+ Repo = "Foo/Bar" ,
111+ Token = "Baz" ,
112+ Publish = true
113+ } ) ;
114+
115+ Assert . False ( result ) ;
116+ _log . Received ( ) . WriteLine ( "You must specifiy the version [/Version ...] (will be tag) when using the /Publish flag" ) ;
117+ }
118+
58119 private static Commit CreateCommit ( string message , DateTimeOffset when )
59120 {
60121 var commit = Substitute . For < Commit > ( ) ;
0 commit comments