Index: /branches/HeuristicLab.Services.Authentication Prototype/HeuristicLab.Services.Authentication Prototyp.sln
===================================================================
--- /branches/HeuristicLab.Services.Authentication Prototype/HeuristicLab.Services.Authentication Prototyp.sln	(revision 3955)
+++ /branches/HeuristicLab.Services.Authentication Prototype/HeuristicLab.Services.Authentication Prototyp.sln	(revision 3956)
@@ -11,5 +11,5 @@
 	ProjectSection(SolutionItems) = preProject
 		HeuristicLab.Services.Authentication Prototyp.vsmdi = HeuristicLab.Services.Authentication Prototyp.vsmdi
-		HeuristicLab.Services.Authentication Prototyp1.vsmdi = HeuristicLab.Services.Authentication Prototyp1.vsmdi
+		HeuristicLab.Services.Authentication Prototyp2.vsmdi = HeuristicLab.Services.Authentication Prototyp2.vsmdi
 		LocalTestRun.testrunconfig = LocalTestRun.testrunconfig
 	EndProjectSection
@@ -17,5 +17,5 @@
 Global
 	GlobalSection(TestCaseManagementSettings) = postSolution
-		CategoryFile = HeuristicLab.Services.Authentication Prototyp1.vsmdi
+		CategoryFile = HeuristicLab.Services.Authentication Prototyp2.vsmdi
 	EndGlobalSection
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
Index: /branches/HeuristicLab.Services.Authentication Prototype/HeuristicLab.Services.Authentication Prototyp2.vsmdi
===================================================================
--- /branches/HeuristicLab.Services.Authentication Prototype/HeuristicLab.Services.Authentication Prototyp2.vsmdi	(revision 3956)
+++ /branches/HeuristicLab.Services.Authentication Prototype/HeuristicLab.Services.Authentication Prototyp2.vsmdi	(revision 3956)
@@ -0,0 +1,6 @@
+﻿<?xml version="1.0" encoding="UTF-8"?>
+<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2006">
+  <TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
+    <RunConfiguration id="3cde0e70-9e75-4b76-a987-9e1d702958f0" name="Lokaler Testlauf" storage="localtestrun.testrunconfig" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common,   PublicKeyToken=b03f5f7f11d50a3a" />
+  </TestList>
+</TestLists>
Index: /branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs
===================================================================
--- /branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs	(revision 3955)
+++ /branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs	(revision 3956)
@@ -16,47 +16,112 @@
 
     public override bool ChangePassword(string username, string oldPassword, string newPassword) {
-      DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext();
-      if (db == null) {
-        return false;
-      }
-      try {
-        HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == username);
-        if (u.ChangePassword(oldPassword, newPassword)) {
+      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
+        // check database connection
+        if (db == null) {
+          return false;
+        }
+        try {
+          // try to get user
+          HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == username);
+          if (u.ChangePassword(oldPassword, newPassword)) {
+            // save user to database only if needed
+            db.SubmitChanges();
+            return true;
+          } else {
+            return false;
+          }
+        }
+        catch (Exception) {
+          return false;
+        }
+      }
+    }
+
+    public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) {
+      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
+        // check database connection
+        if (db == null) {
+          return false;
+        }
+        try {
+          // try to get user
+          HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == username);
+          if (u.ChangePasswordQuestionAndAnswer(password, newPasswordQuestion, newPasswordAnswer)) {
+            // save user to database only if needed
+            db.SubmitChanges();
+            return true;
+          } else {
+            return false;
+          }
+        }
+        catch (Exception) {
+          return false;
+        }
+      }
+    }
+
+    public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) {
+      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
+        // check database connection
+        if (db == null) {
+          status = MembershipCreateStatus.ProviderError;
+          return null;
+        }
+        try {
+          // check for duplicate entries
+          if (db.HeuristicLabUsers.Count(x => x.UserName == username) > 0) {
+            status = MembershipCreateStatus.DuplicateUserName;
+            return null;
+          }
+          if (db.HeuristicLabUsers.Count(x => x.Email == email) > 0) {
+            status = MembershipCreateStatus.DuplicateEmail;
+            return null;
+          }
+
+          // create new user
+          HeuristicLabUser u = new HeuristicLabUser(username, email, passwordQuestion, "");
+          u.ChangePassword("INIT", password);
+          u.ChangePasswordQuestionAndAnswer(password, passwordQuestion, passwordAnswer);
+          // save user into database
+          db.HeuristicLabUsers.InsertOnSubmit(u);
+          db.SubmitChanges();
+
+          // success
+          status = MembershipCreateStatus.Success;
+          return u;
+        }
+        catch (Exception) {
+          // error
+          status = MembershipCreateStatus.ProviderError;
+          return null;
+        }
+      }
+    }
+
+    public override bool DeleteUser(string username, bool deleteAllRelatedData) {
+      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
+        // check database connection
+        if (db == null) {
+          return false;
+        }
+        try {
+          // try to get user
+          HeuristicLabUser u = 
+            db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == username);
+
+          // optionally delete related data
+          if (deleteAllRelatedData) {
+            db.HeuristicLabUserRole.DeleteAllOnSubmit<HeuristicLabUserRole>(u.HeuristicLabUserRole);
+          }
+          
+          // delete user
+          db.HeuristicLabUsers.DeleteOnSubmit(u);
           db.SubmitChanges();
           return true;
-        } else {
-          return false;
-        }
-      }
-      catch (Exception) {
-        return false;
-      }
-    }
-
-    public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) {
-      DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext();
-      if (db == null) {
-        return false;
-      }
-      try {
-        HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == username);
-        if (u.ChangePasswordQuestionAndAnswer(password, newPasswordQuestion, newPasswordAnswer)) {
-          db.SubmitChanges();
-          return true;
-        } else {
-          return false;
-        }
-      }
-      catch (Exception) {
-        return false;
-      }
-    }
-
-    public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) {
-      throw new NotImplementedException();
-    }
-
-    public override bool DeleteUser(string username, bool deleteAllRelatedData) {
-      throw new NotImplementedException();
+        }
+        catch (Exception) {
+          return false;
+        }
+      }
     }
 
