private static void ResetCurrentUser() { var userSession = MockRepository.GenerateStub<IUserSession>(); CurrentUser = new User(); userSession.Stub(us => us.GetCurrentUser()).Return(CurrentUser); ObjectFactory.Inject(userSession); }
public void Should_check_for_uniqueness_by_specification() { var address = "*****@*****.**"; var otherAddress = "*****@*****.**"; var differentCase = "*****@*****.**"; var existing = new User {EmailAddress = address}; var incoming = new User {EmailAddress = otherAddress}; PersistEntities(existing); var counter = CreateEntityCounter(); //The only existing one is "me" var spec = new EntitySpecificationOfGuid<User>{PropertyExpression = x=> x.EmailAddress, Value = address, Id = existing.Id}; counter.CountByProperty(spec).ShouldEqual(0); //The existing user has this value var spec2 = new EntitySpecificationOfGuid<User>{PropertyExpression = x=> x.EmailAddress, Value = address, Id = incoming.Id}; counter.CountByProperty(spec2).ShouldEqual(1); //Case insensitive. A SQLServer installation configuration. var spec3 = new EntitySpecificationOfGuid<User> { PropertyExpression = x => x.EmailAddress, Value = differentCase, Id = incoming.Id }; counter.CountByProperty(spec3).ShouldEqual(1); //This email address is not in the database var spec4 = new EntitySpecificationOfGuid<User> { PropertyExpression = x => x.EmailAddress, Value = otherAddress, Id = incoming.Id }; counter.CountByProperty(spec4).ShouldEqual(0); }
public void should_not_update_user_audit_info() { ResetCurrentUser(); var user = new User(); PersistEntities(CurrentUser); PersistEntitiesWithAuditing(CurrentUser, new DateTime(2009, 1, 1), user); user.ChangeAuditInfo.Created.ShouldBeNull(); user.ChangeAuditInfo.CreatedBy.ShouldBeNull(); user.ChangeAuditInfo.Updated.ShouldBeNull(); user.ChangeAuditInfo.UpdatedBy.ShouldBeNull(); using (ISession session = GetSession()) { var persistedUser = session.Load<User>(user.Id); session.SaveOrUpdate(persistedUser); session.Flush(); persistedUser.ChangeAuditInfo.Created.ShouldBeNull(); persistedUser.ChangeAuditInfo.CreatedBy.ShouldBeNull(); persistedUser.ChangeAuditInfo.Updated.ShouldBeNull(); persistedUser.ChangeAuditInfo.UpdatedBy.ShouldBeNull(); } }
public void User_should_be_cache_enabled() { var user = new User {Username = "******"}; var session = GetSession(); var transaction = session.BeginTransaction(); session.SaveOrUpdate(user); transaction.Commit(); session.Dispose(); var session2 = GetSession(); var result = session2.CreateQuery("from User u where u.Username = ?").SetString(0, "foo"). SetCacheable(true).UniqueResult<User>(); var command = session2.Connection.CreateCommand(); command.CommandText = "delete from Users"; command.ExecuteNonQuery(); session2.Dispose(); var result2 = GetSession().CreateQuery("from User u where u.Username = ?").SetString(0, "foo") .SetCacheable(true).UniqueResult <User>(); Assert.That(result2, Is.EqualTo(result)); Assert.That(result2, Is.Not.SameAs(result)); }
protected void PersistEntitiesWithAuditing(User user, DateTime today, params AuditedPersistentObject[] entities) { using (ISession session = GetAuditedSession(user, today)) { Persist(entities, session); } }
public void Should_be_admin_if_username_matches() { var user=new User {Username = User.ADMIN_USERNAME}; var userIsAdmin = user.IsAdmin(); userIsAdmin.ShouldBeTrue(); }
private static void blowUpIfEmployeeCannotLogin(User user) { if (user == null) { throw new InvalidCredentialException( "That user doesn't exist or is not valid."); } }
public ViewResult Edit(User entity) { if (!_securityContext.IsAdmin()) { return NotAuthorizedView; } return AutoMappedView<UserInput>(entity ?? new User()); }
public void Should_add_and_remove_users() { var @group = new UserGroup(); var child = new User(); group.Add(child); group.GetUsers().ShouldEqual(new []{child}); group.Remove(child); group.GetUsers().Length.ShouldEqual(0); }
public void Save_should_update_an_existing_user() { var user = new User {Username = "******", Id = Guid.NewGuid()}; var form = new UserInput {Id = user.Id, Password = "******"}; var controller = new UserController(null, PermisiveSecurityContext()); var result = (CommandResult) controller.Edit(form); result.Success.AssertActionRedirect().ToAction<HomeController>(a => a.Index(null)); }
public void Should_authenticate_if_salt_matches() { var user = new User {PasswordHash = "123xyz"}; var cryptographer = S<ICryptographer>(); cryptographer.Stub(x => x.GetPasswordHash("password", user.PasswordSalt)).Return("123xyz"); cryptographer.Stub(x => x.GetPasswordHash("pasword", user.PasswordSalt)).Return("123xy"); IAuthenticationService service = new AuthenticationService(cryptographer); service.PasswordMatches(user, "password").ShouldBeTrue(); service.PasswordMatches(user, "pasword").ShouldBeFalse(); }
public void Should_map_user() { var user = new User { EmailAddress = "*****@*****.**", Name = "sdf", Username = "******", PasswordHash = "foo", PasswordSalt = "bar" }; AssertObjectCanBePersisted(user); }
public void Should_ignore_non_auditable_entities() { var userSession = S<IUserSession>(); var currentUser = new User(); userSession.Stub(us => us.GetCurrentUser()).Return(currentUser); var testEntity = S<PersistentObject>(); var interceptor = new ChangeAuditInfoInterceptor(userSession, null); interceptor.OnSave(testEntity, null, new[] {new ChangeAuditInfo()}, new[] {"ChangeAuditInfo"}, null); interceptor.OnFlushDirty(testEntity, null, new[] {new ChangeAuditInfo()}, null, new[] {"ChangeAuditInfo"}, null); }
public void The_security_context_should_find_a_user_has_permissions() { var session = S<IUserSession>(); var user = new User(); session.Stub(userSession => userSession.GetCurrentUser()).Return(user); var usergroup = new UserGroup(); usergroup.Add(user); ISecurityContext context = new SecurityContext(session, null); bool hasPermission = context.HasPermissionsFor(usergroup); hasPermission.ShouldBeTrue(); }
public void The_security_context_should_allow_a_system_admin_to_access_a_group() { var session = S<IUserSession>(); var user = new User(); session.Stub(userSession => userSession.GetCurrentUser()).Return(user); var userGroupRepo = S<IUserGroupRepository>(); var defaultUserGroup = new UserGroup(); defaultUserGroup.Add(user); userGroupRepo.Stub(repository => repository.GetDefaultUserGroup()).Return(defaultUserGroup); ISecurityContext context = new SecurityContext(session, userGroupRepo); bool hasPermission = context.IsAdmin(); hasPermission.ShouldBeTrue(); }
public void The_security_context_should_find_a_user_does_not_have_permissions() { var session = S<IUserSession>(); var user = new User(); session.Stub(userSession => userSession.GetCurrentUser()).Return(user); var usergroup = new UserGroup(); var userGroupRepo = S<IUserGroupRepository>(); userGroupRepo.Stub(repository => repository.GetDefaultUserGroup()).Return(new UserGroup()); ISecurityContext context = new SecurityContext(session, userGroupRepo); bool hasPermission = context.HasPermissionsFor(usergroup); hasPermission.ShouldBeFalse(); }
public void Should_tag_created_and_updated_info_when_no_created_date_exists() { var userSession = S<IUserSession>(); var currentUser = new User {Username = "******"}; userSession.Stub(us => us.GetCurrentUser()).Return(currentUser); var conference = new Conference(); var interceptor = new ChangeAuditInfoInterceptor(userSession, new Clock(new DateTime(2008, 10, 20))); interceptor.OnSave(conference, null, new[] {new ChangeAuditInfo()}, new[] {"ChangeAuditInfo"}, null); conference.ChangeAuditInfo.Created.ShouldEqual(new DateTime(2008, 10, 20)); conference.ChangeAuditInfo.CreatedBy.ShouldEqual(currentUser.Username); conference.ChangeAuditInfo.Updated.ShouldEqual(new DateTime(2008, 10, 20)); conference.ChangeAuditInfo.UpdatedBy.ShouldEqual(currentUser.Username); }
public void The_security_context_should_allow_admins_to_create_new_users_groups() { var session = S<IUserSession>(); var user = new User(); session.Stub(userSession => userSession.GetCurrentUser()).Return(user); var userGroupRepo = S<IUserGroupRepository>(); var userGroup = new UserGroup(); userGroup.Add(user); userGroupRepo.Stub(repository => repository.GetDefaultUserGroup()).Return(userGroup); ISecurityContext context = new SecurityContext(session, userGroupRepo); bool hasPermission = context.HasPermissionsFor(null); hasPermission.ShouldBeTrue(); }
public void Should_tag_updated_info_when_created_info_exists() { var userSession = S<IUserSession>(); var createdUser = new User {Username = "******"}; var currentUser = new User {Username = "******"}; userSession.Stub(us => us.GetCurrentUser()).Return(currentUser); var conference = new Conference { ChangeAuditInfo = new ChangeAuditInfo {Created = new DateTime(2008, 10, 1), CreatedBy = createdUser.Username} }; var interceptor = new ChangeAuditInfoInterceptor(userSession, new Clock(new DateTime(2008, 10, 20))); interceptor.OnFlushDirty(conference, null, new[] {conference.ChangeAuditInfo}, null, new[] {"ChangeAuditInfo"}, null); conference.ChangeAuditInfo.Created.ShouldEqual(new DateTime(2008, 10, 1)); conference.ChangeAuditInfo.CreatedBy.ShouldEqual(createdUser.Username); conference.ChangeAuditInfo.Updated.ShouldEqual(new DateTime(2008, 10, 20)); conference.ChangeAuditInfo.UpdatedBy.ShouldEqual(currentUser.Username); }
protected virtual ISession GetAuditedSession(User user, DateTime today) { return new SessionFactoryBuilder().GetFactory().OpenSession(new ChangeAuditInfoInterceptor(new UserSessionStub(user), new Clock(today))); }
public ViewResult Display(User entity) { return AutoMappedView<UserInput>(entity); }
public void LogIn(User user) { blowUpIfEmployeeCannotLogin(user); FormsAuthentication.RedirectFromLoginPage(user.Username, false); }
public void LogIn(User user) { _currentUser = user; }
public UserSessionStub(User currentUser) { _currentUser = currentUser; }
public bool PasswordMatches(User user, string password) { var passwordHash = _cryptographer.GetPasswordHash(password, user.PasswordSalt); return passwordHash.Equals(user.PasswordHash); }
public virtual void Remove(User child) { _users.Remove(child); }
public virtual void Add(User child) { _users.Add(child); }