/** * @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'); }
/** * Constructs HTTP call context for deleteEntity API. * * @param string $table The name of the table. * @param string $partitionKey The entity partition key. * @param string $rowKey The entity row key. * @param Models\DeleteEntityOptions $options The optional parameters. * * @return HttpCallContext */ private function _constructDeleteEntityContext($table, $partitionKey, $rowKey, $options) { Validate::isString($table, 'table'); Validate::notNullOrEmpty($table, 'table'); Validate::isTrue(!is_null($partitionKey), Resources::NULL_TABLE_KEY_MSG); Validate::isTrue(!is_null($rowKey), Resources::NULL_TABLE_KEY_MSG); $method = Resources::HTTP_DELETE; $headers = array(); $queryParams = array(); $statusCode = Resources::STATUS_NO_CONTENT; $path = $this->_getEntityPath($table, $partitionKey, $rowKey); if (is_null($options)) { $options = new DeleteEntityOptions(); } $etagObj = $options->getETag(); $ETag = !is_null($etagObj); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $this->addOptionalHeader($headers, Resources::IF_MATCH, $ETag ? $etagObj : Resources::ASTERISK); $context = new HttpCallContext(); $context->setHeaders($headers); $context->setMethod($method); $context->setPath($path); $context->setQueryParameters($queryParams); $context->addStatusCode($statusCode); $context->setUri($this->getUri()); $context->setBody(''); return $context; }
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; } }