1
1
namespace Cake . AzureDevOps . Tests . Repos . PullRequest
2
2
{
3
+ using System ;
3
4
using System . Collections . Generic ;
4
5
using System . Linq ;
5
6
using Cake . AzureDevOps . Repos . PullRequest ;
@@ -767,97 +768,115 @@ public void Should_Return_Valid_Comment_Threads()
767
768
768
769
public sealed class TheCreateCommentMethod
769
770
{
770
- [ Fact ]
771
- public void Should_Throw_If_Comment_Is_Null ( )
771
+ [ Theory ]
772
+ [ InlineData ( ( string ) null , typeof ( ArgumentNullException ) ) ]
773
+ [ InlineData ( "" , typeof ( ArgumentOutOfRangeException ) ) ]
774
+ [ InlineData ( " " , typeof ( ArgumentOutOfRangeException ) ) ]
775
+ public void Should_Throw_If_Comment_Is_Null_Or_Empty_Or_Whitespace ( string comment , Type expectedExceptionType )
772
776
{
773
777
// Given
774
778
var fixture = new PullRequestFixture ( BasePullRequestFixture . ValidAzureDevOpsServerUrl , 100 ) ;
775
779
var pullRequest = new AzureDevOpsPullRequest ( fixture . Log , fixture . Settings , fixture . GitClientFactory ) ;
776
780
777
781
// When
778
- var result = Record . Exception ( ( ) => pullRequest . CreateComment ( null ) ) ;
782
+ var result = Record . Exception ( ( ) => pullRequest . CreateComment ( comment ) ) as ArgumentException ;
779
783
780
784
// Then
781
- result . IsArgumentNullException ( "comment" ) ;
785
+ result . ShouldNotBeNull ( ) ;
786
+ result . IsArgumentException ( expectedExceptionType , "comment" ) ;
782
787
}
783
788
784
789
[ Fact ]
785
- public void Should_Throw_If_Comment_Is_Empty ( )
790
+ public void Should_Return_Null_If_Null_Is_Returned_From_Git_Client ( )
786
791
{
787
792
// Given
788
- var fixture = new PullRequestFixture ( BasePullRequestFixture . ValidAzureDevOpsServerUrl , 100 ) ;
793
+ var fixture = new PullRequestFixture ( BasePullRequestFixture . ValidAzureDevOpsServerUrl , 100 )
794
+ {
795
+ GitClientFactory = new FakeNullForMethodsGitClientFactory ( ) ,
796
+ } ;
789
797
var pullRequest = new AzureDevOpsPullRequest ( fixture . Log , fixture . Settings , fixture . GitClientFactory ) ;
790
798
791
799
// When
792
- var result = Record . Exception ( ( ) => pullRequest . CreateComment ( string . Empty ) ) ;
800
+ var thread = pullRequest . CreateComment ( "Foo" ) ;
793
801
794
802
// Then
795
- result . IsArgumentOutOfRangeException ( "comment" ) ;
803
+ thread . ShouldBeNull ( ) ;
796
804
}
797
805
798
806
[ Fact ]
799
- public void Should_Throw_If_Comment_Is_Whitespace ( )
807
+ public void Should_Create_Valid_Thread_With_One_Comment ( )
800
808
{
801
809
// Given
802
810
var fixture = new PullRequestFixture ( BasePullRequestFixture . ValidAzureDevOpsServerUrl , 100 ) ;
803
811
var pullRequest = new AzureDevOpsPullRequest ( fixture . Log , fixture . Settings , fixture . GitClientFactory ) ;
804
812
805
813
// When
806
- var result = Record . Exception ( ( ) => pullRequest . CreateComment ( " " ) ) ;
814
+ var thread = pullRequest . CreateComment ( "Valid" ) ;
807
815
808
816
// Then
809
- result . IsArgumentOutOfRangeException ( "comment" ) ;
817
+ thread . ShouldNotBeNull ( ) ;
818
+ thread . Status . ShouldBe ( AzureDevOpsCommentThreadStatus . Active ) ;
819
+ thread . Comments . ShouldNotBeNull ( ) ;
820
+ thread . Comments . Count ( ) . ShouldBe ( 1 ) ;
821
+
822
+ var comment = thread . Comments . First ( ) ;
823
+ comment . CommentType . ShouldBe ( AzureDevOpsCommentType . System ) ;
824
+ comment . IsDeleted . ShouldBeFalse ( ) ;
825
+ comment . Content . ShouldBe ( "Valid" ) ;
810
826
}
827
+ }
811
828
829
+ public sealed class TheCreateCommentThreadMethod
830
+ {
812
831
[ Fact ]
813
- public void Should_Not_Throw_If_Null_Is_Returned ( )
832
+ public void Should_Throw_If_Input_Thread_Is_Null ( )
814
833
{
815
834
// Given
816
- var fixture = new PullRequestFixture ( BasePullRequestFixture . ValidAzureDevOpsServerUrl , 100 )
817
- {
818
- GitClientFactory = new FakeNullForMethodsGitClientFactory ( ) ,
819
- } ;
835
+ var fixture = new PullRequestFixture ( BasePullRequestFixture . ValidAzureDevOpsServerUrl , 100 ) ;
820
836
var pullRequest = new AzureDevOpsPullRequest ( fixture . Log , fixture . Settings , fixture . GitClientFactory ) ;
821
837
822
838
// When
823
- pullRequest . CreateComment ( "Foo" ) ;
839
+ var result = Record . Exception ( ( ) => pullRequest . CreateCommentThread ( null ) ) ;
824
840
825
841
// Then
826
- // ?? Nothing to validate here since the method returns void
842
+ result . IsArgumentNullException ( "thread" ) ;
827
843
}
828
- }
829
844
830
- public sealed class TheCreateCommentThreadMethod
831
- {
832
845
[ Fact ]
833
- public void Should_Throw_If_Input_Thread_Is_Null ( )
846
+ public void Should_Return_Null_If_Pull_Request_Is_Invalid ( )
834
847
{
835
848
// Given
836
- var fixture = new PullRequestFixture ( BasePullRequestFixture . ValidAzureDevOpsServerUrl , 100 ) ;
849
+ var fixture = new PullRequestFixture ( BasePullRequestFixture . ValidAzureDevOpsServerUrl , 100 )
850
+ {
851
+ GitClientFactory = new FakeNullGitClientFactory ( ) ,
852
+ } ;
853
+ fixture . Settings . ThrowExceptionIfPullRequestCouldNotBeFound = false ;
854
+
837
855
var pullRequest = new AzureDevOpsPullRequest ( fixture . Log , fixture . Settings , fixture . GitClientFactory ) ;
838
856
839
857
// When
840
- var result = Record . Exception ( ( ) => pullRequest . CreateCommentThread ( null ) ) ;
858
+ var outThread = pullRequest . CreateCommentThread ( new AzureDevOpsPullRequestCommentThread ( ) ) ;
841
859
842
860
// Then
843
- result . IsArgumentNullException ( "thread" ) ;
861
+ outThread . ShouldBeNull ( ) ;
844
862
}
845
863
846
864
[ Fact ]
847
- public void Should_Not_Throw_If_Null_Is_Returned ( )
865
+ public void Should_Return_Null_If_Null_Is_Returned_From_Git_Client ( )
848
866
{
849
867
// Given
850
868
var fixture = new PullRequestFixture ( BasePullRequestFixture . ValidAzureDevOpsServerUrl , 100 )
851
869
{
852
870
GitClientFactory = new FakeNullForMethodsGitClientFactory ( ) ,
853
871
} ;
872
+
854
873
var pullRequest = new AzureDevOpsPullRequest ( fixture . Log , fixture . Settings , fixture . GitClientFactory ) ;
855
874
856
875
// When
857
- pullRequest . CreateCommentThread ( new AzureDevOpsPullRequestCommentThread ( ) ) ;
876
+ var outThread = pullRequest . CreateCommentThread ( new AzureDevOpsPullRequestCommentThread ( ) ) ;
858
877
859
878
// Then
860
- // ?? Nothing to validate here since the method returns void
879
+ outThread . ShouldBeNull ( ) ;
861
880
}
862
881
863
882
[ Fact ]
@@ -866,12 +885,15 @@ public void Should_Create_Valid_Comment_Thread()
866
885
// Given
867
886
var fixture = new PullRequestFixture ( BasePullRequestFixture . ValidAzureDevOpsUrl , 200 ) ;
868
887
var pullRequest = new AzureDevOpsPullRequest ( fixture . Log , fixture . Settings , fixture . GitClientFactory ) ;
888
+ var inThread = new AzureDevOpsPullRequestCommentThread { Id = 300 , Status = AzureDevOpsCommentThreadStatus . Pending , FilePath = "/index.html" } ;
869
889
870
890
// When
871
- pullRequest . CreateCommentThread ( new AzureDevOpsPullRequestCommentThread { Id = 300 , Status = AzureDevOpsCommentThreadStatus . Pending , FilePath = "/index.html" } ) ;
891
+ var outThread = pullRequest . CreateCommentThread ( inThread ) ;
872
892
873
893
// Then
874
- // ?? Nothing to validate here since the method returns void
894
+ outThread . Id . ShouldBe ( inThread . Id ) ;
895
+ outThread . Status . ShouldBe ( inThread . Status ) ;
896
+ outThread . FilePath . ShouldBeEquivalentTo ( inThread . FilePath ) ;
875
897
}
876
898
}
877
899
0 commit comments