Changeset 3943 for branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabUserTest.cs
- Timestamp:
- 06/24/10 00:23:16 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabUserTest.cs
r3940 r3943 1 using Persistence; 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 2 4 using Microsoft.VisualStudio.TestTools.UnitTesting; 3 using System;5 using Persistence; 4 6 5 7 namespace UnitTests { … … 9 11 ///</summary> 10 12 [TestClass()] 11 public class HeuristicLabUserTest {13 public class HeuristicLabUserTest : AbstractHeuristicLabTest { 12 14 private TestContext testContextInstance; 13 15 14 private Persistence.DataClassesDataContext db; 15 16 public HeuristicLabUserTest() { 17 db = Persistence.DatabaseUtil.createDataClassesDataContext(); 18 } 19 20 /// <summary> 21 /// creates a local database for all other test methods 16 /// <summary> 17 /// inserts, modifies and deletes a new user into the database 22 18 /// </summary> 23 19 [TestMethod()] 24 public void createDBTest() { 25 if (db.DatabaseExists()) { 26 Console.WriteLine("Deleting old database..."); 27 db.DeleteDatabase(); 28 Console.WriteLine("Deleted old database!"); 29 } 30 Console.WriteLine("Creating new database..."); 31 db.CreateDatabase(); 32 Console.WriteLine("Created new database!"); 33 } 34 35 /// <summary> 36 /// inserts a new user into the database 37 /// </summary> 38 [TestMethod()] 39 public void addUserTest() { 40 //Assert.IsNotNull(db); 41 42 //Persistence.HeuristicLabUser user = new HeuristicLabUser(); 43 //user.UserName = "TEST"; 44 //db.HeuristicLabUsers.InsertOnSubmit(user); 45 //db.SubmitChanges(); 46 47 // db.HeuristicLabUsers. 20 public void modifyUserTest() { 21 checkConnection(); 22 23 // insert new user 24 Persistence.HeuristicLabUser user = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 25 db.HeuristicLabUsers.InsertOnSubmit(user); 26 db.SubmitChanges(); 27 Persistence.HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == "testname"); 28 Assert.IsNotNull(u); 29 Assert.AreEqual<string>("testname", u.UserName); 30 Assert.AreEqual<string>("testemail", u.Email); 31 Assert.AreEqual<string>("testquestion", u.PasswordQuestion); 32 Assert.AreEqual<string>("testcomment", u.Comment); 33 34 // modify existing user 35 u.Email = "testemail2"; 36 u.Comment = "testcomment2"; 37 db.SubmitChanges(); 38 u = db.HeuristicLabUsers.Single(x => x.UserName == "testname"); 39 Assert.IsNotNull(u); 40 Assert.AreEqual<string>("testname", u.UserName); 41 Assert.AreEqual<string>("testemail2", u.Email); 42 Assert.AreEqual<string>("testquestion", u.PasswordQuestion); 43 Assert.AreEqual<string>("testcomment2", u.Comment); 44 45 // delete user 46 db.HeuristicLabUsers.DeleteOnSubmit(u); 47 db.SubmitChanges(); 48 List<HeuristicLabUser> uList = db.HeuristicLabUsers.Where(x => x.UserName == "testname").ToList<HeuristicLabUser>(); 49 Assert.AreEqual(0, uList.Count); 48 50 } 49 51 … … 91 93 #endregion 92 94 93 94 95 /// <summary> 95 96 ///A test for UserName … … 97 98 [TestMethod()] 98 99 public void UserNameTest() { 99 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value 100 string actual; 101 actual = target.UserName; 100 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 101 Assert.AreEqual<String>("testname", target.UserName); 102 } 103 104 /// <summary> 105 ///A test for PasswordQuestion 106 ///</summary> 107 [TestMethod()] 108 public void PasswordQuestionTest() { 109 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 110 Assert.AreEqual<String>("testquestion", target.PasswordQuestion); 111 target.ChangePasswordQuestionAndAnswer("INIT", "newquestion", "newanswer"); 112 Assert.AreEqual<String>("newquestion", target.PasswordQuestion); 113 } 114 115 /// <summary> 116 ///A test for PasswordAnswer 117 ///</summary> 118 [TestMethod()] 119 public void PasswordAnswerTest() { 120 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 121 Assert.AreEqual<String>("", target.PasswordAnswer); 122 target.ChangePasswordQuestionAndAnswer("INIT", "newquestion", "newanswer"); 123 Assert.AreEqual<String>("newquestion", target.PasswordQuestion); 124 target.PasswordAnswer = "testanswer"; 125 Assert.AreEqual<String>("testanswer", target.PasswordAnswer); 126 } 127 128 /// <summary> 129 ///A test for Password 130 ///</summary> 131 [TestMethod()] 132 public void PasswordTest() { 133 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 134 Assert.AreEqual<String>("INIT", target.Password); 135 target.ChangePassword(target.Password, "pwd1"); 136 Assert.AreEqual<String>("pwd1", target.Password); 137 target.ChangePassword("pwd1", "pwd2"); 138 Assert.AreEqual<String>("pwd2", target.Password); 139 } 140 141 /// <summary> 142 ///A test for LastPasswordChangedDate 143 ///</summary> 144 [TestMethod()] 145 public void LastPasswordChangedDateTest() { 146 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 147 Assert.AreEqual<DateTime>(System.DateTime.Today, target.LastPasswordChangedDate); 148 target.ChangePassword(target.Password, "pwd1"); 149 Assert.AreEqual<DateTime>(System.DateTime.Today, target.LastPasswordChangedDate); 150 } 151 152 /// <summary> 153 ///A test for Email 154 ///</summary> 155 [TestMethod()] 156 public void EmailTest() { 157 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 158 Assert.AreEqual<String>("testemail", target.Email); 159 target.Email = "testemail2"; 160 Assert.AreEqual<String>("testemail2", target.Email); 161 } 162 163 /// <summary> 164 ///A test for Comment 165 ///</summary> 166 [TestMethod()] 167 public void CommentTest() { 168 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 169 target.Comment = "testcomment2"; 170 Assert.AreEqual<String>("testcomment2", target.Comment); 171 } 172 173 /// <summary> 174 ///A test for UnlockUser 175 ///</summary> 176 [TestMethod()] 177 public void UnlockUserTest() { 102 178 Assert.Inconclusive("Verify the correctness of this test method."); 103 179 } 104 180 105 181 /// <summary> 106 ///A test for PasswordQuestion107 ///</summary>108 [TestMethod()]109 public void PasswordQuestionTest() {110 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value111 string actual;112 actual = target.PasswordQuestion;113 Assert.Inconclusive("Verify the correctness of this test method.");114 }115 116 /// <summary>117 ///A test for PasswordAnswer118 ///</summary>119 [TestMethod()]120 public void PasswordAnswerTest() {121 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value122 string expected = string.Empty; // TODO: Initialize to an appropriate value123 string actual;124 target.PasswordAnswer = expected;125 actual = target.PasswordAnswer;126 Assert.AreEqual(expected, actual);127 Assert.Inconclusive("Verify the correctness of this test method.");128 }129 130 /// <summary>131 ///A test for Password132 ///</summary>133 [TestMethod()]134 public void PasswordTest() {135 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value136 string expected = string.Empty; // TODO: Initialize to an appropriate value137 string actual;138 target.Password = expected;139 actual = target.Password;140 Assert.AreEqual(expected, actual);141 Assert.Inconclusive("Verify the correctness of this test method.");142 }143 144 /// <summary>145 ///A test for LastPasswordChangedDate146 ///</summary>147 [TestMethod()]148 public void LastPasswordChangedDateTest() {149 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value150 DateTime actual;151 actual = target.LastPasswordChangedDate;152 Assert.Inconclusive("Verify the correctness of this test method.");153 }154 155 /// <summary>156 ///A test for Email157 ///</summary>158 [TestMethod()]159 public void EmailTest() {160 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value161 string expected = string.Empty; // TODO: Initialize to an appropriate value162 string actual;163 target.Email = expected;164 actual = target.Email;165 Assert.AreEqual(expected, actual);166 Assert.Inconclusive("Verify the correctness of this test method.");167 }168 169 /// <summary>170 ///A test for Comment171 ///</summary>172 [TestMethod()]173 public void CommentTest() {174 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value175 string expected = string.Empty; // TODO: Initialize to an appropriate value176 string actual;177 target.Comment = expected;178 actual = target.Comment;179 Assert.AreEqual(expected, actual);180 Assert.Inconclusive("Verify the correctness of this test method.");181 }182 183 /// <summary>184 ///A test for UnlockUser185 ///</summary>186 [TestMethod()]187 public void UnlockUserTest() {188 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value189 bool expected = false; // TODO: Initialize to an appropriate value190 bool actual;191 actual = target.UnlockUser();192 Assert.AreEqual(expected, actual);193 Assert.Inconclusive("Verify the correctness of this test method.");194 }195 196 /// <summary>197 182 ///A test for ToString 198 183 ///</summary> 199 184 [TestMethod()] 200 185 public void ToStringTest() { 201 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value 202 string expected = string.Empty; // TODO: Initialize to an appropriate value 203 string actual; 204 actual = target.ToString(); 205 Assert.AreEqual(expected, actual); 206 Assert.Inconclusive("Verify the correctness of this test method."); 186 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 187 Assert.AreEqual<String>("testname", target.ToString()); 207 188 } 208 189 … … 235 216 [TestMethod()] 236 217 public void ResetPasswordTest1() { 237 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value 238 string expected = string.Empty; // TODO: Initialize to an appropriate value 239 string actual; 240 actual = target.ResetPassword(); 241 Assert.AreEqual(expected, actual); 242 Assert.Inconclusive("Verify the correctness of this test method."); 218 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 219 target.ChangePassword(target.Password, "pwd1"); 220 Assert.AreEqual<String>("pwd1", target.GetPassword()); 221 target.ResetPassword(); 222 Assert.AreEqual<String>("", target.GetPassword()); 243 223 } 244 224 … … 248 228 [TestMethod()] 249 229 public void ResetPasswordTest() { 250 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value 251 string passwordAnswer = string.Empty; // TODO: Initialize to an appropriate value 252 string expected = string.Empty; // TODO: Initialize to an appropriate value 253 string actual; 254 actual = target.ResetPassword(passwordAnswer); 255 Assert.AreEqual(expected, actual); 256 Assert.Inconclusive("Verify the correctness of this test method."); 230 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 231 target.ChangePassword(target.Password, "pwd1"); 232 Assert.AreEqual<String>("pwd1", target.GetPassword()); 233 target.ResetPassword("wrongAnswer"); 234 Assert.AreEqual<String>("pwd1", target.GetPassword()); 257 235 } 258 236 … … 262 240 [TestMethod()] 263 241 public void GetPasswordTest1() { 264 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value 265 string passwordAnswer = string.Empty; // TODO: Initialize to an appropriate value 266 string expected = string.Empty; // TODO: Initialize to an appropriate value 267 string actual; 268 actual = target.GetPassword(passwordAnswer); 269 Assert.AreEqual(expected, actual); 270 Assert.Inconclusive("Verify the correctness of this test method."); 242 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 243 target.PasswordAnswer = "answer"; 244 Assert.AreEqual<String>("", 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")); 271 250 } 272 251 … … 276 255 [TestMethod()] 277 256 public void GetPasswordTest() { 278 HeuristicLabUser target = new HeuristicLabUser( ); // TODO: Initialize to an appropriate value279 string expected = string.Empty; // TODO: Initialize to an appropriate value280 string actual;281 actual = target.GetPassword();282 Assert.AreEqual(expected, actual);283 Assert. Inconclusive("Verify the correctness of this test method.");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()); 284 263 } 285 264 … … 289 268 [TestMethod()] 290 269 public void ChangePasswordQuestionAndAnswerTest() { 291 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value 292 string password = string.Empty; // TODO: Initialize to an appropriate value 293 string newPasswordQuestion = string.Empty; // TODO: Initialize to an appropriate value 294 string newPasswordAnswer = string.Empty; // TODO: Initialize to an appropriate value 295 bool expected = false; // TODO: Initialize to an appropriate value 296 bool actual; 297 actual = target.ChangePasswordQuestionAndAnswer(password, newPasswordQuestion, newPasswordAnswer); 298 Assert.AreEqual(expected, actual); 299 Assert.Inconclusive("Verify the correctness of this test method."); 270 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 271 Assert.AreEqual<String>("testquestion", target.PasswordQuestion); 272 Assert.AreEqual<String>("", target.PasswordAnswer); 273 target.ChangePasswordQuestionAndAnswer("INIT", "newquestion", "newanswer"); 274 Assert.AreEqual<String>("newquestion", target.PasswordQuestion); 275 Assert.AreEqual<String>("newanswer", target.PasswordAnswer); 300 276 } 301 277 … … 305 281 [TestMethod()] 306 282 public void ChangePasswordTest() { 307 HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value 308 string oldPassword = string.Empty; // TODO: Initialize to an appropriate value 309 string newPassword = string.Empty; // TODO: Initialize to an appropriate value 310 bool expected = false; // TODO: Initialize to an appropriate value 311 bool actual; 312 actual = target.ChangePassword(oldPassword, newPassword); 313 Assert.AreEqual(expected, actual); 314 Assert.Inconclusive("Verify the correctness of this test method."); 283 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 284 Assert.AreEqual<String>("INIT", target.Password); 285 target.ChangePassword(target.Password, "pwd1"); 286 Assert.AreEqual<String>("pwd1", target.Password); 287 target.ChangePassword("pwd1", "pwd2"); 288 Assert.AreEqual<String>("pwd2", target.Password); 289 try { 290 target.ChangePassword("abc", "def"); 291 Assert.Fail(); 292 } 293 catch (Exception) { 294 } 315 295 } 316 296 … … 320 300 [TestMethod()] 321 301 public void HeuristicLabUserConstructorTest() { 322 HeuristicLabUser target = new HeuristicLabUser(); 323 Assert.Inconclusive("TODO: Implement code to verify target"); 302 HeuristicLabUser target = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 303 Assert.AreEqual<String>("testname", target.UserName); 304 Assert.AreEqual<String>("INIT", target.Password); 305 Assert.AreEqual<DateTime>(System.DateTime.Today, target.LastPasswordChangedDate); 306 Assert.AreEqual<String>("testquestion", target.PasswordQuestion); 307 Assert.AreEqual<String>("", target.PasswordAnswer); 308 Assert.AreEqual<String>("testemail", target.Email); 309 Assert.AreEqual<String>("testcomment", target.Comment); 324 310 } 325 311 }
Note: See TracChangeset
for help on using the changeset viewer.