/** * @covers MicrosoftAzure\Storage\Table\Models\DeleteEntityOptions::setETag * @covers MicrosoftAzure\Storage\Table\Models\DeleteEntityOptions::getETag */ public function testSetETag() { // Setup $options = new DeleteEntityOptions(); $ETag = 'etag value'; // Test $options->setETag($ETag); // Assert $this->assertEquals($ETag, $options->getETag()); }
/** * @covers MicrosoftAzure\Storage\Table\TableRestProxy::deleteEntity * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertEntity */ public function testDeleteEntityWithETagWorks() { // Arrange $entity = new Entity(); $entity->setPartitionKey('001'); $entity->setRowKey('deleteEntityWithETagWorks'); $entity->addProperty('test', EdmType::BOOLEAN, true); $entity->addProperty('test2', EdmType::STRING, 'value'); $entity->addProperty('test3', EdmType::INT32, 3); $entity->addProperty('test4', EdmType::INT64, '12345678901'); $entity->addProperty('test5', EdmType::DATETIME, new \DateTime()); // Act $result = $this->restProxy->insertEntity(self::$testTable2, $entity); $deo = new DeleteEntityOptions(); $deo->setETag($result->getEntity()->getETag()); $this->restProxy->deleteEntity(self::$testTable2, $result->getEntity()->getPartitionKey(), $result->getEntity()->getRowKey(), $deo); // Assert $this->assertTrue(true, 'expect no errors'); }
/** * Creates contexts for batch operations. * * @param array $operations The batch operations array. * * @return array * * @throws \InvalidArgumentException */ private function _createOperationsContexts($operations) { $contexts = array(); foreach ($operations as $operation) { $context = null; $type = $operation->getType(); switch ($type) { case BatchOperationType::INSERT_ENTITY_OPERATION: case BatchOperationType::UPDATE_ENTITY_OPERATION: case BatchOperationType::MERGE_ENTITY_OPERATION: case BatchOperationType::INSERT_REPLACE_ENTITY_OPERATION: case BatchOperationType::INSERT_MERGE_ENTITY_OPERATION: $table = $operation->getParameter(BatchOperationParameterName::BP_TABLE); $entity = $operation->getParameter(BatchOperationParameterName::BP_ENTITY); $context = $this->_getOperationContext($table, $entity, $type); break; case BatchOperationType::DELETE_ENTITY_OPERATION: $table = $operation->getParameter(BatchOperationParameterName::BP_TABLE); $partitionKey = $operation->getParameter(BatchOperationParameterName::BP_PARTITION_KEY); $rowKey = $operation->getParameter(BatchOperationParameterName::BP_ROW_KEY); $etag = $operation->getParameter(BatchOperationParameterName::BP_ETAG); $options = new DeleteEntityOptions(); $options->setETag($etag); $context = $this->_constructDeleteEntityContext($table, $partitionKey, $rowKey, $options); break; default: throw new \InvalidArgumentException(); } $contexts[] = $context; } return $contexts; }
public function testCheckDeleteEntityOptions() { $options = new DeleteEntityOptions(); $etag = 'foo'; $this->assertNull($options->getETag(), 'Default DeleteEntityOptions->getETag'); $options->setETag($etag); $this->assertEquals($etag, $options->getETag(), 'Set DeleteEntityOptions->getETag'); }
/** * @covers MicrosoftAzure\Storage\Table\TableRestProxy::deleteEntity * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertEntity * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertOrMergeEntity * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertOrReplaceEntity * @covers MicrosoftAzure\Storage\Table\TableRestProxy::mergeEntity * @covers MicrosoftAzure\Storage\Table\TableRestProxy::updateEntity */ private function executeCrudMethod($table, $targetEnt, $opType, $concurType, $options) { switch ($opType) { case OpType::DELETE_ENTITY: if (is_null($options) && $concurType != ConcurType::KEY_MATCH_ETAG_MISMATCH) { $this->restProxy->deleteEntity($table, $targetEnt->getPartitionKey(), $targetEnt->getRowKey()); } else { $delOptions = new DeleteEntityOptions(); $delOptions->setETag($targetEnt->getETag()); $this->restProxy->deleteEntity($table, $targetEnt->getPartitionKey(), $targetEnt->getRowKey(), $delOptions); } break; case OpType::INSERT_ENTITY: if (is_null($options)) { $this->restProxy->insertEntity($table, $targetEnt); } else { $this->restProxy->insertEntity($table, $targetEnt, $options); } break; case OpType::INSERT_OR_MERGE_ENTITY: if (is_null($options)) { $this->restProxy->insertOrMergeEntity($table, $targetEnt); } else { $this->restProxy->insertOrMergeEntity($table, $targetEnt, $options); } break; case OpType::INSERT_OR_REPLACE_ENTITY: if (is_null($options)) { $this->restProxy->insertOrReplaceEntity($table, $targetEnt); } else { $this->restProxy->insertOrReplaceEntity($table, $targetEnt, $options); } break; case OpType::MERGE_ENTITY: if (is_null($options)) { $this->restProxy->mergeEntity($table, $targetEnt); } else { $this->restProxy->mergeEntity($table, $targetEnt, $options); } break; case OpType::UPDATE_ENTITY: if (is_null($options)) { $this->restProxy->updateEntity($table, $targetEnt); } else { $this->restProxy->updateEntity($table, $targetEnt, $options); } break; } }