From 6b9d4a926ed17ebfed0dc002e0304bd03504c60d Mon Sep 17 00:00:00 2001 From: Elizabeth Okerio Date: Thu, 27 Apr 2023 13:37:10 +0300 Subject: [PATCH] update based on review comments --- .../Tests/BulkUpdateE2ETests.cs | 77 ++++++------------- 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/BulkUpdateE2ETests.cs b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/BulkUpdateE2ETests.cs index 35fb67b0ba..956465d846 100644 --- a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/BulkUpdateE2ETests.cs +++ b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/BulkUpdateE2ETests.cs @@ -10,6 +10,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Xml; using AstoriaUnitTests.Tests; @@ -125,7 +126,7 @@ public void CallingBulkUpdateRequest_WithNullArguments_ShouldThrowAnException() } [Fact] - public async Task CallingBulkUpdateAsync_WithNullArguments_ShouldThrowAnExceptionAsync() + public async Task CallingBulkUpdateAsync_WithNullArguments_ShouldThrowAnException() { await Assert.ThrowsAsync(async () => await this.context.BulkUpdateAsync(null)); } @@ -171,6 +172,29 @@ public void BulkUpdateAnEntry_WithOneLevelOfNesting_ReturnsOne_OperationResponse Assert.Equal(1001, returnedCar.ID); } + [Fact] + public async Task BulkUpdateAsync_ShouldThrowExceptions_RaisedDuringSeriliazation() + { + var expectedResponse = "{\"@context\":\"http://localhost:8000/$metadata#Persons/$delta\",\"value\":[{\"ID\":100,\"Name\":\"Bing\"}]}"; + + SetupContextWithRequestPipelineForSaving( + this.context, + expectedResponse); + + var person = new Person + { + ID = 100, + Name = "Bing", + }; + + this.context.AttachTo("Persons", person); + + var entitydesc = this.context.Entities[0] as EntityDescriptor; + entitydesc.Entity = null; + + await Assert.ThrowsAsync(() => this.context.BulkUpdateAsync(person)); + } + [Fact] public void HandleResponse_Of_AnInvalidResponse_ThrowsException() { @@ -404,57 +428,6 @@ public async Task BulkUpdateAsyncTwoTopLevelObjects_WithTheSameNestedObject_Dese Assert.Equal(carTargetEntity, car2TargetEntity); } - [Fact] - public async Task NullTopLevelObjects_ShouldThrowException() - { - var expectedResponse = "{\"@context\":\"http://localhost:8000/$metadata#Persons/$delta\",\"value\":[{\"ID\":100,\"Name\":\"Bing\",\"Cars@delta\":[{\"@id\":\"http://localhost:8000/Cars(1001)\"}]},{\"ID\":200,\"Name\":\"Edge\",\"Cars@delta\":[{\"@id\":\"http://localhost:8000/Cars(1001)\"}]}]}"; - - SetupContextWithRequestPipelineForSaving( - this.context, - expectedResponse); - - var person = new Person - { - ID = 100, - Name = "Bing", - }; - - var person2 = new Person - { - ID = 200, - Name = "Edge" - }; - - var car = new Car - { - ID = 1002, - Name = "CarA" - }; - - this.context.AttachTo("Persons", person); - this.context.AttachTo("Persons", person2); - this.context.AttachTo("Cars", car); - - this.context.AddLink(person, "Cars", car); - this.context.AddLink(person2, "Cars", car); - - DataServiceResponse response = await this.context.BulkUpdateAsync(person, person2); - - var personOperationResponse = response.First() as ChangeOperationResponse; - var person1 = (personOperationResponse.Descriptor as EntityDescriptor).Entity as Person; - var personcarOperationResponse = personOperationResponse.NestedResponses.FirstOrDefault() as ChangeOperationResponse; - var carTargetEntity = (personcarOperationResponse.Descriptor as LinkDescriptor).Target as Car; - var person2OperationResponse = response.Last() as ChangeOperationResponse; - var person2Response = (person2OperationResponse.Descriptor as EntityDescriptor).Entity as Person; - var person2carOperationResponse = personOperationResponse.NestedResponses.FirstOrDefault() as ChangeOperationResponse; - var car2TargetEntity = (person2carOperationResponse.Descriptor as LinkDescriptor).Target as Car; - - Assert.Equal(2, response.Count()); - Assert.Equal("Bing", person1.Name); - Assert.Equal("Edge", person2Response.Name); - Assert.Equal(carTargetEntity, car2TargetEntity); - } - [Fact] public void TwoTopLevelObjects_WithNestedProperties_UpdatedSuccessfully() {