Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/24/10 00:23:16 (14 years ago)
Author:
hmayr
Message:

following changes (#1046):

  • extended DatabaseUtil.cs
  • extended HeuristicLabUser.cs
  • created HeuristicLabUserTest.cs
  • created AbstractHeuristicLabTest.cs
  • implemented a demo method in HeuristicLabMembershipProvider.cs to show usage of HeuristicLabUser.cs and DatabaseUtil.cs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabUserTest.cs

    r3940 r3943  
    1 using Persistence;
     1using System;
     2using System.Collections.Generic;
     3using System.Linq;
    24using Microsoft.VisualStudio.TestTools.UnitTesting;
    3 using System;
     5using Persistence;
    46
    57namespace UnitTests {
     
    911  ///</summary>
    1012  [TestClass()]
    11   public class HeuristicLabUserTest {
     13  public class HeuristicLabUserTest : AbstractHeuristicLabTest {
    1214    private TestContext testContextInstance;
    1315
    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
    2218    /// </summary>
    2319    [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);
    4850    }
    4951
     
    9193    #endregion
    9294
    93 
    9495    /// <summary>
    9596    ///A test for UserName
     
    9798    [TestMethod()]
    9899    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() {
    102178      Assert.Inconclusive("Verify the correctness of this test method.");
    103179    }
    104180
    105181    /// <summary>
    106     ///A test for PasswordQuestion
    107     ///</summary>
    108     [TestMethod()]
    109     public void PasswordQuestionTest() {
    110       HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value
    111       string actual;
    112       actual = target.PasswordQuestion;
    113       Assert.Inconclusive("Verify the correctness of this test method.");
    114     }
    115 
    116     /// <summary>
    117     ///A test for PasswordAnswer
    118     ///</summary>
    119     [TestMethod()]
    120     public void PasswordAnswerTest() {
    121       HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value
    122       string expected = string.Empty; // TODO: Initialize to an appropriate value
    123       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 Password
    132     ///</summary>
    133     [TestMethod()]
    134     public void PasswordTest() {
    135       HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value
    136       string expected = string.Empty; // TODO: Initialize to an appropriate value
    137       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 LastPasswordChangedDate
    146     ///</summary>
    147     [TestMethod()]
    148     public void LastPasswordChangedDateTest() {
    149       HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value
    150       DateTime actual;
    151       actual = target.LastPasswordChangedDate;
    152       Assert.Inconclusive("Verify the correctness of this test method.");
    153     }
    154 
    155     /// <summary>
    156     ///A test for Email
    157     ///</summary>
    158     [TestMethod()]
    159     public void EmailTest() {
    160       HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value
    161       string expected = string.Empty; // TODO: Initialize to an appropriate value
    162       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 Comment
    171     ///</summary>
    172     [TestMethod()]
    173     public void CommentTest() {
    174       HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value
    175       string expected = string.Empty; // TODO: Initialize to an appropriate value
    176       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 UnlockUser
    185     ///</summary>
    186     [TestMethod()]
    187     public void UnlockUserTest() {
    188       HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value
    189       bool expected = false; // TODO: Initialize to an appropriate value
    190       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>
    197182    ///A test for ToString
    198183    ///</summary>
    199184    [TestMethod()]
    200185    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());
    207188    }
    208189
     
    235216    [TestMethod()]
    236217    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());
    243223    }
    244224
     
    248228    [TestMethod()]
    249229    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());
    257235    }
    258236
     
    262240    [TestMethod()]
    263241    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"));
    271250    }
    272251
     
    276255    [TestMethod()]
    277256    public void GetPasswordTest() {
    278       HeuristicLabUser target = new HeuristicLabUser(); // TODO: Initialize to an appropriate value
    279       string expected = string.Empty; // TODO: Initialize to an appropriate value
    280       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());
    284263    }
    285264
     
    289268    [TestMethod()]
    290269    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);
    300276    }
    301277
     
    305281    [TestMethod()]
    306282    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      }
    315295    }
    316296
     
    320300    [TestMethod()]
    321301    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);
    324310    }
    325311  }
Note: See TracChangeset for help on using the changeset viewer.