Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/10 21:09:36 (14 years ago)
Author:
bfarka
Message:

added unit tests to check if the unique constraints on rolename username email are working (1046)

Location:
branches/HeuristicLab.Services.Authentication Prototype/UnitTests
Files:
2 edited

Legend:

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

    r3965 r3974  
    77using System.Linq;
    88using System.Collections.Generic;
     9using System.Data.SqlClient;
    910
    1011namespace UnitTests {
     
    216217    public void ValidateUserTestHashed() {
    217218      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider();
    218       NameValueCollection  config = new NameValueCollection();
     219      NameValueCollection config = new NameValueCollection();
    219220      config.Add("passwordFormat", "Hashed");
    220       target.Initialize("",config);
     221      target.Initialize("", config);
    221222      MembershipCreateStatus status;
    222223      target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
     
    490491      Assert.Inconclusive("TODO: Implement code to verify target");
    491492    }
     493
     494    [TestMethod()]
     495    public void NoDuplicateUserNameTest() {
     496      try {
     497        Persistence.HeuristicLabUser user = new Persistence.HeuristicLabUser("duplicateName", "mail", "myQuestion", "myComment");
     498        db.HeuristicLabUsers.InsertOnSubmit(user);
     499        Persistence.HeuristicLabUser user2 = new Persistence.HeuristicLabUser("duplicateName", "mail2", "myQuestion2", "myComment2");
     500        db.HeuristicLabUsers.InsertOnSubmit(user2);
     501        db.SubmitChanges();
     502        Assert.Fail();
     503      }
     504      catch (SqlException) {
     505        //swallowing Exception because it is expected that a SQL Exception is thrown       
     506      }
     507    }
     508    [TestMethod()]
     509    public void NoDuplicateEmailTest() {
     510      try {
     511        Persistence.HeuristicLabUser user = new Persistence.HeuristicLabUser("duplicateName", "mail", "myQuestion", "myComment");
     512        db.HeuristicLabUsers.InsertOnSubmit(user);
     513        Persistence.HeuristicLabUser user2 = new Persistence.HeuristicLabUser("duplicateName2", "mail", "myQuestion2", "myComment2");
     514        db.HeuristicLabUsers.InsertOnSubmit(user2);
     515        db.SubmitChanges();
     516        Assert.Fail();
     517      }
     518      catch (SqlException) {
     519        //swallowing Exception because it is expected that a SQL Exception is thrown       
     520      }
     521    }
    492522  }
    493523}
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabRoleProviderTest.cs

    r3967 r3974  
    33using System.Linq;
    44using System.Collections.Generic;
     5using System.Data.SqlClient;
    56namespace UnitTests {
    67  /// <summary>
     
    325326      Assert.IsNotNull(target);
    326327    }
     328    [TestMethod()]
     329    public void NoDuplicateRoleTest() {
     330      try {
     331        Persistence.HeuristicLabRole role = new Persistence.HeuristicLabRole();
     332        role.RoleName ="role1";
     333        Persistence.HeuristicLabRole role1 = new Persistence.HeuristicLabRole();
     334        role1.RoleName ="role1";
     335        db.HeuristicLabRole.InsertOnSubmit(role);
     336        db.HeuristicLabRole.InsertOnSubmit(role1);
     337        db.SubmitChanges();
     338        Assert.Fail();
     339      }
     340      catch (SqlException) {
     341        //swallowing Exception because it is expected that a SQL Exception is thrown       
     342      }
     343    }
    327344  }
    328345
     346 
     347
    329348
    330349
Note: See TracChangeset for help on using the changeset viewer.