public void Can_Perform_Add_With_Group() { var group = MockedUserGroup.CreateUserGroup(); // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); using (var repository = CreateUserGroupRepository(unitOfWork)) { repository.AddOrUpdate(group); unitOfWork.Commit(); } using (var repository = CreateRepository(unitOfWork)) { IUser user = MockedUser.CreateUser(); user.AddGroup(group.ToReadOnlyGroup()); // Act repository.AddOrUpdate(user); unitOfWork.Commit(); user = repository.Get(user.Id); // Assert Assert.That(user.HasIdentity, Is.True); Assert.AreEqual(1, user.Groups.Count()); Assert.AreEqual(group.Alias, user.Groups.ElementAt(0).Alias); } }
public void Can_Perform_Delete_On_UserGroupRepository() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); using (var repository = CreateRepository(unitOfWork)) { var userGroup = MockedUserGroup.CreateUserGroup(); // Act repository.AddOrUpdate(userGroup); unitOfWork.Commit(); var id = userGroup.Id; using (var repository2 = new UserGroupRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax)) { repository2.Delete(userGroup); unitOfWork.Commit(); var resolved = repository2.Get(id); // Assert Assert.That(resolved, Is.Null); } } }
public void Get_Groups_Assigned_To_Section() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = CreateRepository(provider); var user1 = MockedUserGroup.CreateUserGroup("1", allowedSections: new[] { "test1" }); var user2 = MockedUserGroup.CreateUserGroup("2", allowedSections: new[] { "test2" }); var user3 = MockedUserGroup.CreateUserGroup("3", allowedSections: new[] { "test1" }); repository.Save(user1); repository.Save(user2); repository.Save(user3); scope.Complete(); // Act var groups = repository.GetGroupsAssignedToSection("test1"); // Assert Assert.AreEqual(2, groups.Count()); var names = groups.Select(x => x.Name).ToArray(); Assert.IsTrue(names.Contains("TestUserGroup1")); Assert.IsFalse(names.Contains("TestUserGroup2")); Assert.IsTrue(names.Contains("TestUserGroup3")); } }
public void Can_Perform_Update_On_UserGroupRepository() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = CreateRepository(provider); var userGroup = MockedUserGroup.CreateUserGroup(); repository.Save(userGroup); // Act var resolved = repository.Get(userGroup.Id); resolved.Name = "New Name"; resolved.Permissions = new[] { "Z", "Y", "X" }; repository.Save(resolved); scope.Complete(); var updatedItem = repository.Get(userGroup.Id); // Assert Assert.That(updatedItem.Id, Is.EqualTo(resolved.Id)); Assert.That(updatedItem.Name, Is.EqualTo(resolved.Name)); Assert.That(updatedItem.Permissions, Is.EqualTo(resolved.Permissions)); } }
public void Get_All_Paged_Users_For_Group_With_Filter() { var userGroup = MockedUserGroup.CreateUserGroup(); ServiceContext.UserService.Save(userGroup); var users = MockedUser.CreateMulipleUsers(10).ToArray(); for (var i = 0; i < 10;) { users[i].AddGroup(userGroup.ToReadOnlyGroup()); i = i + 2; } for (var i = 0; i < 10;) { users[i].Name = "blah" + users[i].Name; i = i + 3; } ServiceContext.UserService.Save(users); long totalRecs; var found = ServiceContext.UserService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, userGroups: new[] { userGroup.Alias }, filter: "blah"); Assert.AreEqual(2, found.Count()); Assert.AreEqual(2, totalRecs); Assert.AreEqual("test0", found.First().Username); Assert.AreEqual("test6", found.Last().Username); }
public void Can_Perform_Get_On_UserGroupRepository() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = CreateRepository(provider); var userGroup = MockedUserGroup.CreateUserGroup(); repository.Save(userGroup); scope.Complete(); // Act var resolved = repository.Get(userGroup.Id); // Assert Assert.That(resolved.Id, Is.EqualTo(userGroup.Id)); //Assert.That(resolved.CreateDate, Is.GreaterThan(DateTime.MinValue)); //Assert.That(resolved.UpdateDate, Is.GreaterThan(DateTime.MinValue)); Assert.That(resolved.Name, Is.EqualTo(userGroup.Name)); Assert.That(resolved.Alias, Is.EqualTo(userGroup.Alias)); Assert.That(resolved.Permissions, Is.EqualTo(userGroup.Permissions)); } }
public void Can_Perform_Delete_On_UserGroupRepository() { var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = CreateRepository(provider); var userGroup = MockedUserGroup.CreateUserGroup(); // Act repository.Save(userGroup); var id = userGroup.Id; var repository2 = new UserGroupRepository((IScopeAccessor)provider, Core.Cache.CacheHelper.Disabled, Logger); repository2.Delete(userGroup); scope.Complete(); var resolved = repository2.Get(id); // Assert Assert.That(resolved, Is.Null); } }
public void Get_Groups_Assigned_To_Section() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); using (var repository = CreateRepository(unitOfWork)) { var user1 = MockedUserGroup.CreateUserGroup("1", allowedSections: new[] { "test1" }); var user2 = MockedUserGroup.CreateUserGroup("2", allowedSections: new[] { "test2" }); var user3 = MockedUserGroup.CreateUserGroup("3", allowedSections: new[] { "test1" }); repository.AddOrUpdate(user1); repository.AddOrUpdate(user2); repository.AddOrUpdate(user3); unitOfWork.Commit(); // Act var groups = repository.GetGroupsAssignedToSection("test1"); // Assert Assert.AreEqual(2, groups.Count()); var names = groups.Select(x => x.Name).ToArray(); Assert.IsTrue(names.Contains("TestUserGroup1")); Assert.IsFalse(names.Contains("TestUserGroup2")); Assert.IsTrue(names.Contains("TestUserGroup3")); } }
public void Can_Perform_Update_On_UserGroupRepository() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); using (var repository = CreateRepository(unitOfWork)) { var userGroup = MockedUserGroup.CreateUserGroup(); repository.AddOrUpdate(userGroup); unitOfWork.Commit(); // Act var resolved = repository.Get(userGroup.Id); resolved.Name = "New Name"; resolved.Permissions = new[] { "Z", "Y", "X" }; repository.AddOrUpdate(resolved); unitOfWork.Commit(); var updatedItem = repository.Get(userGroup.Id); // Assert Assert.That(updatedItem.Id, Is.EqualTo(resolved.Id)); Assert.That(updatedItem.Name, Is.EqualTo(resolved.Name)); Assert.That(updatedItem.Permissions, Is.EqualTo(resolved.Permissions)); } }
private IUserGroup[] CreateAndCommitMultipleUserGroups(IUserGroupRepository repository, IUnitOfWork unitOfWork) { var userGroup1 = MockedUserGroup.CreateUserGroup("1"); var userGroup2 = MockedUserGroup.CreateUserGroup("2"); var userGroup3 = MockedUserGroup.CreateUserGroup("3"); repository.AddOrUpdate(userGroup1); repository.AddOrUpdate(userGroup2); repository.AddOrUpdate(userGroup3); unitOfWork.Commit(); return(new IUserGroup[] { userGroup1, userGroup2, userGroup3 }); }
private IUserGroup[] CreateAndCommitMultipleUserGroups(IUserGroupRepository repository) { var userGroup1 = MockedUserGroup.CreateUserGroup("1"); var userGroup2 = MockedUserGroup.CreateUserGroup("2"); var userGroup3 = MockedUserGroup.CreateUserGroup("3"); repository.Save(userGroup1); repository.Save(userGroup2); repository.Save(userGroup3); return(new IUserGroup[] { userGroup1, userGroup2, userGroup3 }); }
private static User CreateAndCommitUserWithGroup(IUserRepository repository, IUserGroupRepository userGroupRepository, IDatabaseUnitOfWork unitOfWork) { var user = MockedUser.CreateUser(); repository.AddOrUpdate(user); unitOfWork.Commit(); var group = MockedUserGroup.CreateUserGroup(); userGroupRepository.AddOrUpdateGroupWithUsers(@group, new[] { user.Id }); unitOfWork.Commit(); return(user); }
private static User CreateAndCommitUserWithGroup(IUserRepository repository, IUserGroupRepository userGroupRepository) { var user = MockedUser.CreateUser(); repository.Save(user); var group = MockedUserGroup.CreateUserGroup(); userGroupRepository.AddOrUpdateGroupWithUsers(@group, new[] { user.Id }); user.AddGroup(group); return(user); }
public void Can_Perform_Add_On_UserGroupRepository() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); using (var repository = CreateRepository(unitOfWork)) { var userGroup = MockedUserGroup.CreateUserGroup(); // Act repository.AddOrUpdate(userGroup); unitOfWork.Commit(); // Assert Assert.That(userGroup.HasIdentity, Is.True); } }
public void Can_Perform_Add_On_UserGroupRepository() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = CreateRepository(provider); var userGroup = MockedUserGroup.CreateUserGroup(); // Act repository.Save(userGroup); scope.Complete(); // Assert Assert.That(userGroup.HasIdentity, Is.True); } }
public void Can_Verify_Fresh_Entity_Is_Not_Dirty() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); using (var repository = CreateRepository(unitOfWork)) { var userGroup = MockedUserGroup.CreateUserGroup(); repository.AddOrUpdate(userGroup); unitOfWork.Commit(); // Act var resolved = repository.Get(userGroup.Id); bool dirty = ((UserGroup)resolved).IsDirty(); // Assert Assert.That(dirty, Is.False); } }
public void Can_Verify_Fresh_Entity_Is_Not_Dirty() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = CreateRepository(provider); var userGroup = MockedUserGroup.CreateUserGroup(); repository.Save(userGroup); scope.Complete(); // Act var resolved = repository.Get(userGroup.Id); bool dirty = ((UserGroup)resolved).IsDirty(); // Assert Assert.That(dirty, Is.False); } }
public void Can_Perform_Get_On_UserGroupRepository() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); using (var repository = CreateRepository(unitOfWork)) { var userGroup = MockedUserGroup.CreateUserGroup(); repository.AddOrUpdate(userGroup); unitOfWork.Commit(); // Act var resolved = repository.Get(userGroup.Id); // Assert Assert.That(resolved.Id, Is.EqualTo(userGroup.Id)); //Assert.That(resolved.CreateDate, Is.GreaterThan(DateTime.MinValue)); //Assert.That(resolved.UpdateDate, Is.GreaterThan(DateTime.MinValue)); Assert.That(resolved.Name, Is.EqualTo(userGroup.Name)); Assert.That(resolved.Alias, Is.EqualTo(userGroup.Alias)); Assert.That(resolved.Permissions, Is.EqualTo(userGroup.Permissions)); } }