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 void CanBatchQueriesWithDataServicesClient() { Uri serviceUrl = new Uri(BaseAddress + "/UnbufferedBatch"); UnbufferedBatchProxy.Container client = new UnbufferedBatchProxy.Container(serviceUrl); client.Format.UseJson(); Uri customersRequestUri = new Uri(BaseAddress + "/UnbufferedBatch/UnbufferedBatchCustomer"); DataServiceRequest <UnbufferedBatchProxy.UnbufferedBatchCustomer> customersRequest = new DataServiceRequest <UnbufferedBatchProxy.UnbufferedBatchCustomer>(customersRequestUri); Uri singleCustomerRequestUri = new Uri(BaseAddress + "/UnbufferedBatch/UnbufferedBatchCustomer(0)"); DataServiceRequest <UnbufferedBatchProxy.UnbufferedBatchCustomer> singleCustomerRequest = new DataServiceRequest <UnbufferedBatchProxy.UnbufferedBatchCustomer>(singleCustomerRequestUri); DataServiceResponse batchResponse = client.ExecuteBatchAsync(customersRequest, singleCustomerRequest).Result; if (batchResponse.IsBatchResponse) { Assert.Equal(200, batchResponse.BatchStatusCode); } foreach (QueryOperationResponse response in batchResponse) { Assert.Equal(200, response.StatusCode); if (response.Query.RequestUri == customersRequestUri) { Assert.Equal(10, response.Cast <UnbufferedBatchProxy.UnbufferedBatchCustomer>().Count()); continue; } if (response.Query.RequestUri == singleCustomerRequestUri) { Assert.Equal(1, response.Cast <UnbufferedBatchProxy.UnbufferedBatchCustomer>().Count()); continue; } } }
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 CanBatchQueriesWithDataServicesClient() { Uri serviceUrl = new Uri(BaseAddress + "/UnbufferedBatch"); UnbufferedBatchProxy.Container client = new UnbufferedBatchProxy.Container(serviceUrl); client.Format.UseJson(); Uri customersRequestUri = new Uri(BaseAddress + "/UnbufferedBatch/UnbufferedBatchCustomer"); DataServiceRequest <UnbufferedBatchProxy.UnbufferedBatchCustomer> customersRequest = new DataServiceRequest <UnbufferedBatchProxy.UnbufferedBatchCustomer>(customersRequestUri); Uri singleCustomerRequestUri = new Uri(BaseAddress + "/UnbufferedBatch/UnbufferedBatchCustomer(0)"); DataServiceRequest <UnbufferedBatchProxy.UnbufferedBatchCustomer> singleCustomerRequest = new DataServiceRequest <UnbufferedBatchProxy.UnbufferedBatchCustomer>(singleCustomerRequestUri); DataServiceResponse batchResponse = await client.ExecuteBatchAsync(customersRequest, singleCustomerRequest); if (batchResponse.IsBatchResponse) { Assert.Equal(200, batchResponse.BatchStatusCode); } foreach (QueryOperationResponse response in batchResponse) { Assert.Equal(200, response.StatusCode); if (response.Query.RequestUri == customersRequestUri) { // Previous test could modify the total count to be anywhere from, 10 to 14. Assert.InRange(response.Cast <UnbufferedBatchProxy.UnbufferedBatchCustomer>().Count(), 10, 14); continue; } if (response.Query.RequestUri == singleCustomerRequestUri) { Assert.Single(response.Cast <UnbufferedBatchProxy.UnbufferedBatchCustomer>()); continue; } } }
public virtual void CanSetLinksInABatchWithDataServicesClient() { Uri serviceUrl = new Uri(BaseAddress + "/UnbufferedBatch"); UnbufferedBatchProxy.Container client = new UnbufferedBatchProxy.Container(serviceUrl); client.Format.UseJson(); UnbufferedBatchProxy.UnbufferedBatchCustomer customer = client.UnbufferedBatchCustomer.ExecuteAsync().Result.First(); UnbufferedBatchProxy.UnbufferedBatchOrder order = new UnbufferedBatchProxy.UnbufferedBatchOrder() { Id = 0, PurchaseDate = DateTime.Now }; client.AddToUnbufferedBatchOrder(order); client.AddLink(customer, "Orders", order); client.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset).Wait(); }
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); }