Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/26/10 10:18:57 (14 years ago)
Author:
hmayr
Message:

following changes (#1046):

  • implemented some methods of HeuristicLabMembershipProvider and unit tests
  • tests for ChangePassword and ChangePasswordQuestionAndAnswer do not work at the moment!
File:
1 edited

Legend:

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

    r3948 r3956  
    1 using Service.Provider;
     1using System;
     2using Service.Provider;
    23using Microsoft.VisualStudio.TestTools.UnitTesting;
    34using System.Web.Security;
     5using Persistence;
     6using System.Linq;
     7using System.Collections.Generic;
    48
    59namespace UnitTests {
     
    368372    [TestMethod()]
    369373    public void DeleteUserTest() {
    370       HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value
    371       string username = string.Empty; // TODO: Initialize to an appropriate value
    372       bool deleteAllRelatedData = false; // TODO: Initialize to an appropriate value
    373       bool expected = false; // TODO: Initialize to an appropriate value
    374       bool actual;
    375       actual = target.DeleteUser(username, deleteAllRelatedData);
    376       Assert.AreEqual(expected, actual);
    377       Assert.Inconclusive("Verify the correctness of this test method.");
     374      // insert new user
     375      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider();
     376      MembershipCreateStatus status;
     377      target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
     378      Assert.AreEqual(MembershipCreateStatus.Success, status);
     379
     380      // delete user
     381      Assert.IsTrue(target.DeleteUser("testname", true));
     382      Assert.AreEqual(0, db.HeuristicLabUsers.Count(x => x.UserName == "testname"));
    378383    }
    379384
     
    383388    [TestMethod()]
    384389    public void CreateUserTest() {
    385       HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value
    386       string username = string.Empty; // TODO: Initialize to an appropriate value
    387       string password = string.Empty; // TODO: Initialize to an appropriate value
    388       string email = string.Empty; // TODO: Initialize to an appropriate value
    389       string passwordQuestion = string.Empty; // TODO: Initialize to an appropriate value
    390       string passwordAnswer = string.Empty; // TODO: Initialize to an appropriate value
    391       bool isApproved = false; // TODO: Initialize to an appropriate value
    392       object providerUserKey = null; // TODO: Initialize to an appropriate value
    393       MembershipCreateStatus status = new MembershipCreateStatus(); // TODO: Initialize to an appropriate value
    394       MembershipCreateStatus statusExpected = new MembershipCreateStatus(); // TODO: Initialize to an appropriate value
    395       MembershipUser expected = null; // TODO: Initialize to an appropriate value
    396       MembershipUser actual;
    397       actual = target.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status);
    398       Assert.AreEqual(statusExpected, status);
    399       Assert.AreEqual(expected, actual);
    400       Assert.Inconclusive("Verify the correctness of this test method.");
     390      // create user
     391      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider();
     392      MembershipCreateStatus status;
     393      target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
     394      Assert.AreEqual(MembershipCreateStatus.Success, status);
     395
     396      // check if user is OK
     397      HeuristicLabUser u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
     398      Assert.AreEqual<string>("testname", u.UserName);
     399      Assert.AreEqual<string>("testemail", u.Email);
     400      Assert.AreEqual<string>("newPassword", u.Password);
     401      Assert.AreEqual<string>("testquestion", u.PasswordQuestion);
     402      Assert.AreEqual<string>("testanswer", u.PasswordAnswer);
     403      Assert.AreEqual<string>("", u.Comment);
     404
     405      // check for duplicate errors
     406      target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
     407      Assert.AreEqual(MembershipCreateStatus.DuplicateUserName, status);
     408      target.CreateUser("testname2", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
     409      Assert.AreEqual(MembershipCreateStatus.DuplicateEmail, status);
    401410    }
    402411
     
    406415    [TestMethod()]
    407416    public void ChangePasswordQuestionAndAnswerTest() {
    408       HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value
    409       string username = string.Empty; // TODO: Initialize to an appropriate value
    410       string password = string.Empty; // TODO: Initialize to an appropriate value
    411       string newPasswordQuestion = string.Empty; // TODO: Initialize to an appropriate value
    412       string newPasswordAnswer = string.Empty; // TODO: Initialize to an appropriate value
    413       bool expected = false; // TODO: Initialize to an appropriate value
    414       bool actual;
    415       actual = target.ChangePasswordQuestionAndAnswer(username, password, newPasswordQuestion, newPasswordAnswer);
    416       Assert.AreEqual(expected, actual);
    417       Assert.Inconclusive("Verify the correctness of this test method.");
     417      // create user
     418      HeuristicLabUser u = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
     419      db.HeuristicLabUsers.InsertOnSubmit(u);
     420      db.SubmitChanges();
     421
     422      // check if user is stored
     423      u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
     424      Assert.AreEqual<String>("testquestion", u.PasswordQuestion);
     425      Assert.AreEqual<String>("", u.PasswordAnswer);
     426
     427      // change data and check again
     428      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider();
     429      // gibt zwar true zurück, was schon mal gut ist
     430      Assert.IsTrue(target.ChangePasswordQuestionAndAnswer("testname", "INIT", "newquestion", "newanswer"));
     431      // aber hier ist die änderung noch nicht da!! es ist immer noch die alte frage + alte antwort
     432      u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
     433      Assert.AreEqual<String>("newquestion", u.PasswordQuestion);
     434      Assert.AreEqual<String>("newanswer", u.PasswordAnswer);
    418435    }
    419436
     
    423440    [TestMethod()]
    424441    public void ChangePasswordTest() {
    425       HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value
    426       string username = string.Empty; // TODO: Initialize to an appropriate value
    427       string oldPassword = string.Empty; // TODO: Initialize to an appropriate value
    428       string newPassword = string.Empty; // TODO: Initialize to an appropriate value
    429       bool expected = false; // TODO: Initialize to an appropriate value
    430       bool actual;
    431       actual = target.ChangePassword(username, oldPassword, newPassword);
    432       Assert.AreEqual(expected, actual);
    433       Assert.Inconclusive("Verify the correctness of this test method.");
     442      // create user
     443      HeuristicLabUser u = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
     444      db.HeuristicLabUsers.InsertOnSubmit(u);
     445      db.SubmitChanges();
     446
     447      // check if user is stored
     448      u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
     449      Assert.AreEqual<String>("INIT", u.Password);
     450
     451      // change data and check again
     452      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider();
     453      Assert.IsTrue(target.ChangePassword("testname", "INIT", "newPassword"));
     454      // hat nix gemacht!! :(
     455      u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
     456      Assert.AreEqual<String>("newPassword", u.Password);
    434457    }
    435458
Note: See TracChangeset for help on using the changeset viewer.