@@ -60,5 +60,138 @@ public void GetCommitTime_ShouldReturnCorrectTime_OnSuccess()
6060 // Assert
6161 Assert . Equal ( "2023-08-21 12:34:56 +0000" , result ) ;
6262 }
63+
64+ [ Fact ]
65+ public void GetGitCommits_ShouldReturnCorrectRange_WhenBothCommitsArePresent ( )
66+ {
67+ // Arrange
68+ var processWrapperMock = new Mock < IProcessWrapper > ( ) ;
69+
70+ var gitLogOutput = "commit5\n commit4\n commit3\n commit2\n commit1" ;
71+ var processResult = new ProcessResult ( gitLogOutput , string . Empty , 0 ) ;
72+ processWrapperMock . Setup ( pw => pw . Start ( It . IsAny < ProcessStartInfo > ( ) , null ) ) . Returns ( processResult ) ;
73+
74+ var gitHelper = new GitHelper ( processWrapperMock . Object ) ;
75+
76+ // Act
77+ var result = gitHelper . GetGitCommits ( "commit2" , "commit4" ) ;
78+
79+ // Assert
80+ Assert . Equal ( new [ ] { "commit4" , "commit3" , "commit2" } , result ) ;
81+ }
82+
83+ [ Fact ]
84+ public void GetGitCommits_ShouldReturnFullRange_WhenEarliestAndLatestAreEmpty ( )
85+ {
86+ // Arrange
87+ var processWrapperMock = new Mock < IProcessWrapper > ( ) ;
88+
89+ var gitLogOutput = "commit5\n commit4\n commit3\n commit2\n commit1" ;
90+ var processResult = new ProcessResult ( gitLogOutput , string . Empty , 0 ) ;
91+ processWrapperMock . Setup ( pw => pw . Start ( It . IsAny < ProcessStartInfo > ( ) , null ) ) . Returns ( processResult ) ;
92+
93+ var gitHelper = new GitHelper ( processWrapperMock . Object ) ;
94+
95+ // Act
96+ var result = gitHelper . GetGitCommits ( "" , "" ) ;
97+
98+ // Assert
99+ Assert . Equal ( new [ ] { "commit5" , "commit4" , "commit3" , "commit2" , "commit1" } , result ) ;
100+ }
101+
102+ [ Fact ]
103+ public void GetGitCommits_ShouldReturnPartialRange_WhenOnlyEarliestCommitIsSpecified ( )
104+ {
105+ // Arrange
106+ var processWrapperMock = new Mock < IProcessWrapper > ( ) ;
107+
108+ var gitLogOutput = "commit5\n commit4\n commit3\n commit2\n commit1" ;
109+ var processResult = new ProcessResult ( gitLogOutput , string . Empty , 0 ) ;
110+ processWrapperMock . Setup ( pw => pw . Start ( It . IsAny < ProcessStartInfo > ( ) , null ) ) . Returns ( processResult ) ;
111+
112+ var gitHelper = new GitHelper ( processWrapperMock . Object ) ;
113+
114+ // Act
115+ var result = gitHelper . GetGitCommits ( "commit3" , "" ) ;
116+
117+ // Assert
118+ Assert . Equal ( new [ ] { "commit5" , "commit4" , "commit3" } , result ) ;
119+ }
120+
121+ [ Fact ]
122+ public void GetGitCommits_ShouldReturnPartialRange_WhenOnlyLatestCommitIsSpecified ( )
123+ {
124+ // Arrange
125+ var processWrapperMock = new Mock < IProcessWrapper > ( ) ;
126+
127+ var gitLogOutput = "commit5\n commit4\n commit3\n commit2\n commit1" ;
128+ var processResult = new ProcessResult ( gitLogOutput , string . Empty , 0 ) ;
129+ processWrapperMock . Setup ( pw => pw . Start ( It . IsAny < ProcessStartInfo > ( ) , null ) ) . Returns ( processResult ) ;
130+
131+ var gitHelper = new GitHelper ( processWrapperMock . Object ) ;
132+
133+ // Act
134+ var result = gitHelper . GetGitCommits ( "" , "commit3" ) ;
135+
136+ // Assert
137+ Assert . Equal ( new [ ] { "commit3" , "commit2" , "commit1" } , result ) ;
138+ }
139+
140+ [ Fact ]
141+ public void GetGitCommits_ShouldReturnEmptyArray_WhenCommitsAreInWrongOrder ( )
142+ {
143+ // Arrange
144+ var processWrapperMock = new Mock < IProcessWrapper > ( ) ;
145+
146+ var gitLogOutput = "commit5\n commit4\n commit3\n commit2\n commit1" ;
147+ var processResult = new ProcessResult ( gitLogOutput , string . Empty , 0 ) ;
148+ processWrapperMock . Setup ( pw => pw . Start ( It . IsAny < ProcessStartInfo > ( ) , null ) ) . Returns ( processResult ) ;
149+
150+ var gitHelper = new GitHelper ( processWrapperMock . Object ) ;
151+
152+ // Act
153+ var result = gitHelper . GetGitCommits ( "commit4" , "commit2" ) ;
154+
155+ // Assert
156+ Assert . Empty ( result ) ;
157+ }
158+
159+ [ Fact ]
160+ public void GetGitCommits_ShouldReturnEmptyArray_WhenEarliestCommitIsNotFound ( )
161+ {
162+ // Arrange
163+ var processWrapperMock = new Mock < IProcessWrapper > ( ) ;
164+
165+ var gitLogOutput = "commit5\n commit4\n commit3\n commit2\n commit1" ;
166+ var processResult = new ProcessResult ( gitLogOutput , string . Empty , 0 ) ;
167+ processWrapperMock . Setup ( pw => pw . Start ( It . IsAny < ProcessStartInfo > ( ) , null ) ) . Returns ( processResult ) ;
168+
169+ var gitHelper = new GitHelper ( processWrapperMock . Object ) ;
170+
171+ // Act
172+ var result = gitHelper . GetGitCommits ( "nonexistentCommit" , "commit2" ) ;
173+
174+ // Assert
175+ Assert . Empty ( result ) ;
176+ }
177+
178+ [ Fact ]
179+ public void GetGitCommits_ShouldReturnEmptyArray_WhenLatestCommitIsNotFound ( )
180+ {
181+ // Arrange
182+ var processWrapperMock = new Mock < IProcessWrapper > ( ) ;
183+
184+ var gitLogOutput = "commit5\n commit4\n commit3\n commit2\n commit1" ;
185+ var processResult = new ProcessResult ( gitLogOutput , string . Empty , 0 ) ;
186+ processWrapperMock . Setup ( pw => pw . Start ( It . IsAny < ProcessStartInfo > ( ) , null ) ) . Returns ( processResult ) ;
187+
188+ var gitHelper = new GitHelper ( processWrapperMock . Object ) ;
189+
190+ // Act
191+ var result = gitHelper . GetGitCommits ( "commit4" , "nonexistentCommit" ) ;
192+
193+ // Assert
194+ Assert . Empty ( result ) ;
195+ }
63196 }
64197}
0 commit comments