public void ReturnUserNodesGivenRoleOnLevelOneAndTwoInSameTree() { // Arrange var nodeOnLevelOne = NodeRepository.GetFirstNodeOnLevel(1); var nodeOnLevelTwo = NodeRepository .GetDescendants(nodeOnLevelOne) .First(node => node.Level() == 2); var userPermissionsRepository = new UserPermissionsRepository(Db.Connection); userPermissionsRepository.Add("John Doe", nodeOnLevelOne.Id, "administrator"); userPermissionsRepository.Add("John Doe", nodeOnLevelTwo.Id, "administrator"); // Act var actual = NodeRepository.GetNodesByUser("John Doe"); // Assert actual.Length.ShouldBe(1 + 5 + (5 * 5) + (5 * 5 * 5)); }
public void ReturnRolesOnAGivenAddedToA() { // Arrange var nodeA = nodeRepository.GetNodesOnLevel(1).Single(node => node.Name == "A"); userPermissionsRepository.Add(userId, nodeA.Id, "administrator"); // Act var userPermissions = userPermissionsRepository.GetForNode(nodeA.Id); // Assert userPermissions.Length.ShouldBe(1); userPermissions[0].UserId.ShouldBe(userId); userPermissions[0].Roles.Count.ShouldBe(1); userPermissions[0].Roles[0].Id.ShouldBe("administrator"); userPermissions[0].Roles[0].Name.ShouldBe("Administrator"); userPermissions[0].Roles[0].Operations.Count.ShouldBe(3); userPermissions[0].Roles[0].Operations.Any(operation => operation.Id == "read").ShouldBeTrue(); userPermissions[0].Roles[0].Operations.Any(operation => operation.Id == "write").ShouldBeTrue(); userPermissions[0].Roles[0].Operations.Any(operation => operation.Id == "execute").ShouldBeTrue(); userPermissions[0].Roles[0].InheritedFrom.ShouldBeNull(); }
public void Setup() { db = new Db(); db.SetupTables(); userPermissionsRepository = new UserPermissionsRepository(db.Connection); Seed.Nodes(db); var nodeRepository = new NodeRepository(db.Connection); // Add user "John Doe" with role "Administrator" to a node on first level nodeOnFirstLevel = nodeRepository.GetFirstNodeOnLevel(1); userPermissionsRepository.Add("John Doe", nodeOnFirstLevel.Id, "administrator"); // Get one descendant on each level under the first level node var descendants = nodeRepository.GetDescendants(nodeOnFirstLevel); nodeOnSecondLevel = descendants.First(descendant => descendant.Level() == 2); nodeOnThirdLevel = descendants.First(descendant => descendant.Level() == 3); nodeOnFourthLevel = descendants.First(descendant => descendant.Level() == 4); nodeOnFifthLevel = descendants.First(descendant => descendant.Level() == 5); }