public void ConstructPatchOperationTest() { PatchOperation operation = PatchOperation.Add(path, "string"); PatchOperationTests.ValidateOperations(operation, PatchOperationType.Add, "string"); DateTime current = DateTime.UtcNow; operation = PatchOperation.Add(path, current); PatchOperationTests.ValidateOperations(operation, PatchOperationType.Add, current); dynamic complexObject = new { a = "complex", b = 12.34, c = true }; operation = PatchOperation.Add(path, complexObject); PatchOperationTests.ValidateOperations(operation, PatchOperationType.Add, complexObject); operation = PatchOperation.Remove(path); PatchOperationTests.ValidateOperations(operation, PatchOperationType.Remove, "value not required"); int[] arrayObject = { 1, 2, 3 }; operation = PatchOperation.Replace(path, arrayObject); PatchOperationTests.ValidateOperations(operation, PatchOperationType.Replace, arrayObject); Guid guid = new Guid(); operation = PatchOperation.Set(path, guid); PatchOperationTests.ValidateOperations(operation, PatchOperationType.Set, guid); }
public async Task CompareRUs(IEnumerable <RGB> rgbList) { try { RGB rgb = rgbList.ElementAt(0); Console.Write("Execute ReplaceItemAsync to update a item [{0}]'s field [/R]... ", rgb.id); ItemResponse <RGB> responseReplace = await this.Container.ReplaceItemAsync( partitionKey : new PartitionKey(rgb.x), id : rgb.id, item : rgb ); Console.Write("Complete! RU Charge for Replace a item [{0}] - {1} RU\n", responseReplace.Resource.id, responseReplace.RequestCharge); Console.Write("Execute PatchItemAsync to update a item [{0}]'s field [/R]... ", rgb.id); ItemResponse <RGB> responsePatch = await this.Container.PatchItemAsync <RGB>( id : rgb.id, partitionKey : new PartitionKey(rgb.x), patchOperations : new[] { PatchOperation.Replace("/R", rgb.R) } ); Console.Write("Complete! RU Charge for Patch a item [{0}] - {1} RU\n", responsePatch.Resource.id, responsePatch.RequestCharge); } catch (Exception e) { throw e; } }
private async Task Validate( ItemRequestOptions requestOptions, Action <ItemResponse <ToDoActivity> > ValidateWrite, Action <ItemResponse <ToDoActivity> > ValidateRead) { ToDoActivity item = ToDoActivity.CreateRandomToDoActivity(); ItemResponse <ToDoActivity> itemResponse = await this.container.CreateItemAsync(item, requestOptions : requestOptions); Assert.AreEqual(HttpStatusCode.Created, itemResponse.StatusCode); ValidateWrite(itemResponse); itemResponse = await this.container.ReadItemAsync <ToDoActivity>(item.id, new PartitionKey(item.status), requestOptions : requestOptions); Assert.AreEqual(HttpStatusCode.OK, itemResponse.StatusCode); ValidateRead(itemResponse); item.cost = 424242.42; itemResponse = await this.container.UpsertItemAsync <ToDoActivity>(item, requestOptions : requestOptions); Assert.AreEqual(HttpStatusCode.OK, itemResponse.StatusCode); ValidateWrite(itemResponse); item.cost = 9000.42; itemResponse = await this.container.ReplaceItemAsync <ToDoActivity>( item, item.id, new PartitionKey(item.status), requestOptions : requestOptions); Assert.AreEqual(HttpStatusCode.OK, itemResponse.StatusCode); ValidateWrite(itemResponse); item.cost = 1000; List <PatchOperation> patch = new List <PatchOperation>() { PatchOperation.Replace("/cost", item.cost) }; itemResponse = await this.containerInternal.PatchItemAsync <ToDoActivity>( item.id, new PartitionKey(item.status), patchOperations : patch, requestOptions : requestOptions); Assert.AreEqual(HttpStatusCode.OK, itemResponse.StatusCode); ValidateWrite(itemResponse); itemResponse = await this.container.DeleteItemAsync <ToDoActivity>( item.id, new PartitionKey(item.status), requestOptions : requestOptions); Assert.AreEqual(HttpStatusCode.NoContent, itemResponse.StatusCode); this.ValidateItemNoContentResponse(itemResponse); }
// </ReplaceItemAsync> // <PatchItemAsync> private static async Task PatchItemAsync(SalesOrder order) { //****************************************************************************************************************** // 1.7 - Patch a item // // Just update a property of an existing item and issue a Patch command //****************************************************************************************************************** Console.WriteLine("\n1.6 - Patching a item using its Id"); ItemResponse <SalesOrder> response = await container.PatchItemAsync <SalesOrder>( id : order.Id, partitionKey : new PartitionKey(order.AccountNumber), patchOperations : new[] { PatchOperation.Replace("/TotalDue", 0) }); SalesOrder updatedSalesOrder = response.Resource; Console.WriteLine($"TotalDue of updated item: {updatedSalesOrder.TotalDue}"); PatchItemRequestOptions patchItemRequestOptions = new PatchItemRequestOptions { FilterPredicate = "from c where (c.TotalDue = 0 OR NOT IS_DEFINED(c.TotalDue))" }; response = await container.PatchItemAsync <SalesOrder>( id : order.Id, partitionKey : new PartitionKey(order.AccountNumber), patchOperations : new[] { PatchOperation.Replace("/ShippedDate", DateTime.UtcNow) }, patchItemRequestOptions); updatedSalesOrder = response.Resource; Console.WriteLine($"\n1.6.2 - Shipped date of updated item: {updatedSalesOrder.ShippedDate}"); IReadOnlyList <PatchOperation> patchOperations = new[] { PatchOperation.Replace("/ShippedDate", DateTime.UtcNow) }; using (Stream stream = Program.ToStream <IReadOnlyList <PatchOperation> >(patchOperations)) { using (ResponseMessage responseMessage = await container.PatchItemStreamAsync( id: order.Id, partitionKey: new PartitionKey(order.AccountNumber), patchOperations: patchOperations)) { // Item stream operations do not throw exceptions for better performance if (responseMessage.IsSuccessStatusCode) { SalesOrder streamResponse = FromStream <SalesOrder>(responseMessage.Content); Console.WriteLine($"\n1.6.3 - Item Patch via stream {streamResponse.Id}"); } else { Console.WriteLine($"Patch item from stream failed. Status code: {responseMessage.StatusCode} Message: {responseMessage.ErrorMessage}"); } } } }
public async Task ClientContentResponseTest() { ToDoActivity item = ToDoActivity.CreateRandomToDoActivity(); ItemResponse <ToDoActivity> itemResponse = await this.containerWithFlag.CreateItemAsync(item); Assert.AreEqual(HttpStatusCode.Created, itemResponse.StatusCode); Assert.IsNotNull(itemResponse); Assert.IsNotNull(itemResponse.Resource); itemResponse = await this.containerWithFlag.ReadItemAsync <ToDoActivity>(item.id, new PartitionKey(item.pk)); Assert.AreEqual(HttpStatusCode.OK, itemResponse.StatusCode); item.cost = 424242.42; itemResponse = await this.containerWithFlag.UpsertItemAsync <ToDoActivity>(item); Assert.AreEqual(HttpStatusCode.OK, itemResponse.StatusCode); Assert.IsNotNull(itemResponse.Resource); item.cost = 9000.42; itemResponse = await this.containerWithFlag.ReplaceItemAsync <ToDoActivity>( item, item.id, new PartitionKey(item.pk)); Assert.AreEqual(HttpStatusCode.OK, itemResponse.StatusCode); Assert.IsNotNull(itemResponse.Resource); ContainerInternal containerInternal = (ContainerInternal)this.containerWithFlag; item.cost = 1000; List <PatchOperation> patch = new List <PatchOperation>() { PatchOperation.Replace("/cost", item.cost) }; itemResponse = await containerInternal.PatchItemAsync <ToDoActivity>( item.id, new PartitionKey(item.pk), patchOperations : patch); Assert.AreEqual(HttpStatusCode.OK, itemResponse.StatusCode); Assert.IsNotNull(itemResponse.Resource); ItemResponse <ToDoActivity> itemResponseWithoutFlag = await this.containerWithoutFlag.CreateItemAsync(item); Assert.AreEqual(HttpStatusCode.Created, itemResponseWithoutFlag.StatusCode); Assert.IsNotNull(itemResponseWithoutFlag); Assert.IsNull(itemResponseWithoutFlag.Resource); }
public async Task ConnectAsync() { using var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_channel.MasterCommunication !.ToString()); using var content = new StringContent(JsonSerializer.Serialize(_channel), Encoding.Default, "application/json"); var message = Policy .Handle <Exception>() .OrResult <HttpResponseMessage>(mess => !mess.IsSuccessStatusCode) .WaitAndRetryForeverAsync(retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (_, __, timeSpan) => _logger.Error( LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.MASTER_SERVER_RETRY), timeSpan.TotalSeconds) ).ExecuteAsync(() => client.PostAsync(new Uri($"{client.BaseAddress}api/channel"), content)); var result = JsonSerializer.Deserialize <ConnectionInfo>(await(await message.ConfigureAwait(false)).Content.ReadAsStringAsync().ConfigureAwait(false), new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); _token = result?.Token; _lastUpdateToken = SystemTime.Now(); _logger.Debug(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.REGISTRED_ON_MASTER)); _channel.ChannelId = result?.ChannelInfo?.ChannelId ?? 0; await Policy .HandleResult <HttpStatusCode>(ping => ping == HttpStatusCode.OK) .WaitAndRetryForeverAsync(retryAttempt => TimeSpan.FromSeconds(1), (_, __, timeSpan) => _logger.Verbose( LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.MASTER_SERVER_PING)) ).ExecuteAsync(() => { var jsonPatch = new JsonPatch(PatchOperation.Replace(Json.Pointer.JsonPointer.Parse("/LastPing"), JsonDocument.Parse(JsonSerializer.Serialize(SystemTime.Now())).RootElement)); return(PatchAsync(_channel.ChannelId, jsonPatch)); }).ConfigureAwait(false); _logger.Error( LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.MASTER_SERVER_PING_FAILED)); Environment.Exit(0); }
public override async Task ExecuteAsync(SetMaintenancePacket setMaintenancePacket, ClientSession session) { var servers = (await _channelHttpClient.GetChannelsAsync().ConfigureAwait(false)) ?.Where(c => c.Type == ServerType.WorldServer).ToList(); var patch = new JsonPatch(PatchOperation.Replace(JsonPointer.Create <ChannelInfo>(o => o.IsMaintenance), setMaintenancePacket.MaintenanceMode.AsJsonElement())); if (setMaintenancePacket.IsGlobal == false) { await _channelHttpClient.PatchAsync(_channel.ChannelId, patch); } else { foreach (var server in servers ?? new List <ChannelInfo>()) { await _channelHttpClient.PatchAsync(server.Id, patch); } } }
public async Task PatchColorRedAsync(IEnumerable <RGB> rgbList) { double totalRUs = 0; Console.WriteLine("Start to patch color red... "); foreach (var rgb in rgbList) { ItemResponse <RGB> response = await this.Container.PatchItemAsync <RGB>( id : rgb.id, partitionKey : new PartitionKey(rgb.x), patchOperations : new[] { PatchOperation.Replace("/R", rgb.R) } ); RGB updated = response.Resource; Console.WriteLine("RU Charge for Patching Item by Id [{0}] - {1} RU", updated.id, response.RequestCharge); totalRUs += response.RequestCharge; } Console.WriteLine("Finished to patch color red... "); Console.WriteLine("Total Request Units Charge for Patching Items to replace /R - {0} RU", totalRUs); }
public async Task BatchCreateAndPatchAsync() { TestDoc testDoc = BatchTestBase.PopulateTestDoc(this.PartitionKey1); List <PatchOperation> patchOperations = new List <PatchOperation>() { PatchOperation.Replace("/Cost", testDoc.Cost + 1) }; BatchCore batch = (BatchCore) new BatchCore((ContainerInlineCore)BatchTestBase.JsonContainer, BatchTestBase.GetPartitionKey(this.PartitionKey1)) .CreateItem(testDoc); batch = (BatchCore)batch.PatchItem(testDoc.Id, patchOperations); TransactionalBatchResponse batchResponse = await batch.ExecuteAsync(); BatchSinglePartitionKeyTests.VerifyBatchProcessed(batchResponse, numberOfOperations: 2); Assert.AreEqual(HttpStatusCode.Created, batchResponse[0].StatusCode); Assert.AreEqual(HttpStatusCode.OK, batchResponse[1].StatusCode); testDoc.Cost = testDoc.Cost + 1; await BatchTestBase.VerifyByReadAsync(BatchTestBase.JsonContainer, testDoc, isStream : false, isSchematized : false, useEpk : false); }
public override async Task ExecuteAsync(PstClientPacket pstClientPacket, ClientSession clientSession) { var isCopy = pstClientPacket.Type == 2; var mail = await _mailHttpClient.GetGiftAsync(pstClientPacket.Id, clientSession.Character.VisualId, isCopy).ConfigureAwait(false); switch (pstClientPacket.ActionType) { case 3: if (mail == null) { return; } var patch = new JsonPatch(PatchOperation.Replace(JsonPointer.Create <MailDto>(o => o.IsOpened), true.AsJsonElement())); await _mailHttpClient.ViewGiftAsync(mail.MailDto.MailId, patch).ConfigureAwait(false); await clientSession.SendPacketAsync(mail.GeneratePostMessage(pstClientPacket.Type)).ConfigureAwait(false); break; case 2: if (mail == null) { return; } await _mailHttpClient.DeleteGiftAsync(pstClientPacket.Id, clientSession.Character.VisualId, isCopy).ConfigureAwait(false); await clientSession.SendPacketAsync( clientSession.Character.GenerateSay( GameLanguage.Instance.GetMessageFromKey(LanguageKey.MAIL_DELETED, clientSession.Account.Language), SayColorType.Purple)).ConfigureAwait(false); break; case 1: if (string.IsNullOrEmpty(pstClientPacket.Text) || string.IsNullOrEmpty(pstClientPacket.Title)) { return; } var dest = await _characterDao.FirstOrDefaultAsync(s => s.Name == pstClientPacket.ReceiverName).ConfigureAwait(false); if (dest != null) { await _mailHttpClient.SendMessageAsync(clientSession.Character, dest.CharacterId, pstClientPacket.Title, pstClientPacket.Text).ConfigureAwait(false); await clientSession.SendPacketAsync(clientSession.Character.GenerateSay( GameLanguage.Instance.GetMessageFromKey( LanguageKey.MAILED, clientSession.Account.Language), SayColorType.Yellow)).ConfigureAwait(false); } else { await clientSession.SendPacketAsync( clientSession.Character.GenerateSay( GameLanguage.Instance.GetMessageFromKey(LanguageKey.USER_NOT_FOUND, clientSession.Account.Language), SayColorType.Yellow)).ConfigureAwait(false); } break; default: return; } }
public async Task PointOperationDiagnostic(bool disableDiagnostics) { ItemRequestOptions requestOptions = new ItemRequestOptions(); if (disableDiagnostics) { requestOptions.DiagnosticContextFactory = () => EmptyCosmosDiagnosticsContext.Singleton; } else { // Add 10 seconds to ensure CPU history is recorded await Task.Delay(TimeSpan.FromSeconds(10)); } //Checking point operation diagnostics on typed operations ToDoActivity testItem = ToDoActivity.CreateRandomToDoActivity(); ItemResponse <ToDoActivity> createResponse = await this.Container.CreateItemAsync <ToDoActivity>( item : testItem, requestOptions : requestOptions); CosmosDiagnosticsTests.VerifyPointDiagnostics( createResponse.Diagnostics, disableDiagnostics); ItemResponse <ToDoActivity> readResponse = await this.Container.ReadItemAsync <ToDoActivity>( id : testItem.id, partitionKey : new PartitionKey(testItem.status), requestOptions); CosmosDiagnosticsTests.VerifyPointDiagnostics( readResponse.Diagnostics, disableDiagnostics); testItem.description = "NewDescription"; ItemResponse <ToDoActivity> replaceResponse = await this.Container.ReplaceItemAsync <ToDoActivity>( item : testItem, id : testItem.id, partitionKey : new PartitionKey(testItem.status), requestOptions : requestOptions); Assert.AreEqual(replaceResponse.Resource.description, "NewDescription"); CosmosDiagnosticsTests.VerifyPointDiagnostics( replaceResponse.Diagnostics, disableDiagnostics); testItem.description = "PatchedDescription"; ContainerInternal containerInternal = (ContainerInternal)this.Container; List <PatchOperation> patch = new List <PatchOperation>() { PatchOperation.Replace("/description", testItem.description) }; ItemResponse <ToDoActivity> patchResponse = await containerInternal.PatchItemAsync <ToDoActivity>( id : testItem.id, partitionKey : new PartitionKey(testItem.status), patchOperations : patch, requestOptions : requestOptions); Assert.AreEqual(patchResponse.Resource.description, "PatchedDescription"); CosmosDiagnosticsTests.VerifyPointDiagnostics( patchResponse.Diagnostics, disableDiagnostics); ItemResponse <ToDoActivity> deleteResponse = await this.Container.DeleteItemAsync <ToDoActivity>( partitionKey : new Cosmos.PartitionKey(testItem.status), id : testItem.id, requestOptions : requestOptions); Assert.IsNotNull(deleteResponse); CosmosDiagnosticsTests.VerifyPointDiagnostics( deleteResponse.Diagnostics, disableDiagnostics); //Checking point operation diagnostics on stream operations ResponseMessage createStreamResponse = await this.Container.CreateItemStreamAsync( partitionKey : new PartitionKey(testItem.status), streamPayload : TestCommon.SerializerCore.ToStream <ToDoActivity>(testItem), requestOptions : requestOptions); CosmosDiagnosticsTests.VerifyPointDiagnostics( createStreamResponse.Diagnostics, disableDiagnostics); ResponseMessage readStreamResponse = await this.Container.ReadItemStreamAsync( id : testItem.id, partitionKey : new PartitionKey(testItem.status), requestOptions : requestOptions); CosmosDiagnosticsTests.VerifyPointDiagnostics( readStreamResponse.Diagnostics, disableDiagnostics); ResponseMessage replaceStreamResponse = await this.Container.ReplaceItemStreamAsync( streamPayload : TestCommon.SerializerCore.ToStream <ToDoActivity>(testItem), id : testItem.id, partitionKey : new PartitionKey(testItem.status), requestOptions : requestOptions); CosmosDiagnosticsTests.VerifyPointDiagnostics( replaceStreamResponse.Diagnostics, disableDiagnostics); ResponseMessage patchStreamResponse = await containerInternal.PatchItemStreamAsync( id : testItem.id, partitionKey : new PartitionKey(testItem.status), patchOperations : patch, requestOptions : requestOptions); CosmosDiagnosticsTests.VerifyPointDiagnostics( patchStreamResponse.Diagnostics, disableDiagnostics); ResponseMessage deleteStreamResponse = await this.Container.DeleteItemStreamAsync( id : testItem.id, partitionKey : new PartitionKey(testItem.status), requestOptions : requestOptions); CosmosDiagnosticsTests.VerifyPointDiagnostics( deleteStreamResponse.Diagnostics, disableDiagnostics); // Ensure diagnostics are set even on failed operations testItem.description = new string('x', Microsoft.Azure.Documents.Constants.MaxResourceSizeInBytes + 1); ResponseMessage createTooBigStreamResponse = await this.Container.CreateItemStreamAsync( partitionKey : new PartitionKey(testItem.status), streamPayload : TestCommon.SerializerCore.ToStream <ToDoActivity>(testItem), requestOptions : requestOptions); Assert.IsFalse(createTooBigStreamResponse.IsSuccessStatusCode); CosmosDiagnosticsTests.VerifyPointDiagnostics( createTooBigStreamResponse.Diagnostics, disableDiagnostics); }
public static PatchOperation Replace(string path, JsonElementProxy value) => PatchOperation.Replace(JsonPointer.Parse(path), value);
private async Task ValidateItemStream( ItemRequestOptions requestOptions, Action <ResponseMessage> ValidateWrite, Action <ResponseMessage> ValidateRead) { ToDoActivity item = ToDoActivity.CreateRandomToDoActivity(); using (ResponseMessage responseMessage = await this.container.CreateItemStreamAsync( TestCommon.SerializerCore.ToStream(item), new PartitionKey(item.status), requestOptions: requestOptions)) { Assert.AreEqual(HttpStatusCode.Created, responseMessage.StatusCode); ValidateWrite(responseMessage); } using (ResponseMessage responseMessage = await this.container.ReadItemStreamAsync( item.id, new PartitionKey(item.status), requestOptions: requestOptions)) { Assert.AreEqual(HttpStatusCode.OK, responseMessage.StatusCode); ValidateRead(responseMessage); } item.cost = 424242.42; using (ResponseMessage responseMessage = await this.container.UpsertItemStreamAsync( TestCommon.SerializerCore.ToStream(item), new PartitionKey(item.status), requestOptions: requestOptions)) { Assert.AreEqual(HttpStatusCode.OK, responseMessage.StatusCode); ValidateWrite(responseMessage); } item.cost = 9000.42; using (ResponseMessage responseMessage = await this.container.ReplaceItemStreamAsync( TestCommon.SerializerCore.ToStream(item), item.id, new PartitionKey(item.status), requestOptions: requestOptions)) { Assert.AreEqual(HttpStatusCode.OK, responseMessage.StatusCode); ValidateWrite(responseMessage); } item.cost = 1000; List <PatchOperation> patch = new List <PatchOperation>() { PatchOperation.Replace("/cost", item.cost) }; using (ResponseMessage responseMessage = await this.containerInternal.PatchItemStreamAsync( item.id, new PartitionKey(item.status), patchOperations: patch, requestOptions: requestOptions)) { Assert.AreEqual(HttpStatusCode.OK, responseMessage.StatusCode); ValidateWrite(responseMessage); } using (ResponseMessage responseMessage = await this.container.DeleteItemStreamAsync( item.id, new PartitionKey(item.status), requestOptions: requestOptions)) { Assert.AreEqual(HttpStatusCode.NoContent, responseMessage.StatusCode); this.ValidateItemStreamNoContentResponse(responseMessage); } }
private async Task <TransactionalBatchResponse> RunCrudAsync(bool isStream, bool isSchematized, bool useEpk, Container container) { TransactionalBatchRequestOptions batchOptions = null; if (isSchematized) { await this.CreateSchematizedTestDocsAsync(container); batchOptions = BatchTestBase.GetUpdatedBatchRequestOptions(batchOptions, isSchematized, useEpk, this.PartitionKey1); } else { await this.CreateJsonTestDocsAsync(container); } TestDoc testDocToCreate = BatchTestBase.PopulateTestDoc(this.PartitionKey1); TestDoc testDocToUpsert = BatchTestBase.PopulateTestDoc(this.PartitionKey1); TestDoc anotherTestDocToUpsert = this.GetTestDocCopy(this.TestDocPk1ExistingA); anotherTestDocToUpsert.Cost++; TestDoc testDocToReplace = this.GetTestDocCopy(this.TestDocPk1ExistingB); testDocToReplace.Cost++; TestDoc testDocToPatch = this.GetTestDocCopy(this.TestDocPk1ExistingC); List <PatchOperation> patchOperations = new List <PatchOperation>() { PatchOperation.Replace("/Cost", testDocToPatch.Cost + 1) }; // We run CRUD operations where all are expected to return HTTP 2xx. TransactionalBatchResponse batchResponse; BatchCore batch; if (!isStream) { batch = (BatchCore) new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1)) .CreateItem(testDocToCreate) .ReadItem(this.TestDocPk1ExistingC.Id) .ReplaceItem(testDocToReplace.Id, testDocToReplace) .UpsertItem(testDocToUpsert) .UpsertItem(anotherTestDocToUpsert) .DeleteItem(this.TestDocPk1ExistingD.Id); batch = (BatchCore)batch.PatchItem(testDocToPatch.Id, patchOperations); } else { batch = (BatchCore) new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1)) .CreateItemStream( BatchTestBase.TestDocToStream(testDocToCreate, isSchematized), BatchTestBase.GetBatchItemRequestOptions(testDocToCreate, isSchematized)) .ReadItem( BatchTestBase.GetId(this.TestDocPk1ExistingC, isSchematized), BatchTestBase.GetBatchItemRequestOptions(this.TestDocPk1ExistingC, isSchematized)) .ReplaceItemStream( BatchTestBase.GetId(testDocToReplace, isSchematized), BatchTestBase.TestDocToStream(testDocToReplace, isSchematized), BatchTestBase.GetBatchItemRequestOptions(testDocToReplace, isSchematized)) .UpsertItemStream( BatchTestBase.TestDocToStream(testDocToUpsert, isSchematized), BatchTestBase.GetBatchItemRequestOptions(testDocToUpsert, isSchematized)) .UpsertItemStream( BatchTestBase.TestDocToStream(anotherTestDocToUpsert, isSchematized), BatchTestBase.GetBatchItemRequestOptions(anotherTestDocToUpsert, isSchematized)) .DeleteItem( BatchTestBase.GetId(this.TestDocPk1ExistingD, isSchematized), BatchTestBase.GetBatchItemRequestOptions(this.TestDocPk1ExistingD, isSchematized)); } batchResponse = await batch.ExecuteAsync(batchOptions); BatchSinglePartitionKeyTests.VerifyBatchProcessed(batchResponse, numberOfOperations: isStream ? 6 :7); Assert.AreEqual(HttpStatusCode.Created, batchResponse[0].StatusCode); Assert.AreEqual(HttpStatusCode.OK, batchResponse[1].StatusCode); Assert.AreEqual(HttpStatusCode.OK, batchResponse[2].StatusCode); Assert.AreEqual(HttpStatusCode.Created, batchResponse[3].StatusCode); Assert.AreEqual(HttpStatusCode.OK, batchResponse[4].StatusCode); Assert.AreEqual(HttpStatusCode.NoContent, batchResponse[5].StatusCode); if (!isStream) { Assert.AreEqual(this.TestDocPk1ExistingC, batchResponse.GetOperationResultAtIndex <TestDoc>(1).Resource); Assert.AreEqual(HttpStatusCode.OK, batchResponse[6].StatusCode); testDocToPatch.Cost = testDocToPatch.Cost + 1; await BatchTestBase.VerifyByReadAsync(container, testDocToPatch, isStream, isSchematized, useEpk); } else { Assert.AreEqual(this.TestDocPk1ExistingC, BatchTestBase.StreamToTestDoc(batchResponse[1].ResourceStream, isSchematized)); } await BatchTestBase.VerifyByReadAsync(container, testDocToCreate, isStream, isSchematized, useEpk); await BatchTestBase.VerifyByReadAsync(container, testDocToReplace, isStream, isSchematized, useEpk); await BatchTestBase.VerifyByReadAsync(container, testDocToUpsert, isStream, isSchematized, useEpk); await BatchTestBase.VerifyByReadAsync(container, anotherTestDocToUpsert, isStream, isSchematized, useEpk); await BatchTestBase.VerifyNotFoundAsync(container, this.TestDocPk1ExistingD, isSchematized, useEpk); return(batchResponse); }