Skip to content

Commit

Permalink
update based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ElizabethOkerio committed Apr 27, 2023
1 parent 52487c2 commit 6b9d4a9
Showing 1 changed file with 25 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ArgumentException>(async () => await this.context.BulkUpdateAsync<Person>(null));
}
Expand Down Expand Up @@ -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<NullReferenceException>(() => this.context.BulkUpdateAsync(person));
}

[Fact]
public void HandleResponse_Of_AnInvalidResponse_ThrowsException()
{
Expand Down Expand Up @@ -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()
{
Expand Down

0 comments on commit 6b9d4a9

Please sign in to comment.