コード例 #1
0
 /**
  *  @covers MicrosoftAzure\Storage\Table\Models\BatchOperations::addInsertOrMergeEntity
  *  @covers MicrosoftAzure\Storage\Table\Models\BatchOperations::addOperation
  *  @covers MicrosoftAzure\Storage\Table\Models\BatchOperations::getOperations
  */
 public function testAddInsertOrMergeEntity()
 {
     // Setup
     $table = 'mytable';
     $entity = new Entity();
     $operations = new BatchOperations();
     // Test
     $operations->addInsertOrMergeEntity($table, $entity);
     // Assert
     $this->assertCount(1, $operations->getOperations());
 }
コード例 #2
0
 /**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::batch
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertEntity
  */
 public function testBatchAllOperationsTogetherWorks()
 {
     // Arrange
     $table = self::$testTable8;
     $partitionKey = '001';
     // Insert a few entities to allow updating them in batch
     $entity1 = new Entity();
     $entity1->setPartitionKey($partitionKey);
     $entity1->setRowKey('batchAllOperationsWorks-' . 1);
     $entity1->addProperty('test', EdmType::BOOLEAN, true);
     $entity1->addProperty('test2', EdmType::STRING, 'value');
     $entity1->addProperty('test3', EdmType::INT32, 3);
     $entity1->addProperty('test4', EdmType::INT64, '12345678901');
     $entity1->addProperty('test5', EdmType::DATETIME, new \DateTime());
     $entity1 = $this->restProxy->insertEntity($table, $entity1)->getEntity();
     $entity2 = new Entity();
     $entity2->setPartitionKey($partitionKey);
     $entity2->setRowKey('batchAllOperationsWorks-' . 2);
     $entity2->addProperty('test', EdmType::BOOLEAN, true);
     $entity2->addProperty('test2', EdmType::STRING, 'value');
     $entity2->addProperty('test3', EdmType::INT32, 3);
     $entity2->addProperty('test4', EdmType::INT64, '12345678901');
     $entity2->addProperty('test5', EdmType::DATETIME, new \DateTime());
     $entity2 = $this->restProxy->insertEntity($table, $entity2)->getEntity();
     $entity3 = new Entity();
     $entity3->setPartitionKey($partitionKey);
     $entity3->setRowKey('batchAllOperationsWorks-' . 3);
     $entity3->addProperty('test', EdmType::BOOLEAN, true);
     $entity3->addProperty('test2', EdmType::STRING, 'value');
     $entity3->addProperty('test3', EdmType::INT32, 3);
     $entity3->addProperty('test4', EdmType::INT64, '12345678901');
     $entity3->addProperty('test5', EdmType::DATETIME, new \DateTime());
     $entity3 = $this->restProxy->insertEntity($table, $entity3)->getEntity();
     $entity4 = new Entity();
     $entity4->setPartitionKey($partitionKey);
     $entity4->setRowKey('batchAllOperationsWorks-' . 4);
     $entity4->addProperty('test', EdmType::BOOLEAN, true);
     $entity4->addProperty('test2', EdmType::STRING, 'value');
     $entity4->addProperty('test3', EdmType::INT32, 3);
     $entity4->addProperty('test4', EdmType::INT64, '12345678901');
     $entity4->addProperty('test5', EdmType::DATETIME, new \DateTime());
     $entity4 = $this->restProxy->insertEntity($table, $entity4)->getEntity();
     // Act
     $batchOperations = new BatchOperations();
     $entity = new Entity();
     $entity->setPartitionKey($partitionKey);
     $entity->setRowKey('batchAllOperationsWorks');
     $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());
     $batchOperations->addInsertEntity($table, $entity);
     $batchOperations->addDeleteEntity($table, $entity1->getPartitionKey(), $entity1->getRowKey(), $entity1->getETag());
     $entity2->addProperty('test3', EdmType::INT32, 5);
     $batchOperations->addUpdateEntity($table, $entity2);
     $entity3->addProperty('test3', EdmType::INT32, 5);
     $batchOperations->addMergeEntity($table, $entity3);
     $entity4->addProperty('test3', EdmType::INT32, 5);
     // Use different behavior in the emulator, as v1.6 does not support this method
     if (!$this->isEmulated()) {
         $batchOperations->addInsertOrReplaceEntity($table, $entity4);
     } else {
         $batchOperations->addUpdateEntity($table, $entity4);
     }
     $entity5 = new Entity();
     $entity5->setPartitionKey($partitionKey);
     $entity5->setRowKey('batchAllOperationsWorks-' . 5);
     $entity5->addProperty('test', EdmType::BOOLEAN, true);
     $entity5->addProperty('test2', EdmType::STRING, 'value');
     $entity5->addProperty('test3', EdmType::INT32, 3);
     $entity5->addProperty('test4', EdmType::INT64, '12345678901');
     $entity5->addProperty('test5', EdmType::DATETIME, new \DateTime());
     // Use different behavior in the emulator, as v1.6 does not support this method
     if ($this->isEmulated()) {
         $batchOperations->addInsertEntity($table, $entity5);
     } else {
         $batchOperations->addInsertOrMergeEntity($table, $entity5);
     }
     $result = $this->restProxy->batch($batchOperations);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertEquals(count($batchOperations->getOperations()), count($result->getEntries()), 'count($result->getEntries())');
     $ents = $result->getEntries();
     $this->assertTrue($ents[0] instanceof InsertEntityResult, '$result->getEntries()->get(0)->getClass()');
     $this->assertTrue(is_string($ents[1]), '$result->getEntries()->get(1)->getClass()');
     $this->assertTrue($ents[2] instanceof UpdateEntityResult, '$result->getEntries()->get(2)->getClass()');
     $this->assertTrue($ents[3] instanceof UpdateEntityResult, '$result->getEntries()->get(3)->getClass()');
     $this->assertTrue($ents[4] instanceof UpdateEntityResult, '$result->getEntries()->get(4)->getClass()');
     if ($this->isEmulated()) {
         $this->assertTrue($ents[5] instanceof InsertEntityResult, '$result->getEntries()->get(5)->getClass()');
     } else {
         $this->assertTrue($ents[5] instanceof UpdateEntityResult, '$result->getEntries()->get(5)->getClass()');
     }
 }
