public void SendsIndividualErrorWhenOneOfTheRequestsFails() { Uri serviceUrl = new Uri(BaseAddress + "/UnbufferedBatch"); UnbufferedBatchProxy.Container client = new UnbufferedBatchProxy.Container(serviceUrl); client.Format.UseJson(); UnbufferedBatchProxy.UnbufferedBatchCustomer validCustomer = new UnbufferedBatchProxy.UnbufferedBatchCustomer() { Id = 10, Name = "Customer 10" }; UnbufferedBatchProxy.UnbufferedBatchCustomer invalidCustomer = new UnbufferedBatchProxy.UnbufferedBatchCustomer() { Id = -1, Name = "Customer -1" }; client.AddToUnbufferedBatchCustomer(validCustomer); client.AddToUnbufferedBatchCustomer(invalidCustomer); var aggregateException = Assert.Throws <AggregateException>(() => { DataServiceResponse response = client.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset).Result; }); var exception = aggregateException.InnerExceptions.SingleOrDefault() as DataServiceRequestException; Assert.NotNull(exception); Assert.Equal(200, exception.Response.BatchStatusCode); Assert.Equal(1, exception.Response.Count()); }
public async Task SendsIndividualErrorWhenOneOfTheRequestsFails() { Uri serviceUrl = new Uri(BaseAddress + "/UnbufferedBatch"); UnbufferedBatchProxy.Container client = new UnbufferedBatchProxy.Container(serviceUrl); client.Format.UseJson(); UnbufferedBatchProxy.UnbufferedBatchCustomer validCustomer = new UnbufferedBatchProxy.UnbufferedBatchCustomer() { Id = 10, Name = "Customer 10" }; UnbufferedBatchProxy.UnbufferedBatchCustomer invalidCustomer = new UnbufferedBatchProxy.UnbufferedBatchCustomer() { Id = -1, Name = "Customer -1" }; client.AddToUnbufferedBatchCustomer(validCustomer); client.AddToUnbufferedBatchCustomer(invalidCustomer); var exception = await Assert.ThrowsAsync <DataServiceRequestException>(async() => { DataServiceResponse response = await client.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset); }); Assert.NotNull(exception); Assert.Equal(200, exception.Response.BatchStatusCode); Assert.Single(exception.Response); }
public async Task CanPerformCudOperationsOnABatch() { Uri serviceUrl = new Uri(BaseAddress + "/UnbufferedBatch"); var client = new UnbufferedBatchProxy.Container(serviceUrl); client.Format.UseJson(); IEnumerable <UnbufferedBatchProxy.UnbufferedBatchCustomer> customers = await client.UnbufferedBatchCustomer.ExecuteAsync(); var customersList = customers.ToList(); UnbufferedBatchProxy.UnbufferedBatchCustomer customerToDelete = customersList[0]; client.DeleteObject(customerToDelete); UnbufferedBatchProxy.UnbufferedBatchCustomer customerToUpdate = customersList[1]; customerToUpdate.Name = "Updated customer name"; client.UpdateObject(customerToUpdate); UnbufferedBatchProxy.UnbufferedBatchCustomer customerToAdd = new UnbufferedBatchProxy.UnbufferedBatchCustomer { Id = 10, Name = "Customer 10" }; client.AddToUnbufferedBatchCustomer(customerToAdd); var response = await client.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset); var newClient = new UnbufferedBatchProxy.Container(serviceUrl); IEnumerable <UnbufferedBatchProxy.UnbufferedBatchCustomer> changedCustomers = await newClient.UnbufferedBatchCustomer.ExecuteAsync(); var changedCustomerList = changedCustomers.ToList(); Assert.False(changedCustomerList.Any(x => x.Id == customerToDelete.Id)); Assert.Equal(customerToUpdate.Name, changedCustomerList.Single(x => x.Id == customerToUpdate.Id).Name); Assert.Single(changedCustomerList, x => x.Id == 10); }