public virtual void SendsIndividualErrorWhenOneOfTheRequestsFails()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/DefaultBatch");

            Default.Container client = new Default.Container(serviceUrl);
            client.Format.UseJson();

            Default.DefaultBatchCustomer validCustomer = new Default.DefaultBatchCustomer()
            {
                Id   = 10,
                Name = "Customer 10"
            };

            Default.DefaultBatchCustomer invalidCustomer = new Default.DefaultBatchCustomer()
            {
                Id   = -1,
                Name = "Customer -1"
            };

            client.AddToDefaultBatchCustomer(validCustomer);
            client.AddToDefaultBatchCustomer(invalidCustomer);
            DataServiceRequestException exception = Assert.Throws <DataServiceRequestException>(() =>
            {
                DataServiceResponse response = client.SaveChanges(SaveChangesOptions.Batch);
            });

            Assert.Equal(202, exception.Response.BatchStatusCode);
            Assert.Equal(1, exception.Response.Count());
        }
        public void CanPerformCudOperationsOnABatch()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/DefaultBatch");
            var client     = new Default.Container(serviceUrl);

            client.Format.UseJson();

            IList <Default.DefaultBatchCustomer> customers = client.DefaultBatchCustomer.ToList();

            Default.DefaultBatchCustomer customerToDelete = customers.First();
            Default.DefaultBatchCustomer customerToUpdate = customers.Skip(1).First();
            Default.DefaultBatchCustomer customerToAdd    = new Default.DefaultBatchCustomer {
                Id = 10, Name = "Customer 10"
            };

            client.DeleteObject(customerToDelete);
            customerToUpdate.Name = "Updated customer name";
            client.UpdateObject(customerToUpdate);
            client.AddToDefaultBatchCustomer(customerToAdd);

            client.SaveChanges(SaveChangesOptions.Batch);

            var newClient = new Default.Container(serviceUrl);
            IList <Default.DefaultBatchCustomer> changedCustomers = newClient.DefaultBatchCustomer.ToList();

            Assert.False(changedCustomers.Any(x => x.Id == customerToDelete.Id));
            Assert.Equal(customerToUpdate.Name, changedCustomers.Single(x => x.Id == customerToUpdate.Id).Name);
            Assert.Single(changedCustomers, x => x.Id == 10);
        }
        public virtual void CanSetLinksInABatchWithDataServicesClient()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/DefaultBatch");

            Default.Container client = new Default.Container(serviceUrl);
            client.Format.UseJson();

            Default.DefaultBatchCustomer customer = client.DefaultBatchCustomer.ToList().First();
            Default.DefaultBatchOrder    order    = new Default.DefaultBatchOrder()
            {
                Id = 0, PurchaseDate = DateTime.Now
            };

            client.AddToDefaultBatchOrder(order);

            client.AddLink(customer, "Orders", order);

            client.SaveChanges(SaveChangesOptions.Batch);
        }