@@ -86,4 +151,5 @@
 
     public override string GetPassword(string username, string answer) {
+
       throw new NotImplementedException();
     }
Index: /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs
===================================================================
--- /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs	(revision 3955)
+++ /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs	(revision 3956)
@@ -1,5 +1,9 @@
-﻿using Service.Provider;
+﻿using System;
+using Service.Provider;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using System.Web.Security;
+using Persistence;
+using System.Linq;
+using System.Collections.Generic;
 
 namespace UnitTests {
@@ -368,12 +372,13 @@
     [TestMethod()]
     public void DeleteUserTest() {
-      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value
-      string username = string.Empty; // TODO: Initialize to an appropriate value
-      bool deleteAllRelatedData = false; // TODO: Initialize to an appropriate value
-      bool expected = false; // TODO: Initialize to an appropriate value
-      bool actual;
-      actual = target.DeleteUser(username, deleteAllRelatedData);
-      Assert.AreEqual(expected, actual);
-      Assert.Inconclusive("Verify the correctness of this test method.");
+      // insert new user
+      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider();
+      MembershipCreateStatus status;
+      target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
+      Assert.AreEqual(MembershipCreateStatus.Success, status);
+
+      // delete user
+      Assert.IsTrue(target.DeleteUser("testname", true));
+      Assert.AreEqual(0, db.HeuristicLabUsers.Count(x => x.UserName == "testname"));
     }
 
@@ -383,20 +388,24 @@
     [TestMethod()]
     public void CreateUserTest() {
-      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value
-      string username = string.Empty; // TODO: Initialize to an appropriate value
-      string password = string.Empty; // TODO: Initialize to an appropriate value
-      string email = string.Empty; // TODO: Initialize to an appropriate value
-      string passwordQuestion = string.Empty; // TODO: Initialize to an appropriate value
-      string passwordAnswer = string.Empty; // TODO: Initialize to an appropriate value
-      bool isApproved = false; // TODO: Initialize to an appropriate value
-      object providerUserKey = null; // TODO: Initialize to an appropriate value
-      MembershipCreateStatus status = new MembershipCreateStatus(); // TODO: Initialize to an appropriate value
-      MembershipCreateStatus statusExpected = new MembershipCreateStatus(); // TODO: Initialize to an appropriate value
-      MembershipUser expected = null; // TODO: Initialize to an appropriate value
-      MembershipUser actual;
-      actual = target.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status);
-      Assert.AreEqual(statusExpected, status);
-      Assert.AreEqual(expected, actual);
-      Assert.Inconclusive("Verify the correctness of this test method.");
+      // create user
+      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider();
+      MembershipCreateStatus status;
+      target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
+      Assert.AreEqual(MembershipCreateStatus.Success, status);
+
+      // check if user is OK
+      HeuristicLabUser u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
+      Assert.AreEqual<string>("testname", u.UserName);
+      Assert.AreEqual<string>("testemail", u.Email);
+      Assert.AreEqual<string>("newPassword", u.Password);
+      Assert.AreEqual<string>("testquestion", u.PasswordQuestion);
+      Assert.AreEqual<string>("testanswer", u.PasswordAnswer);
+      Assert.AreEqual<string>("", u.Comment);
+
+      // check for duplicate errors
+      target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
+      Assert.AreEqual(MembershipCreateStatus.DuplicateUserName, status);
+      target.CreateUser("testname2", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
+      Assert.AreEqual(MembershipCreateStatus.DuplicateEmail, status);
     }
 
@@ -406,14 +415,22 @@
     [TestMethod()]
     public void ChangePasswordQuestionAndAnswerTest() {
-      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value
-      string username = string.Empty; // TODO: Initialize to an appropriate value
-      string password = string.Empty; // TODO: Initialize to an appropriate value
-      string newPasswordQuestion = string.Empty; // TODO: Initialize to an appropriate value
-      string newPasswordAnswer = string.Empty; // TODO: Initialize to an appropriate value
-      bool expected = false; // TODO: Initialize to an appropriate value
-      bool actual;
-      actual = target.ChangePasswordQuestionAndAnswer(username, password, newPasswordQuestion, newPasswordAnswer);
-      Assert.AreEqual(expected, actual);
-      Assert.Inconclusive("Verify the correctness of this test method.");
+      // create user
+      HeuristicLabUser u = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
+      db.HeuristicLabUsers.InsertOnSubmit(u);
+      db.SubmitChanges();
+
+      // check if user is stored
+      u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
+      Assert.AreEqual<String>("testquestion", u.PasswordQuestion);
+      Assert.AreEqual<String>("", u.PasswordAnswer);
+
+      // change data and check again
+      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider();
+      // gibt zwar true zurück, was schon mal gut ist
+      Assert.IsTrue(target.ChangePasswordQuestionAndAnswer("testname", "INIT", "newquestion", "newanswer"));
+      // aber hier ist die änderung noch nicht da!! es ist immer noch die alte frage + alte antwort
+      u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
+      Assert.AreEqual<String>("newquestion", u.PasswordQuestion);
+      Assert.AreEqual<String>("newanswer", u.PasswordAnswer);
     }
 
@@ -423,13 +440,19 @@
     [TestMethod()]
     public void ChangePasswordTest() {
-      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value
-      string username = string.Empty; // TODO: Initialize to an appropriate value
-      string oldPassword = string.Empty; // TODO: Initialize to an appropriate value
-      string newPassword = string.Empty; // TODO: Initialize to an appropriate value
-      bool expected = false; // TODO: Initialize to an appropriate value
-      bool actual;
-      actual = target.ChangePassword(username, oldPassword, newPassword);
-      Assert.AreEqual(expected, actual);
-      Assert.Inconclusive("Verify the correctness of this test method.");
+      // create user
+      HeuristicLabUser u = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
+      db.HeuristicLabUsers.InsertOnSubmit(u);
+      db.SubmitChanges();
+
+      // check if user is stored
+      u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
+      Assert.AreEqual<String>("INIT", u.Password);
+
+      // change data and check again
+      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider();
+      Assert.IsTrue(target.ChangePassword("testname", "INIT", "newPassword"));
+      // hat nix gemacht!! :(
+      u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
+      Assert.AreEqual<String>("newPassword", u.Password);
     }
 
Index: /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabUserTest.cs
===================================================================
--- /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabUserTest.cs	(revision 3955)
+++ /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabUserTest.cs	(revision 3956)
@@ -20,8 +20,8 @@
     public void modifyUserTest() {
       // insert new user
-      Persistence.HeuristicLabUser user = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
+      HeuristicLabUser user = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
       db.HeuristicLabUsers.InsertOnSubmit(user);
       db.SubmitChanges();
-      Persistence.HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == "testname");
+      HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == "testname");
       Assert.IsNotNull(u);
       Assert.AreEqual<string>("testname", u.UserName);
