@@ -15,4 +15,118 @@ public void AddParameter_ConsidersEnumMemberAttribute(EventAction value, string
1515
1616 Assert . That ( url , Is . EqualTo ( $ "{ basePath } ?event_action={ expectedQueryParamValue } ") ) ;
1717 }
18+
19+ [ TestCase ]
20+ public void AppendSegmentToUrl_ValueIsNullIncludeSegmentSeparatorFalse_ReturnsUrlWithoutAnyChange ( )
21+ {
22+ // Arrange
23+ const string basePath = "https://gitlab.org/api/v4/stuff" ;
24+ var url = basePath ;
25+ var expected = basePath ;
26+
27+ // Act
28+ var actual = NGitLab . Impl . Utils . AppendSegmentToUrl < string > ( url , value : null , includeSegmentSeparator : false ) ;
29+
30+ // Assert
31+ Assert . That ( expected , Is . EqualTo ( actual ) ) ;
32+ }
33+
34+ [ TestCase ]
35+ public void AppendSegmentToUrl_ValueIsNullIncludeSegmentSeparatorTrue_ReturnsUrlWithoutAnyChange ( )
36+ {
37+ // Arrange
38+ const string basePath = "https://gitlab.org/api/v4/stuff" ;
39+ var url = basePath ;
40+ var expected = basePath ;
41+
42+ // Act
43+ var actual = NGitLab . Impl . Utils . AppendSegmentToUrl < string > ( url , value : null , includeSegmentSeparator : true ) ;
44+
45+ // Assert
46+ Assert . That ( expected , Is . EqualTo ( actual ) ) ;
47+ }
48+
49+ [ TestCase ]
50+ public void AppendSegmentToUrl_UrlAlreadyContainsQueryString_ThrowsInvalidOperationException ( )
51+ {
52+ // Arrange
53+ const string basePath = "https://gitlab.org/api/v4/stuff" ;
54+ var url = basePath ;
55+
56+ url = NGitLab . Impl . Utils . AddParameter ( url , "param1" , "one" ) ;
57+
58+ // Act and Assert
59+ Assert . That ( ( ) => NGitLab . Impl . Utils . AppendSegmentToUrl ( url , "segment" ) , Throws . InvalidOperationException ) ;
60+ }
61+
62+ [ TestCase ( "https://gitlab.org/api/v4/stuff/" , "/segment" ) ]
63+ [ TestCase ( "https://gitlab.org/api/v4/stuff/" , "segment" ) ]
64+ [ TestCase ( "https://gitlab.org/api/v4/stuff" , "/segment" ) ]
65+ [ TestCase ( "https://gitlab.org/api/v4/stuff" , "segment" ) ]
66+ public void AppendSegmentToUrl_IncludeSegmentSeparatorIsTrue_SegmentAppendedWithSeparator ( string basePath , string segment )
67+ {
68+ // Arrange
69+ var url = basePath ;
70+ var expected = "https://gitlab.org/api/v4/stuff/segment" ;
71+
72+ // Act
73+ var actual = NGitLab . Impl . Utils . AppendSegmentToUrl ( url , value : segment , includeSegmentSeparator : true ) ;
74+
75+ // Assert
76+ Assert . That ( expected , Is . EqualTo ( actual ) ) ;
77+ }
78+
79+ [ TestCase ( "https://gitlab.org/api/v4/stuff/" , "/segment" ) ]
80+ [ TestCase ( "https://gitlab.org/api/v4/stuff/" , "segment" ) ]
81+ [ TestCase ( "https://gitlab.org/api/v4/stuff" , "/segment" ) ]
82+ [ TestCase ( "https://gitlab.org/api/v4/stuff" , "segment" ) ]
83+ public void AppendSegmentToUrl_IncludeSegmentSeparatorIsFalse_SegmentAppendedWithoutSeparator ( string basePath , string segment )
84+ {
85+ // Arrange
86+ var url = basePath ;
87+ var expected = "https://gitlab.org/api/v4/stuffsegment" ;
88+
89+ // Act
90+ var actual = NGitLab . Impl . Utils . AppendSegmentToUrl ( url , value : segment , includeSegmentSeparator : false ) ;
91+
92+ // Assert
93+ Assert . That ( expected , Is . EqualTo ( actual ) ) ;
94+ }
95+
96+ [ TestCase ( "https://gitlab.org/api/v4/stuff.bz2" , FileArchiveFormat . Bz2 ) ]
97+ [ TestCase ( "https://gitlab.org/api/v4/stuff.gz" , FileArchiveFormat . Gz ) ]
98+ [ TestCase ( "https://gitlab.org/api/v4/stuff.tar" , FileArchiveFormat . Tar ) ]
99+ [ TestCase ( "https://gitlab.org/api/v4/stuff.tar.bz2" , FileArchiveFormat . TarBz2 ) ]
100+ [ TestCase ( "https://gitlab.org/api/v4/stuff.tar.gz" , FileArchiveFormat . TarGz ) ]
101+ [ TestCase ( "https://gitlab.org/api/v4/stuff.tb2" , FileArchiveFormat . Tb2 ) ]
102+ [ TestCase ( "https://gitlab.org/api/v4/stuff.tbz" , FileArchiveFormat . Tbz ) ]
103+ [ TestCase ( "https://gitlab.org/api/v4/stuff.tbz2" , FileArchiveFormat . Tbz2 ) ]
104+ [ TestCase ( "https://gitlab.org/api/v4/stuff.zip" , FileArchiveFormat . Zip ) ]
105+ public void AppendSegmentToUrl_ValueIsEnumWithEnumMemberAttribute_EnumMemberValueAppended ( string expected , FileArchiveFormat fileArchiveFormat )
106+ {
107+ // Arrange
108+ const string basePath = "https://gitlab.org/api/v4/stuff" ;
109+ var url = basePath ;
110+
111+ // Act
112+ var actual = NGitLab . Impl . Utils . AppendSegmentToUrl ( url , value : fileArchiveFormat , includeSegmentSeparator : false ) ;
113+
114+ // Assert
115+ Assert . That ( expected , Is . EqualTo ( actual ) ) ;
116+ }
117+
118+ [ TestCase ( "https://gitlab.org/api/v4/stuff/Group" , BadgeKind . Group ) ]
119+ [ TestCase ( "https://gitlab.org/api/v4/stuff/Project" , BadgeKind . Project ) ]
120+ public void AppendSegmentToUrl_ValueIsEnumWithoutEnumMemberAttribute_EnumToStringValueAppended ( string expected , BadgeKind badgeKind )
121+ {
122+ // Arrange
123+ const string basePath = "https://gitlab.org/api/v4/stuff" ;
124+ var url = basePath ;
125+
126+ // Act
127+ var actual = NGitLab . Impl . Utils . AppendSegmentToUrl ( url , value : badgeKind , includeSegmentSeparator : true ) ;
128+
129+ // Assert
130+ Assert . That ( expected , Is . EqualTo ( actual ) ) ;
131+ }
18132}
0 commit comments