コード例 #3
0
 /**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::batch
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_createBatchRequestBody
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_getOperationContext
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_createOperationsContexts
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_constructPutOrMergeEntityContext
  * @covers MicrosoftAzure\Storage\Table\Internal\MimeReaderWriter::encodeMimeMultipart
  * @covers MicrosoftAzure\Storage\Table\Internal\MimeReaderWriter::decodeMimeMultipart
  * @covers MicrosoftAzure\Storage\Table\Models\BatchResult::create
  * @covers MicrosoftAzure\Storage\Table\Models\BatchResult::_constructResponses
  * @covers MicrosoftAzure\Storage\Table\Models\BatchResult::_compareUsingContentId
  * @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::sendContext
  */
 public function testBatchWithInsertOrMerge()
 {
     $this->skipIfEmulated();
     // Setup
     $name = 'batchwithinsertormerge';
     $this->createTable($name);
     $partitionKey = '123';
     $rowKey = '456';
     $expected = TestResources::getTestEntity($partitionKey, $rowKey);
     $this->restProxy->insertEntity($name, $expected);
     $result = $this->restProxy->queryEntities($name);
     $entities = $result->getEntities();
     $expected = $entities[0];
     $expected->addProperty('CustomerPlace', EdmType::STRING, 'Redmond');
     $operations = new BatchOperations();
     $operations->addInsertOrMergeEntity($name, $expected);
     // Test
     $result = $this->restProxy->batch($operations);
     // Assert
     $entries = $result->getEntries();
     $this->assertNotNull($entries[0]->getETag());
     $result = $this->restProxy->queryEntities($name);
     $entities = $result->getEntities();
     $actual = $entities[0];
     $this->assertEquals($expected->getPartitionKey(), $actual->getPartitionKey());
     $this->assertEquals($expected->getRowKey(), $actual->getRowKey());
     $this->assertCount(count($expected->getProperties()), $actual->getProperties());
 }