コード例 #1
0
 public function testGetsGroupById()
 {
     $group1 = new ResourceGroup(1, 'group1');
     $group1a = new ResourceGroup(2, 'group1a', 1);
     $group1a1 = new ResourceGroup(3, 'group1a1', 2);
     $resourceGroupTree = new ResourceGroupTree();
     $resourceGroupTree->AddGroup($group1);
     $resourceGroupTree->AddGroup($group1a);
     $resourceGroupTree->AddGroup($group1a1);
     $resourceGroupTree->AddAssignment(new ResourceGroupAssignment($group1a1->id, 'resource1', 1, null, 1, ResourceStatus::AVAILABLE, null));
     $resourceGroupTree->AddAssignment(new ResourceGroupAssignment($group1a1->id, 'resource2', 2, null, 1, ResourceStatus::AVAILABLE, null));
     $resourceGroupTree->AddAssignment(new ResourceGroupAssignment($group1a->id, 'resource3', 3, null, 1, ResourceStatus::AVAILABLE, null));
     $resourceGroupTree->AddAssignment(new ResourceGroupAssignment($group1->id, 'resource4', 4, null, 1, ResourceStatus::AVAILABLE, null));
     $this->assertEquals($group1, $resourceGroupTree->GetGroup(1));
     $this->assertEquals($group1a, $resourceGroupTree->GetGroup(2));
     $this->assertEquals($group1a1, $resourceGroupTree->GetGroup(3));
 }
コード例 #2
0
 /**
  * @param $groups ResourceGroup[]
  * @param $assignments ResourceGroupAssignment[]
  * @param $resourceFilter IResourceFilter|null
  * @return ResourceGroupTree
  */
 private function BuildResourceGroupTree($groups, $assignments, $resourceFilter)
 {
     $tree = new ResourceGroupTree();
     foreach ($groups as $g) {
         $tree->AddGroup($g);
     }
     foreach ($assignments as $assignment) {
         if ($resourceFilter == null || $resourceFilter->ShouldInclude($assignment)) {
             $tree->AddAssignment($assignment);
         }
     }
     return $tree;
 }