/**
  *  @covers MicrosoftAzure\Storage\Table\Models\BatchOperations::addUpdateEntity
  *  @covers MicrosoftAzure\Storage\Table\Models\BatchOperations::addOperation
  *  @covers MicrosoftAzure\Storage\Table\Models\BatchOperations::getOperations
  */
 public function testAddUpdateEntity()
 {
     // Setup
     $table = 'mytable';
     $entity = new Entity();
     $operations = new BatchOperations();
     // Test
     $operations->addUpdateEntity($table, $entity);
     // Assert
     $this->assertCount(1, $operations->getOperations());
 }
 /**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::batch
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertEntity
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::updateEntity
  */
 public function testBatchNegativeWorks()
 {
     // Arrange
     $table = self::$testTable8;
     $partitionKey = '001';
     // Insert an entity the modify it outside of the batch
     $entity1 = new Entity();
     $entity1->setPartitionKey($partitionKey);
     $entity1->setRowKey('batchNegativeWorks1');
     $entity1->addProperty('test', EdmType::INT32, 1);
     $entity2 = new Entity();
     $entity2->setPartitionKey($partitionKey);
     $entity2->setRowKey('batchNegativeWorks2');
     $entity2->addProperty('test', EdmType::INT32, 2);
     $entity3 = new Entity();
     $entity3->setPartitionKey($partitionKey);
     $entity3->setRowKey('batchNegativeWorks3');
     $entity3->addProperty('test', EdmType::INT32, 3);
     $entity1 = $this->restProxy->insertEntity($table, $entity1)->getEntity();
     $entity2 = $this->restProxy->insertEntity($table, $entity2)->getEntity();
     $entity2->addProperty('test', EdmType::INT32, -2);
     $this->restProxy->updateEntity($table, $entity2);
     // Act
     $batchOperations = new BatchOperations();
     // The $entity1 still has the original etag from the first submit,
     // so this update should fail, because another update was already made.
     $entity1->addProperty('test', EdmType::INT32, 3);
     $batchOperations->addDeleteEntity($table, $entity1->getPartitionKey(), $entity1->getRowKey(), $entity1->getETag());
     $batchOperations->addUpdateEntity($table, $entity2);
     $batchOperations->addInsertEntity($table, $entity3);
     $result = $this->restProxy->batch($batchOperations);
     // Assert
     $this->assertNotNull($result, '$result');
     $entries = $result->getEntries();
     $this->assertEquals(1, count($entries), 'count($result->getEntries())');
     $this->assertNotNull($entries[0], 'First $result should not be null');
     $this->assertTrue($entries[0] instanceof BatchError, 'First $result type');
     $error = $entries[0];
     $this->assertEquals(412, $error->getError()->getCode(), 'First $result status code');
 }
 /**
  * @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 testBatchWithDifferentPKFail()
 {
     // Setup
     $name = 'batchwithwithdifferentpkfail';
     $this->createTable($name);
     $partitionKey = '123';
     $rk1 = '456';
     $rk3 = '458';
     $delete = TestResources::getTestEntity($partitionKey, $rk1);
     $update = TestResources::getTestEntity($partitionKey, $rk3);
     $this->restProxy->insertEntity($name, $delete);
     $this->restProxy->insertEntity($name, $update);
     $result = $this->restProxy->queryEntities($name);
     $entities = $result->getEntities();
     $delete = $entities[0];
     $update = $entities[1];
     $update->addProperty('CustomerPlace', EdmType::STRING, 'Redmond');
     $operations = new BatchOperations();
     $operations->addUpdateEntity($name, $update);
     $operations->addDeleteEntity($name, '125', $delete->getRowKey(), $delete->getETag());
     // Test
     $result = $this->restProxy->batch($operations);
     // Assert
     $this->assertTrue(true);
 }