public function LoadResourceType($resourceTypeId) { $resourceType = null; $reader = ServiceLocator::GetDatabase()->Query(new GetResourceTypeCommand($resourceTypeId)); if ($row = $reader->GetRow()) { $resourceType = new ResourceType($row[ColumnNames::RESOURCE_TYPE_ID], $row[ColumnNames::RESOURCE_TYPE_NAME], $row[ColumnNames::RESOURCE_TYPE_DESCRIPTION]); $getAttributes = new GetAttributeValuesCommand($resourceTypeId, CustomAttributeCategory::RESOURCE_TYPE); $attributeReader = ServiceLocator::GetDatabase()->Query($getAttributes); while ($attributeRow = $attributeReader->GetRow()) { $resourceType->WithAttribute(new AttributeValue($attributeRow[ColumnNames::ATTRIBUTE_ID], $attributeRow[ColumnNames::ATTRIBUTE_VALUE])); } $attributeReader->Free(); } $reader->Free(); return $resourceType; }
public function testUpdatesResourceType() { $unchanged = new AttributeValue(1, 'value'); $toChange = new AttributeValue(2, 'value'); $toAdd = new AttributeValue(3, 'value'); $id = 11; $type = new ResourceType($id, 'name', 'desc'); $type->WithAttribute($unchanged); $type->WithAttribute(new AttributeValue(100, 'should be removed')); $type->WithAttribute(new AttributeValue(2, 'new value')); $attributes = array($unchanged, $toChange, $toAdd); $type->ChangeAttributes($attributes); $this->repository->UpdateResourceType($type); $addNewCommand = new AddAttributeValueCommand($toAdd->AttributeId, $toAdd->Value, $id, CustomAttributeCategory::RESOURCE_TYPE); $removeOldCommand = new RemoveAttributeValueCommand(100, $id); $removeUpdated = new RemoveAttributeValueCommand($toChange->AttributeId, $id); $addUpdated = new AddAttributeValueCommand($toChange->AttributeId, $toChange->Value, $id, CustomAttributeCategory::RESOURCE_TYPE); $expectedCommand = new UpdateResourceTypeCommand($type->Id(), $type->Name(), $type->Description()); $this->assertEquals($expectedCommand, $this->db->_Commands[0]); $this->assertEquals($removeOldCommand, $this->db->_Commands[1]); $this->assertEquals($removeUpdated, $this->db->_Commands[2], "need to remove before adding to make sure changed values are not immediately deleted"); $this->assertEquals($addUpdated, $this->db->_Commands[3]); $this->assertEquals($addNewCommand, $this->db->_Commands[4]); }