Inheritance: Contrive.Common.Data.DataServiceBase, IUserRepository
Beispiel #1
0
 public void When_generating_a_user_password()
 {
     var verified = false;
     "Given an existing user".Context(() => new ConnectionProviderStartupTask().OnStartup());
     "When generating a password".Do(() =>
                                     {
                                         var repository = new UserRepository();
                                         var u = repository.GetUserByUserName("ChrisAshton");
                                         var cryptographer = new WebCryptographer();
                                         //u.PasswordSalt = cryptographer.GenerateSalt();
                                         var passwordHash1 = cryptographer.CalculatePasswordHash("pass@word1", u.PasswordSalt);
                                         var passwordHash2 = cryptographer.CalculatePasswordHash("pass@word1", u.PasswordSalt);
                                         verified = u.PasswordHash == passwordHash1;
                                         Console.WriteLine("{0} - {1} {2}, {3}".FormatWith(u.Id, u.FirstName, u.LastName, u.Email));
                                         Console.WriteLine("Existing hash:    {0}".FormatWith(u.PasswordHash));
                                         Console.WriteLine("Generated hash 2: {0}".FormatWith(passwordHash1));
                                         Console.WriteLine("Generated hash 1: {0}".FormatWith(passwordHash2));
                                     });
     "It should match the existing password hash".Assert(() => verified.Should()
                                                                       .BeTrue());
 }
Beispiel #2
0
 //[Specification]
 public void When_updating_all_users()
 {
     "Given ".Context(() => new ConnectionProviderStartupTask().OnStartup());
     "When ".Do(() =>
                {
                    var repository = new UserRepository();
                    var users = repository.GetAll();
                    users.Each(u =>
                               {
                                   //u.PasswordSalt = cryptographer.GenerateSalt();
                                   u.PasswordHash = _cryptographer.CalculatePasswordHash("pass@word1", u.PasswordSalt);
                                   repository.Update(u);
                                   Console.WriteLine("{0} - {1} {2}, {3}".FormatWith(u.Id, u.FirstName, u.LastName, u.Email));
                               });
                });
     "It should ".Assert(() => { });
 }