-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnitTestGeneral.cs
More file actions
234 lines (181 loc) · 7.99 KB
/
Copy pathUnitTestGeneral.cs
File metadata and controls
234 lines (181 loc) · 7.99 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Mayerch1.GithubUpdateCheck;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
namespace GithubUpdateCheckTest
{
/// <summary>
/// Unit test of the GithubUpdateCheck
/// As the update checker needs a connection to github for almost all funcionality, this is closer to an integration test than a unit test
/// This unit test can take more than 20s runtime
/// </summary>
[TestClass]
[ExcludeFromCodeCoverage]
public class UnitTestGeneral
{
[TestMethod]
public void TestDefaultConstructorIsIncremental()
{
// compare type is private, therefore use compare
GithubUpdateCheck defaultCon = new GithubUpdateCheck("", "");
Assert.AreEqual(defaultCon.CompareType, CompareType.Incremental);
}
[TestMethod]
public void TestAreEqualFalse()
{
// change one member at a time
bool isEqual;
GithubUpdateCheck aCmpType = new GithubUpdateCheck("Mayerch1", "DIFFERENT", CompareType.Incremental);
GithubUpdateCheck bCmpType = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Incremental);
isEqual = (aCmpType == bCmpType);
Assert.IsFalse(isEqual);
GithubUpdateCheck aAuthor = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Boolean);
GithubUpdateCheck bAuthor = new GithubUpdateCheck("DIFFERENT", "GithubUpdateCheck", CompareType.Boolean);
isEqual = (aAuthor == bAuthor);
Assert.IsFalse(isEqual);
GithubUpdateCheck aRepo = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Boolean);
GithubUpdateCheck bRepo = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Incremental);
isEqual = (aRepo == bRepo);
Assert.IsFalse(isEqual);
}
[TestMethod]
public void TestAreEqualTrue()
{
// only if all are the same, it should return true
GithubUpdateCheck aCmpType = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Boolean);
GithubUpdateCheck bCmpType = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Boolean);
bool isEqual = (aCmpType == bCmpType);
Assert.IsTrue(isEqual);
}
[TestMethod]
public void TestAreNotEqualTrue()
{
// assuming == is working, it is enough to test a single !=, as it returns !(==)
GithubUpdateCheck aCmpType = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Boolean);
GithubUpdateCheck bCmpType = new GithubUpdateCheck("DIFFERENT", "GithubUpdateCheck", CompareType.Boolean);
bool isDifferent = (aCmpType != bCmpType);
Assert.IsTrue(isDifferent);
}
[TestMethod]
public void TestNullInvertTrue()
{
GithubUpdateCheck obj = null;
Assert.IsTrue(null == obj);
}
[TestMethod]
public void TestNullInvertFalse()
{
GithubUpdateCheck obj = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Boolean);
Assert.IsFalse(null == obj);
}
[TestMethod]
public void TestEqualNullTrue()
{
GithubUpdateCheck obj = null;
Assert.IsTrue(obj == null);
}
[TestMethod]
public void TestEqualNullFalse()
{
GithubUpdateCheck obj = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Boolean);
Assert.IsFalse(obj == null);
}
[TestMethod]
public void TestNotEqualNullTrue()
{
GithubUpdateCheck obj = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Boolean);
Assert.IsTrue(obj != null);
}
[TestMethod]
public void TestNotEqualNullFalse()
{
GithubUpdateCheck obj = null;
Assert.IsFalse(obj != null);
}
[TestMethod]
public void TestEqualsMethodFalse()
{
GithubUpdateCheck aCmpType = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Boolean);
GithubUpdateCheck bCmpType = new GithubUpdateCheck("DIFFERENT", "GithubUpdateCheck", CompareType.Boolean);
Assert.IsFalse(aCmpType.Equals(bCmpType));
}
[TestMethod]
public void TestEqualsMethodTrue()
{
GithubUpdateCheck aCmpType = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Incremental);
GithubUpdateCheck bCmpType = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheck", CompareType.Incremental);
Assert.IsTrue(aCmpType.Equals(bCmpType));
}
[TestMethod]
public void TestNullConstructor()
{
// if the repo is invalid,
GithubUpdateCheck obj = new GithubUpdateCheck(null, null);
Assert.IsFalse(obj.IsUpdateAvailable("1.0.0"));
}
[TestMethod]
public void TestNoRelease()
{
// this repo doesn't have releases
GithubUpdateCheck obj = new GithubUpdateCheck("Mayerch1", "BunnyVisual");
Assert.IsFalse(obj.IsUpdateAvailable("1.0.0.0"));
}
[TestMethod]
public void TestInvalidRepository()
{
// random uuid, high change for non-existent repo
GithubUpdateCheck obj = new GithubUpdateCheck("Mayerch1", "cb91fb82-9621-479a-9c5a-23e565e6390d");
obj.IsUpdateAvailable("1.0.0.0");
}
[TestMethod]
public void TestInvalidUser()
{
// random uuid, high change for non-existent repo
GithubUpdateCheck obj = new GithubUpdateCheck("5fe54fd3-2fd8-48ff-8f63-1b8575348b5f", "GithubUpdateCheck");
obj.IsUpdateAvailable("1.0.0.0");
}
[TestMethod]
public async Task TestAsyncRequest()
{
GithubUpdateCheck obj = new GithubUpdateCheck("Mayerch1", "TheDiscordSoundboard");
// it cannot be guaranteed, that the major version of TDS will stay at 2
// more specific compares cannot be made
Assert.IsTrue(await obj.IsUpdateAvailableAsync("1.0.0", VersionChange.Major));
}
[TestMethod]
public async Task TestInvalidRepositoryAsync()
{
// random uuid, high change for non-existent repo
GithubUpdateCheck obj = new GithubUpdateCheck("Mayerch1", "cb91fb82-9621-479a-9c5a-23e565e6390d");
Assert.IsFalse(await obj.IsUpdateAvailableAsync("1.0.0.0"));
}
[TestMethod]
public async Task TestInvalidUserAsync()
{
// random uuid, high change for non-existent repo
GithubUpdateCheck obj = new GithubUpdateCheck("5fe54fd3-2fd8-48ff-8f63-1b8575348b5f", "GithubUpdateCheck");
Assert.IsFalse(await obj.IsUpdateAvailableAsync("1.0.0.0"));
}
[TestMethod]
public void TestGetVersionIncremental()
{
GithubUpdateCheck getV = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheckUnitTest", CompareType.Incremental);
var version = getV.Version();
Assert.IsTrue(version.Equals("2.4.1.5"));
}
[TestMethod]
public void TestGetVersionBoolean()
{
GithubUpdateCheck getV = new GithubUpdateCheck("Mayerch1", "GithubUpdateCheckUnitTest", CompareType.Boolean);
var version = getV.Version();
Assert.IsTrue(version.Equals("v.2.4.1.5"));
}
[TestMethod]
public void TestGetVersionNoVersion()
{
// repo doesn't have releases
GithubUpdateCheck getV = new GithubUpdateCheck("Mayerch1", "BunnyVisual", CompareType.Incremental);
Assert.ThrowsException<Mayerch1.GithubUpdateCheck.NoVersionException>(() => getV.Version());
}
}
}