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
Location:
branches/HeuristicLab.Services.Authentication Prototype
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Services.Authentication Prototype/HeuristicLab.Services.Authentication Prototyp.vsmdi

    r3940 r3943  
    44    <Description>just first test for HeuristicLabUser</Description>
    55    <TestLinks>
     6      <TestLink id="537e2ce5-1968-64c1-932a-0aff7f0ea564" name="ToStringTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
     7      <TestLink id="ecaca427-086c-9493-06af-9887f2d8184f" name="PasswordAnswerTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
     8      <TestLink id="c94ce8a9-0db1-d5f7-0d29-a5b40ed93b8f" name="ChangePasswordTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
     9      <TestLink id="5c113ee8-ae71-cf76-5bf1-608203739eeb" name="HeuristicLabUserConstructorTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
     10      <TestLink id="b6e6a789-8f4e-329c-38ef-d9e19bd14e55" name="PasswordTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
    611      <TestLink id="def90666-533d-bda5-8a29-fde7f290333f" name="createDBTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
     12      <TestLink id="4452b5de-b1d7-2a87-17cf-5bcef24a98ba" name="modifyUserTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
     13      <TestLink id="ce8163d5-a5c1-2a43-04b4-3afe6a0140c3" name="ChangePasswordQuestionAndAnswerTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
     14      <TestLink id="5a5bdb37-43b0-c6f1-1b5b-7df4fecd3b8f" name="PasswordQuestionTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
     15      <TestLink id="799ee04a-e351-af4d-61c5-344e29aaace3" name="UserNameTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
     16      <TestLink id="23131c03-ebe9-6d64-7d73-52214a9dac7d" name="EmailTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
     17      <TestLink id="e3413b57-3027-8e7d-3f25-67842a5c6986" name="CommentTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
     18      <TestLink id="2b5d5229-e68f-6a88-fb76-73fa5d493613" name="LastPasswordChangedDateTest" storage="unittests\bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" />
    719    </TestLinks>
    820  </TestList>
  • branches/HeuristicLab.Services.Authentication Prototype/Persistence/DataClasses.dbml

    r3942 r3943  
    44    <Type Name="HeuristicLabUser">
    55      <Column Name="id" Member="ID" Storage="_id" Type="System.Int64" IsReadOnly="true" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
    6       <Column Name="UserName" Modifier="Override" Type="System.String" IsReadOnly="true" CanBeNull="false" />
     6      <Column Name="UserName" Modifier="Virtual" Type="System.String" IsReadOnly="true" CanBeNull="false" />
    77      <Column Name="Password" Type="System.String" CanBeNull="false" />
    8       <Column Name="LastPasswordChangedDate" Modifier="Override" Type="System.DateTime" IsReadOnly="true" CanBeNull="false" />
    9       <Column Name="PasswordQuestion" Modifier="Override" Type="System.String" IsReadOnly="true" CanBeNull="false" />
     8      <Column Name="LastPasswordChangedDate" Modifier="Virtual" Type="System.DateTime" IsReadOnly="true" CanBeNull="false" />
     9      <Column Name="PasswordQuestion" Modifier="Virtual" Type="System.String" IsReadOnly="true" CanBeNull="false" />
    1010      <Column Name="PasswordAnswer" Type="System.String" CanBeNull="false" />
    11       <Column Name="Email" Modifier="Override" Type="System.String" CanBeNull="false" />
    12       <Column Name="Comment" Modifier="Override" Type="System.String" CanBeNull="false" />
     11      <Column Name="Email" Modifier="Virtual" Type="System.String" CanBeNull="false" />
     12      <Column Name="Comment" Modifier="Virtual" Type="System.String" CanBeNull="false" />
    1313      <Association Name="HeuristicLabUser_HeuristicLabUserRole" Member="HeuristicLabUserRole" ThisKey="ID" OtherKey="HeuristicLabUserID" Type="HeuristicLabUserRole" />
    1414    </Type>
    1515  </Table>
    1616  <Table Name="" Member="HeuristicLabAbstractRoles">
    17     <Type Name="HeuristicLabAbstractRole" IsInheritanceDefault="true" Modifier="Abstract">
     17    <Type Name="HeuristicLabAbstractRole" Modifier="Abstract">
    1818      <Column Name="ID" Type="System.Int64" IsReadOnly="true" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
    1919      <Column Name="roleName" Member="RoleName" Storage="_roleName" Type="System.String" CanBeNull="false" />
    2020      <Column Name="parentRoleID" Member="ParentRoleID" Storage="_parentRoleID" Type="System.Int64" CanBeNull="false" />
    21       <Column Member="RoleType" Type="System.String" IsReadOnly="true" CanBeNull="false" UpdateCheck="Always" IsDiscriminator="true" />
     21      <Column Name="RoleType" Type="System.String" IsReadOnly="true" CanBeNull="false" IsDiscriminator="true" />
     22      <Association Name="HeuristicLabAbstractRole_HeuristicLabAbstractRole" Member="HeuristicLabAbstractRole2" ThisKey="ID" OtherKey="ParentRoleID" Type="HeuristicLabAbstractRole" />
    2223      <Association Name="HeuristicLabAbstractRole_HeuristicLabUserRole" Member="HeuristicLabUserRole" ThisKey="ID" OtherKey="HeuristicLabRoleID" Type="HeuristicLabUserRole" />
    23       <Association Name="HeuristicLabAbstractRole_HeuristicLabAbstractRole" Member="HeuristicLabAbstractRole2" ThisKey="ID" OtherKey="ParentRoleID" Type="HeuristicLabAbstractRole" />
    2424      <Association Name="HeuristicLabAbstractRole_HeuristicLabAbstractRole" Member="HeuristicLabAbstractRole1" ThisKey="ParentRoleID" OtherKey="ID" Type="HeuristicLabAbstractRole" IsForeignKey="true" />
    2525      <Type Name="HeuristicLabPermissionRole" InheritanceCode="permission" />
    26       <Type Name="HeuristicLabRole" InheritanceCode="role" />
     26      <Type Name="HeuristicLabRole" InheritanceCode="role" IsInheritanceDefault="true" />
    2727    </Type>
    2828  </Table>
    2929  <Table Name="" Member="HeuristicLabUserRole">
    3030    <Type Name="HeuristicLabUserRole">
    31       <Column Member="ID" Type="System.Int64" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
    32       <Column Member="HeuristicLabUserID" Type="System.Int64" CanBeNull="false" />
    33       <Column Member="HeuristicLabRoleID" Type="System.Int64" CanBeNull="false" />
     31      <Column Name="ID" Type="System.Int64" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
     32      <Column Name="HeuristicLabUserID" Type="System.Int64" CanBeNull="false" />
     33      <Column Name="HeuristicLabRoleID" Type="System.Int64" CanBeNull="false" />
    3434      <Association Name="HeuristicLabUser_HeuristicLabUserRole" Member="HeuristicLabUser" ThisKey="HeuristicLabUserID" OtherKey="ID" Type="HeuristicLabUser" IsForeignKey="true" />
    3535      <Association Name="HeuristicLabAbstractRole_HeuristicLabUserRole" Member="HeuristicLabAbstractRole" ThisKey="HeuristicLabRoleID" OtherKey="ID" Type="HeuristicLabAbstractRole" IsForeignKey="true" />
  • branches/HeuristicLab.Services.Authentication Prototype/Persistence/DataClasses.dbml.layout

    r3942 r3943  
    2727      </nestedChildShapes>
    2828    </classShape>
    29     <inheritanceConnector edgePoints="[(5.5 : 2.22679768880208); (6.875 : 2.22679768880208)]" fixedFrom="Algorithm" fixedTo="Algorithm" TargetRelationshipDomainClassId="7a7fe09e-e9ef-4b01-9ff3-bde95e827b62">
     29    <inheritanceConnector edgePoints="[(5.5 : 2.22679768880208); (6.875 : 2.22679768880208)]" fixedFrom="NotFixed" fixedTo="NotFixed" TargetRelationshipDomainClassId="7a7fe09e-e9ef-4b01-9ff3-bde95e827b62">
    3030      <nodes>
    3131        <classShapeMoniker Id="c7373ccc-61b3-43fb-88fa-14149d69bee9" />
     
    3333      </nodes>
    3434    </inheritanceConnector>
    35     <inheritanceConnector edgePoints="[(5.5 : 1.21719482421875); (6.875 : 1.21719482421875)]" fixedFrom="Algorithm" fixedTo="Algorithm" TargetRelationshipDomainClassId="7a7fe09e-e9ef-4b01-9ff3-bde95e827b62">
     35    <inheritanceConnector edgePoints="[(5.5 : 1.21719482421875); (6.875 : 1.21719482421875)]" fixedFrom="NotFixed" fixedTo="NotFixed" TargetRelationshipDomainClassId="7a7fe09e-e9ef-4b01-9ff3-bde95e827b62">
    3636      <nodes>
    3737        <classShapeMoniker Id="c7373ccc-61b3-43fb-88fa-14149d69bee9" />
     
    4545      </nestedChildShapes>
    4646    </classShape>
    47     <associationConnector edgePoints="[(1.5625 : 2.97280110677083); (1.5625 : 3.625)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     47    <associationConnector edgePoints="[(1.5625 : 2.97280110677083); (1.5625 : 3.625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    4848      <AssociationMoniker Name="/DataClassesDataContext/HeuristicLabUser/HeuristicLabUser_HeuristicLabUserRole" />
    4949      <nodes>
     
    5252      </nodes>
    5353    </associationConnector>
    54     <associationConnector edgePoints="[(3.9687475 : 2.45359537760417); (3.9687475 : 4.35564697265625); (2.625 : 4.35564697265625)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     54    <associationConnector edgePoints="[(3.9687475 : 2.45359537760417); (3.9687475 : 4.35564697265625); (2.625 : 4.35564697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    5555      <AssociationMoniker Name="/DataClassesDataContext/HeuristicLabAbstractRole/HeuristicLabAbstractRole_HeuristicLabUserRole" />
    5656      <nodes>
  • branches/HeuristicLab.Services.Authentication Prototype/Persistence/DataClasses.designer.cs

    r3942 r3943  
    22//------------------------------------------------------------------------------
    33// <auto-generated>
    4 //     Dieser Code wurde von einem Tool generiert.
    5 //     Laufzeitversion:2.0.50727.4927
     4//     This code was generated by a tool.
     5//     Runtime Version:2.0.50727.4927
    66//
    7 //     Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
    8 //     der Code erneut generiert wird.
     7//     Changes to this file may cause incorrect behavior and will be lost if
     8//     the code is regenerated.
    99// </auto-generated>
    1010//------------------------------------------------------------------------------
     
    144144   
    145145    [Column(Storage="_UserName", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
    146     public override string UserName
     146    public virtual string UserName
    147147    {
    148148      get
     
    173173   
    174174    [Column(Storage="_LastPasswordChangedDate", UpdateCheck=UpdateCheck.Never)]
    175     public override System.DateTime LastPasswordChangedDate
     175    public virtual System.DateTime LastPasswordChangedDate
    176176    {
    177177      get
     
    182182   
    183183    [Column(Storage="_PasswordQuestion", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
    184     public override string PasswordQuestion
     184    public virtual string PasswordQuestion
    185185    {
    186186      get
     
    211211   
    212212    [Column(Storage="_Email", CanBeNull=false)]
    213     public override string Email
     213    public virtual string Email
    214214    {
    215215      get
     
    231231   
    232232    [Column(Storage="_Comment", CanBeNull=false)]
    233     public override string Comment
     233    public virtual string Comment
    234234    {
    235235      get
     
    298298  [Table(Name="")]
    299299  [InheritanceMapping(Code="permission", Type=typeof(HeuristicLabPermissionRole))]
    300   [InheritanceMapping(Code="role", Type=typeof(HeuristicLabRole))]
     300  [InheritanceMapping(Code="role", Type=typeof(HeuristicLabRole), IsDefault=true)]
    301301  public abstract partial class HeuristicLabAbstractRole : INotifyPropertyChanging, INotifyPropertyChanged
    302302  {
     
    312312    private string _RoleType = default(string);
    313313   
     314    private EntitySet<HeuristicLabAbstractRole> _HeuristicLabAbstractRole2;
     315   
    314316    private EntitySet<HeuristicLabUserRole> _HeuristicLabUserRole;
    315    
    316     private EntitySet<HeuristicLabAbstractRole> _HeuristicLabAbstractRole2;
    317317   
    318318    private EntityRef<HeuristicLabAbstractRole> _HeuristicLabAbstractRole1;
     
    330330    public HeuristicLabAbstractRole()
    331331    {
     332      this._HeuristicLabAbstractRole2 = new EntitySet<HeuristicLabAbstractRole>(new Action<HeuristicLabAbstractRole>(this.attach_HeuristicLabAbstractRole2), new Action<HeuristicLabAbstractRole>(this.detach_HeuristicLabAbstractRole2));
    332333      this._HeuristicLabUserRole = new EntitySet<HeuristicLabUserRole>(new Action<HeuristicLabUserRole>(this.attach_HeuristicLabUserRole), new Action<HeuristicLabUserRole>(this.detach_HeuristicLabUserRole));
    333       this._HeuristicLabAbstractRole2 = new EntitySet<HeuristicLabAbstractRole>(new Action<HeuristicLabAbstractRole>(this.attach_HeuristicLabAbstractRole2), new Action<HeuristicLabAbstractRole>(this.detach_HeuristicLabAbstractRole2));
    334334      this._HeuristicLabAbstractRole1 = default(EntityRef<HeuristicLabAbstractRole>);
    335335      OnCreated();
     
    394394    }
    395395   
     396    [Association(Name="HeuristicLabAbstractRole_HeuristicLabAbstractRole", Storage="_HeuristicLabAbstractRole2", ThisKey="ID", OtherKey="ParentRoleID")]
     397    public EntitySet<HeuristicLabAbstractRole> HeuristicLabAbstractRole2
     398    {
     399      get
     400      {
     401        return this._HeuristicLabAbstractRole2;
     402      }
     403      set
     404      {
     405        this._HeuristicLabAbstractRole2.Assign(value);
     406      }
     407    }
     408   
    396409    [Association(Name="HeuristicLabAbstractRole_HeuristicLabUserRole", Storage="_HeuristicLabUserRole", ThisKey="ID", OtherKey="HeuristicLabRoleID")]
    397410    public EntitySet<HeuristicLabUserRole> HeuristicLabUserRole
     
    404417      {
    405418        this._HeuristicLabUserRole.Assign(value);
    406       }
    407     }
    408    
    409     [Association(Name="HeuristicLabAbstractRole_HeuristicLabAbstractRole", Storage="_HeuristicLabAbstractRole2", ThisKey="ID", OtherKey="ParentRoleID")]
    410     public EntitySet<HeuristicLabAbstractRole> HeuristicLabAbstractRole2
    411     {
    412       get
    413       {
    414         return this._HeuristicLabAbstractRole2;
    415       }
    416       set
    417       {
    418         this._HeuristicLabAbstractRole2.Assign(value);
    419419      }
    420420    }
     
    474474    }
    475475   
     476    private void attach_HeuristicLabAbstractRole2(HeuristicLabAbstractRole entity)
     477    {
     478      this.SendPropertyChanging();
     479      entity.HeuristicLabAbstractRole1 = this;
     480    }
     481   
     482    private void detach_HeuristicLabAbstractRole2(HeuristicLabAbstractRole entity)
     483    {
     484      this.SendPropertyChanging();
     485      entity.HeuristicLabAbstractRole1 = null;
     486    }
     487   
    476488    private void attach_HeuristicLabUserRole(HeuristicLabUserRole entity)
    477489    {
     
    484496      this.SendPropertyChanging();
    485497      entity.HeuristicLabAbstractRole = null;
    486     }
    487    
    488     private void attach_HeuristicLabAbstractRole2(HeuristicLabAbstractRole entity)
    489     {
    490       this.SendPropertyChanging();
    491       entity.HeuristicLabAbstractRole1 = this;
    492     }
    493    
    494     private void detach_HeuristicLabAbstractRole2(HeuristicLabAbstractRole entity)
    495     {
    496       this.SendPropertyChanging();
    497       entity.HeuristicLabAbstractRole1 = null;
    498498    }
    499499  }
  • branches/HeuristicLab.Services.Authentication Prototype/Persistence/DatabaseUtil.cs

    r3940 r3943  
    1 namespace Persistence {
     1using System;
     2
     3namespace Persistence {
    24  /// <summary>
    3   ///
     5  /// combines multiple used static methods into one class
    46  /// </summary>
    57  public class DatabaseUtil {
    68    /// <summary>
    7     ///
     9    /// creates and returns a database connection, if possible
    810    /// </summary>
    9     /// <returns></returns>
     11    /// <returns>database connection (could be null)</returns>
    1012    public static DataClassesDataContext createDataClassesDataContext() {
    11       return new Persistence.DataClassesDataContext(@"C:\TEMP\HeuristicLabTemp.mdf");
     13      DataClassesDataContext db;
     14      try {
     15        db = new Persistence.DataClassesDataContext(@"C:\TEMP\HeuristicLabTemp.mdf");
     16      }
     17      catch (Exception) {
     18        return null;
     19      }
     20      return db;
     21    }
     22
     23    /// <summary>
     24    /// creates a new database out of the LINQ to SQL classes
     25    /// </summary>
     26    /// <param name="db">DataClassesDataContext</param>
     27    public static void createDatabase(DataClassesDataContext db) {
     28      if (db == null) {
     29        throw new ArgumentNullException("db");
     30      }
     31     
     32      if (db.DatabaseExists()) {
     33        Console.WriteLine("Deleting old database...");
     34        db.DeleteDatabase();
     35        Console.WriteLine("Deleted old database!");
     36      }
     37
     38      Console.WriteLine("Creating new database...");
     39      db.CreateDatabase();
     40      Console.WriteLine("Created new database!");
    1241    }
    1342  }
  • branches/HeuristicLab.Services.Authentication Prototype/Persistence/HeuristicLabUser.cs

    r3941 r3943  
    33
    44namespace Persistence {
     5  /// <summary>
     6  /// implements the MembershipUser for HeuristicLab
     7  /// </summary>
    58  partial class HeuristicLabUser : MembershipUser {
     9    public HeuristicLabUser(string name, string email, string passwordQuestion, string comment) : this() {
     10      _UserName = name;
     11      Password = "INIT"; // just for tests
     12      _LastPasswordChangedDate = System.DateTime.Today;
     13      _PasswordQuestion = passwordQuestion;
     14      PasswordAnswer = "";
     15      Email = email;
     16      Comment = comment;
     17    }
     18
    619    public override bool ChangePassword(string oldPassword, string newPassword) {
    720      if (oldPassword == null) {
  • branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs

    r3939 r3943  
    11using System;
    2 using System.Collections.Generic;
    32using System.Linq;
    4 using System.Text;
    53using System.Web.Security;
     4using Persistence;
    65
    76namespace Service.Provider {
     
    1716
    1817    public override bool ChangePassword(string username, string oldPassword, string newPassword) {
    19       throw new NotImplementedException();
     18      DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext();
     19      if (db == null) {
     20        return false;
     21      }
     22      try {
     23        HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == username);
     24        if (u.ChangePassword(oldPassword, newPassword)) {
     25          db.SubmitChanges();
     26          return true;
     27        } else {
     28          return false;
     29        }
     30      }
     31      catch (Exception) {
     32        return false;
     33      }
    2034    }
    2135
  • branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabRoleProvider.cs

    r3939 r3943  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    52using System.Web.Security;
     3using Persistence;
    64
    75namespace Service.Provider {
  • branches/HeuristicLab.Services.Authentication Prototype/Service/Service.csproj

    r3932 r3943  
    3838    </Reference>
    3939    <Reference Include="System.Data" />
     40    <Reference Include="System.Data.Linq">
     41      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     42    </Reference>
    4043    <Reference Include="System.Runtime.Serialization">
    4144      <RequiredTargetFramework>3.0</RequiredTargetFramework>
     
    7477  </Target>
    7578  -->
     79  <ProjectExtensions>
     80    <VisualStudio>
     81      <FlavorProperties GUID="{3D9AD99F-2412-4246-B90B-4EAA41C64699}">
     82        <WcfProjectProperties>
     83          <AutoStart>True</AutoStart>
     84        </WcfProjectProperties>
     85      </FlavorProperties>
     86    </VisualStudio>
     87  </ProjectExtensions>
    7688</Project>
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs

    r3939 r3943  
    44
    55namespace UnitTests {
    6 
    7 
    86  /// <summary>
    97  ///Dies ist eine Testklasse für "HeuristicLabMembershipProviderTest" und soll
     
    119  ///</summary>
    1210  [TestClass()]
    13   public class HeuristicLabMembershipProviderTest {
    14 
    15 
     11  public class HeuristicLabMembershipProviderTest : AbstractHeuristicLabTest {
    1612    private TestContext testContextInstance;
    1713
     
    5955    #endregion
    6056
    61 
    6257    /// <summary>
    6358    ///Ein Test für "RequiresUniqueEmail"
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabRoleProviderTest.cs

    r3939 r3943  
    22using Microsoft.VisualStudio.TestTools.UnitTesting;
    33namespace UnitTests {
    4 
    5 
    64  /// <summary>
    75  ///Dies ist eine Testklasse für "HeuristicLabRoleProviderTest" und soll
     
    97  ///</summary>
    108  [TestClass()]
    11   public class HeuristicLabRoleProviderTest {
    12 
    13 
     9  public class HeuristicLabRoleProviderTest : AbstractHeuristicLabTest {
    1410    private TestContext testContextInstance;
    1511
     
    5753    #endregion
    5854
    59 
    6055    /// <summary>
    6156    ///Ein Test für "ApplicationName"
  • 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  }
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/UnitTests.csproj

    r3940 r3943  
    5858  </ItemGroup>
    5959  <ItemGroup>
     60    <Compile Include="AbstractHeuristicLabTest.cs" />
    6061    <Compile Include="HeuristicLabMembershipProviderTest.cs" />
    6162    <Compile Include="HeuristicLabRoleProviderTest.cs" />
Note: See TracChangeset for help on using the changeset viewer.