-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathUtilsTests.cs
More file actions
132 lines (108 loc) · 5.09 KB
/
UtilsTests.cs
File metadata and controls
132 lines (108 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using NGitLab.Models;
using NUnit.Framework;
namespace NGitLab.Tests.Impl;
public class UtilsTests
{
[TestCase(EventAction.PushedTo, "pushed+to")]
[TestCase(EventAction.Accepted, "Accepted")]
public void AddParameter_ConsidersEnumMemberAttribute(EventAction value, string expectedQueryParamValue)
{
const string basePath = "https://gitlab.org/api/v4/stuff";
var url = basePath;
url = NGitLab.Impl.Utils.AddParameter(url, "event_action", value);
Assert.That(url, Is.EqualTo($"{basePath}?event_action={expectedQueryParamValue}"));
}
[TestCase]
public void AppendSegmentToUrl_ValueIsNullIncludeSegmentSeparatorFalse_ReturnsUrlWithoutAnyChange()
{
// Arrange
const string basePath = "https://gitlab.org/api/v4/stuff";
var url = basePath;
var expected = basePath;
// Act
var actual = NGitLab.Impl.Utils.AppendSegmentToUrl<string>(url, value: null, includeSegmentSeparator: false);
// Assert
Assert.That(expected, Is.EqualTo(actual));
}
[TestCase]
public void AppendSegmentToUrl_ValueIsNullIncludeSegmentSeparatorTrue_ReturnsUrlWithoutAnyChange()
{
// Arrange
const string basePath = "https://gitlab.org/api/v4/stuff";
var url = basePath;
var expected = basePath;
// Act
var actual = NGitLab.Impl.Utils.AppendSegmentToUrl<string>(url, value: null, includeSegmentSeparator: true);
// Assert
Assert.That(expected, Is.EqualTo(actual));
}
[TestCase]
public void AppendSegmentToUrl_UrlAlreadyContainsQueryString_ThrowsInvalidOperationException()
{
// Arrange
const string basePath = "https://gitlab.org/api/v4/stuff";
var url = basePath;
url = NGitLab.Impl.Utils.AddParameter(url, "param1", "one");
// Act and Assert
Assert.That(() => NGitLab.Impl.Utils.AppendSegmentToUrl(url, "segment"), Throws.InvalidOperationException);
}
[TestCase("https://gitlab.org/api/v4/stuff/", "/segment")]
[TestCase("https://gitlab.org/api/v4/stuff/", "segment")]
[TestCase("https://gitlab.org/api/v4/stuff", "/segment")]
[TestCase("https://gitlab.org/api/v4/stuff", "segment")]
public void AppendSegmentToUrl_IncludeSegmentSeparatorIsTrue_SegmentAppendedWithSeparator(string basePath, string segment)
{
// Arrange
var url = basePath;
var expected = "https://gitlab.org/api/v4/stuff/segment";
// Act
var actual = NGitLab.Impl.Utils.AppendSegmentToUrl(url, value: segment, includeSegmentSeparator: true);
// Assert
Assert.That(expected, Is.EqualTo(actual));
}
[TestCase("https://gitlab.org/api/v4/stuff/", "/segment")]
[TestCase("https://gitlab.org/api/v4/stuff/", "segment")]
[TestCase("https://gitlab.org/api/v4/stuff", "/segment")]
[TestCase("https://gitlab.org/api/v4/stuff", "segment")]
public void AppendSegmentToUrl_IncludeSegmentSeparatorIsFalse_SegmentAppendedWithoutSeparator(string basePath, string segment)
{
// Arrange
var url = basePath;
var expected = "https://gitlab.org/api/v4/stuffsegment";
// Act
var actual = NGitLab.Impl.Utils.AppendSegmentToUrl(url, value: segment, includeSegmentSeparator: false);
// Assert
Assert.That(expected, Is.EqualTo(actual));
}
[TestCase("https://gitlab.org/api/v4/stuff.bz2", FileArchiveFormat.Bz2)]
[TestCase("https://gitlab.org/api/v4/stuff.gz", FileArchiveFormat.Gz)]
[TestCase("https://gitlab.org/api/v4/stuff.tar", FileArchiveFormat.Tar)]
[TestCase("https://gitlab.org/api/v4/stuff.tar.bz2", FileArchiveFormat.TarBz2)]
[TestCase("https://gitlab.org/api/v4/stuff.tar.gz", FileArchiveFormat.TarGz)]
[TestCase("https://gitlab.org/api/v4/stuff.tb2", FileArchiveFormat.Tb2)]
[TestCase("https://gitlab.org/api/v4/stuff.tbz", FileArchiveFormat.Tbz)]
[TestCase("https://gitlab.org/api/v4/stuff.tbz2", FileArchiveFormat.Tbz2)]
[TestCase("https://gitlab.org/api/v4/stuff.zip", FileArchiveFormat.Zip)]
public void AppendSegmentToUrl_ValueIsEnumWithEnumMemberAttribute_EnumMemberValueAppended(string expected, FileArchiveFormat fileArchiveFormat)
{
// Arrange
const string basePath = "https://gitlab.org/api/v4/stuff";
var url = basePath;
// Act
var actual = NGitLab.Impl.Utils.AppendSegmentToUrl(url, value: fileArchiveFormat, includeSegmentSeparator: false);
// Assert
Assert.That(expected, Is.EqualTo(actual));
}
[TestCase("https://gitlab.org/api/v4/stuff/Group", BadgeKind.Group)]
[TestCase("https://gitlab.org/api/v4/stuff/Project", BadgeKind.Project)]
public void AppendSegmentToUrl_ValueIsEnumWithoutEnumMemberAttribute_EnumToStringValueAppended(string expected, BadgeKind badgeKind)
{
// Arrange
const string basePath = "https://gitlab.org/api/v4/stuff";
var url = basePath;
// Act
var actual = NGitLab.Impl.Utils.AppendSegmentToUrl(url, value: badgeKind, includeSegmentSeparator: true);
// Assert
Assert.That(expected, Is.EqualTo(actual));
}
}