1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
5 | using Persistence;
|
---|
6 |
|
---|
7 | namespace UnitTests {
|
---|
8 | /// <summary>
|
---|
9 | ///This is a test class for HeuristicLabUserTest and is intended
|
---|
10 | ///to contain all HeuristicLabUserTest Unit Tests
|
---|
11 | ///</summary>
|
---|
12 | [TestClass()]
|
---|
13 | public class HeuristicLabUserTest : AbstractHeuristicLabTest {
|
---|
14 | private TestContext testContextInstance;
|
---|
15 |
|
---|
16 | /// <summary>
|
---|
17 | /// inserts, modifies and deletes a new user into the database
|
---|
18 | /// </summary>
|
---|
19 | [TestMethod()]
|
---|
20 | public void modifyUserTest() {
|
---|
21 | // insert new user
|
---|
22 | HeuristicLabUser user = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
23 | db.HeuristicLabUsers.InsertOnSubmit(user);
|
---|
24 | db.SubmitChanges();
|
---|
25 | HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == "testname");
|
---|
26 | Assert.IsNotNull(u);
|
---|
27 | Assert.AreEqual<string>("testname", u.UserName);
|
---|
28 | Assert.AreEqual<string>("testemail", u.Email);
|
---|
29 | Assert.AreEqual<string>("testquestion", u.PasswordQuestion);
|
---|
30 | Assert.AreEqual<string>("testcomment", u.Comment);
|
---|
31 |
|
---|
32 | // modify existing user
|
---|
33 | u.Email = "testemail2";
|
---|
34 | u.Comment = "testcomment2";
|
---|
35 | db.SubmitChanges();
|
---|
36 | u = db.HeuristicLabUsers.Single(x => x.UserName == "testname");
|
---|
37 | Assert.IsNotNull(u);
|
---|
38 | Assert.AreEqual<string>("testname", u.UserName);
|
---|
39 | Assert.AreEqual<string>("testemail2", u.Email);
|
---|
40 | Assert.AreEqual<string>("testquestion", u.PasswordQuestion);
|
---|
41 | Assert.AreEqual<string>("testcomment2", u.Comment);
|
---|
42 |
|
---|
43 | // delete user
|
---|
44 | db.HeuristicLabUsers.DeleteOnSubmit(u);
|
---|
45 | db.SubmitChanges();
|
---|
46 | List<HeuristicLabUser> uList = db.HeuristicLabUsers.Where(x => x.UserName == "testname").ToList<HeuristicLabUser>();
|
---|
47 | Assert.AreEqual(0, uList.Count);
|
---|
48 | }
|
---|
49 |
|
---|
50 | /// <summary>
|
---|
51 | ///Gets or sets the test context which provides
|
---|
52 | ///information about and functionality for the current test run.
|
---|
53 | ///</summary>
|
---|
54 | public TestContext TestContext {
|
---|
55 | get {
|
---|
56 | return testContextInstance;
|
---|
57 | }
|
---|
58 | set {
|
---|
59 | testContextInstance = value;
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | #region Additional test attributes
|
---|
64 | //
|
---|
65 | //You can use the following additional attributes as you write your tests:
|
---|
66 | //
|
---|
67 | //Use ClassInitialize to run code before running the first test in the class
|
---|
68 | //[ClassInitialize()]
|
---|
69 | //public static void MyClassInitialize(TestContext testContext)
|
---|
70 | //{
|
---|
71 | //}
|
---|
72 | //
|
---|
73 | //Use ClassCleanup to run code after all tests in a class have run
|
---|
74 | //[ClassCleanup()]
|
---|
75 | //public static void MyClassCleanup()
|
---|
76 | //{
|
---|
77 | //}
|
---|
78 | //
|
---|
79 | //Use TestInitialize to run code before running each test
|
---|
80 | //[TestInitialize()]
|
---|
81 | //public void MyTestInitialize()
|
---|
82 | //{
|
---|
83 | //}
|
---|
84 | //
|
---|
85 | //Use TestCleanup to run code after each test has run
|
---|
86 | //[TestCleanup()]
|
---|
87 | //public void MyTestCleanup()
|
---|
88 | //{
|
---|
89 | //}
|
---|
90 | //
|
---|
91 | #endregion
|
---|
92 |
|
---|
93 | /// <summary>
|
---|
94 | ///A test for UserName
|
---|
95 | ///</summary>
|
---|
96 | [TestMethod()]
|
---|
97 | public void UserNameTest() {
|
---|
98 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
99 | Assert.AreEqual<String>("testname", target.UserName);
|
---|
100 | }
|
---|
101 |
|
---|
102 | /// <summary>
|
---|
103 | ///A test for PasswordQuestion
|
---|
104 | ///</summary>
|
---|
105 | [TestMethod()]
|
---|
106 | public void PasswordQuestionTest() {
|
---|
107 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
108 | Assert.AreEqual<String>("testquestion", target.PasswordQuestion);
|
---|
109 | target.ChangePasswordQuestionAndAnswer("INIT", "newquestion", "newanswer");
|
---|
110 | Assert.AreEqual<String>("newquestion", target.PasswordQuestion);
|
---|
111 | }
|
---|
112 |
|
---|
113 | /// <summary>
|
---|
114 | ///A test for PasswordAnswer
|
---|
115 | ///</summary>
|
---|
116 | [TestMethod()]
|
---|
117 | public void PasswordAnswerTest() {
|
---|
118 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
119 | Assert.AreEqual<String>("", target.PasswordAnswer);
|
---|
120 | target.ChangePasswordQuestionAndAnswer("INIT", "newquestion", "newanswer");
|
---|
121 | Assert.AreEqual<String>("newquestion", target.PasswordQuestion);
|
---|
122 | target.PasswordAnswer = "testanswer";
|
---|
123 | Assert.AreEqual<String>("testanswer", target.PasswordAnswer);
|
---|
124 | }
|
---|
125 |
|
---|
126 | /// <summary>
|
---|
127 | ///A test for Password
|
---|
128 | ///</summary>
|
---|
129 | [TestMethod()]
|
---|
130 | public void PasswordTest() {
|
---|
131 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
132 | Assert.AreEqual<String>("INIT", target.Password);
|
---|
133 | target.ChangePassword(target.Password, "pwd1");
|
---|
134 | Assert.AreEqual<String>("pwd1", target.Password);
|
---|
135 | target.ChangePassword("pwd1", "pwd2");
|
---|
136 | Assert.AreEqual<String>("pwd2", target.Password);
|
---|
137 | }
|
---|
138 |
|
---|
139 | /// <summary>
|
---|
140 | ///A test for LastPasswordChangedDate
|
---|
141 | ///</summary>
|
---|
142 | [TestMethod()]
|
---|
143 | public void LastPasswordChangedDateTest() {
|
---|
144 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
145 | Assert.AreEqual<DateTime>(System.DateTime.Today, target.LastPasswordChangedDate);
|
---|
146 | target.ChangePassword(target.Password, "pwd1");
|
---|
147 | Assert.AreEqual<DateTime>(System.DateTime.Today, target.LastPasswordChangedDate);
|
---|
148 | }
|
---|
149 |
|
---|
150 | /// <summary>
|
---|
151 | ///A test for Email
|
---|
152 | ///</summary>
|
---|
153 | [TestMethod()]
|
---|
154 | public void EmailTest() {
|
---|
155 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
156 | Assert.AreEqual<String>("testemail", target.Email);
|
---|
157 | target.Email = "testemail2";
|
---|
158 | Assert.AreEqual<String>("testemail2", target.Email);
|
---|
159 | }
|
---|
160 |
|
---|
161 | /// <summary>
|
---|
162 | ///A test for Comment
|
---|
163 | ///</summary>
|
---|
164 | [TestMethod()]
|
---|
165 | public void CommentTest() {
|
---|
166 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
167 | target.Comment = "testcomment2";
|
---|
168 | Assert.AreEqual<String>("testcomment2", target.Comment);
|
---|
169 | }
|
---|
170 |
|
---|
171 | /// <summary>
|
---|
172 | ///A test for UnlockUser
|
---|
173 | ///</summary>
|
---|
174 | [TestMethod()]
|
---|
175 | public void UnlockUserTest() {
|
---|
176 | Assert.Inconclusive("Verify the correctness of this test method.");
|
---|
177 | }
|
---|
178 |
|
---|
179 | /// <summary>
|
---|
180 | ///A test for ToString
|
---|
181 | ///</summary>
|
---|
182 | [TestMethod()]
|
---|
183 | public void ToStringTest() {
|
---|
184 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
185 | Assert.AreEqual<String>("testname", target.ToString());
|
---|
186 | }
|
---|
187 |
|
---|
188 | /// <summary>
|
---|
189 | ///A test for SendPropertyChanging
|
---|
190 | ///</summary>
|
---|
191 | [TestMethod()]
|
---|
192 | [DeploymentItem("Persistence.dll")]
|
---|
193 | public void SendPropertyChangingTest() {
|
---|
194 | HeuristicLabUser_Accessor target = new HeuristicLabUser_Accessor(); // TODO: Initialize to an appropriate value
|
---|
195 | target.SendPropertyChanging();
|
---|
196 | Assert.Inconclusive("A method that does not return a value cannot be verified.");
|
---|
197 | }
|
---|
198 |
|
---|
199 | /// <summary>
|
---|
200 | ///A test for SendPropertyChanged
|
---|
201 | ///</summary>
|
---|
202 | [TestMethod()]
|
---|
203 | [DeploymentItem("Persistence.dll")]
|
---|
204 | public void SendPropertyChangedTest() {
|
---|
205 | HeuristicLabUser_Accessor target = new HeuristicLabUser_Accessor(); // TODO: Initialize to an appropriate value
|
---|
206 | string propertyName = string.Empty; // TODO: Initialize to an appropriate value
|
---|
207 | target.SendPropertyChanged(propertyName);
|
---|
208 | Assert.Inconclusive("A method that does not return a value cannot be verified.");
|
---|
209 | }
|
---|
210 |
|
---|
211 | /// <summary>
|
---|
212 | ///A test for ResetPassword
|
---|
213 | ///</summary>
|
---|
214 | [TestMethod()]
|
---|
215 | public void ResetPasswordTest1() {
|
---|
216 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
217 | target.ChangePassword(target.Password, "pwd1");
|
---|
218 | Assert.AreEqual<String>("pwd1", target.GetPassword());
|
---|
219 | target.ResetPassword();
|
---|
220 | Assert.AreEqual<String>("INIT", target.GetPassword());
|
---|
221 | }
|
---|
222 |
|
---|
223 | /// <summary>
|
---|
224 | ///A test for ResetPassword
|
---|
225 | ///</summary>
|
---|
226 | [TestMethod()]
|
---|
227 | public void ResetPasswordTest() {
|
---|
228 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
229 | target.ChangePassword(target.Password, "pwd1");
|
---|
230 | Assert.AreEqual<String>("pwd1", target.GetPassword());
|
---|
231 | Assert.AreEqual<String>("", target.ResetPassword("wrongAnswer"));
|
---|
232 | Assert.AreEqual<String>("pwd1", target.GetPassword());
|
---|
233 | Assert.AreEqual<String>("INIT", target.ResetPassword(""));
|
---|
234 | Assert.AreEqual<String>("INIT", target.GetPassword());
|
---|
235 | }
|
---|
236 |
|
---|
237 | /// <summary>
|
---|
238 | ///A test for GetPassword
|
---|
239 | ///</summary>
|
---|
240 | [TestMethod()]
|
---|
241 | public void GetPasswordTest1() {
|
---|
242 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
243 | target.PasswordAnswer = "answer";
|
---|
244 | Assert.AreEqual<String>("INIT", target.GetPassword("answer"));
|
---|
245 | target.ChangePassword(target.Password, "pwd1");
|
---|
246 | Assert.AreEqual<String>("pwd1", target.GetPassword("answer"));
|
---|
247 | target.ChangePassword("pwd1", "pwd2");
|
---|
248 | Assert.AreEqual<String>("pwd2", target.GetPassword("answer"));
|
---|
249 | Assert.AreEqual<String>("", target.GetPassword("wrong"));
|
---|
250 | }
|
---|
251 |
|
---|
252 | /// <summary>
|
---|
253 | ///A test for GetPassword
|
---|
254 | ///</summary>
|
---|
255 | [TestMethod()]
|
---|
256 | public void GetPasswordTest() {
|
---|
257 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
258 | Assert.AreEqual<String>("INIT", target.GetPassword());
|
---|
259 | target.ChangePassword(target.Password, "pwd1");
|
---|
260 | Assert.AreEqual<String>("pwd1", target.GetPassword());
|
---|
261 | target.ChangePassword("pwd1", "pwd2");
|
---|
262 | Assert.AreEqual<String>("pwd2", target.GetPassword());
|
---|
263 | }
|
---|
264 |
|
---|
265 | /// <summary>
|
---|
266 | ///A test for ChangePasswordQuestionAndAnswer
|
---|
267 | ///</summary>
|
---|
268 | [TestMethod()]
|
---|
269 | public void ChangePasswordQuestionAndAnswerTest() {
|
---|
270 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
271 | Assert.AreEqual<String>("testquestion", target.PasswordQuestion);
|
---|
272 | Assert.AreEqual<String>("", target.PasswordAnswer);
|
---|
273 |
|
---|
274 | // check all exceptions
|
---|
275 | try {
|
---|
276 | target.ChangePasswordQuestionAndAnswer(null, null, null);
|
---|
277 | Assert.Fail();
|
---|
278 | }
|
---|
279 | catch {
|
---|
280 | }
|
---|
281 | try {
|
---|
282 | target.ChangePasswordQuestionAndAnswer("", null, null);
|
---|
283 | Assert.Fail();
|
---|
284 | }
|
---|
285 | catch {
|
---|
286 | }
|
---|
287 | try {
|
---|
288 | target.ChangePasswordQuestionAndAnswer("", "", null);
|
---|
289 | Assert.Fail();
|
---|
290 | }
|
---|
291 | catch {
|
---|
292 | }
|
---|
293 | try {
|
---|
294 | target.ChangePasswordQuestionAndAnswer("", "x", "x");
|
---|
295 | Assert.Fail();
|
---|
296 | }
|
---|
297 | catch {
|
---|
298 | }
|
---|
299 | try {
|
---|
300 | target.ChangePasswordQuestionAndAnswer("x", "", "x");
|
---|
301 | Assert.Fail();
|
---|
302 | }
|
---|
303 | catch {
|
---|
304 | }
|
---|
305 | try {
|
---|
306 | target.ChangePasswordQuestionAndAnswer("x", "x", "");
|
---|
307 | Assert.Fail();
|
---|
308 | }
|
---|
309 | catch {
|
---|
310 | }
|
---|
311 |
|
---|
312 | // wrong old password
|
---|
313 | Assert.IsFalse(target.ChangePasswordQuestionAndAnswer("wrong", "newquestion", "newanswer"));
|
---|
314 | Assert.AreEqual<String>("testquestion", target.PasswordQuestion);
|
---|
315 | Assert.AreEqual<String>("", target.PasswordAnswer);
|
---|
316 |
|
---|
317 | // should work
|
---|
318 | Assert.IsTrue(target.ChangePasswordQuestionAndAnswer("INIT", "newquestion", "newanswer"));
|
---|
319 | Assert.AreEqual<String>("newquestion", target.PasswordQuestion);
|
---|
320 | Assert.AreEqual<String>("newanswer", target.PasswordAnswer);
|
---|
321 | }
|
---|
322 |
|
---|
323 | /// <summary>
|
---|
324 | ///A test for ChangePassword
|
---|
325 | ///</summary>
|
---|
326 | [TestMethod()]
|
---|
327 | public void ChangePasswordTest() {
|
---|
328 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
329 | Assert.AreEqual<String>("INIT", target.Password);
|
---|
330 |
|
---|
331 | // check all exceptions
|
---|
332 | try {
|
---|
333 | target.ChangePassword(null, null);
|
---|
334 | Assert.Fail();
|
---|
335 | }
|
---|
336 | catch {
|
---|
337 | }
|
---|
338 | try {
|
---|
339 | target.ChangePassword("", "abc");
|
---|
340 | Assert.Fail();
|
---|
341 | }
|
---|
342 | catch {
|
---|
343 | }
|
---|
344 | try {
|
---|
345 | target.ChangePassword("INIT", null);
|
---|
346 | Assert.Fail();
|
---|
347 | }
|
---|
348 | catch {
|
---|
349 | }
|
---|
350 | try {
|
---|
351 | target.ChangePassword("INIT", "");
|
---|
352 | Assert.Fail();
|
---|
353 | }
|
---|
354 | catch {
|
---|
355 | }
|
---|
356 |
|
---|
357 | target.ChangePassword(target.Password, "pwd1");
|
---|
358 | Assert.AreEqual<String>("pwd1", target.Password);
|
---|
359 | target.ChangePassword("pwd1", "pwd2");
|
---|
360 | Assert.AreEqual<String>("pwd2", target.Password);
|
---|
361 | try {
|
---|
362 | target.ChangePassword("abc", "def");
|
---|
363 | Assert.Fail();
|
---|
364 | }
|
---|
365 | catch (Exception) {
|
---|
366 | }
|
---|
367 | }
|
---|
368 |
|
---|
369 | /// <summary>
|
---|
370 | ///A test for HeuristicLabUser Constructor
|
---|
371 | ///</summary>
|
---|
372 | [TestMethod()]
|
---|
373 | public void HeuristicLabUserConstructorTest() {
|
---|
374 | HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
|
---|
375 | Assert.AreEqual<String>("testname", target.UserName);
|
---|
376 | Assert.AreEqual<String>("INIT", target.Password);
|
---|
377 | Assert.AreEqual<DateTime>(System.DateTime.Today, target.LastPasswordChangedDate);
|
---|
378 | Assert.AreEqual<String>("testquestion", target.PasswordQuestion);
|
---|
379 | Assert.AreEqual<String>("", target.PasswordAnswer);
|
---|
380 | Assert.AreEqual<String>("testemail", target.Email);
|
---|
381 | Assert.AreEqual<String>("testcomment", target.Comment);
|
---|
382 | }
|
---|
383 | }
|
---|
384 | }
|
---|