Ejemplo n.º 1
0
        public virtual void SendsIndividualErrorWhenOneOfTheRequestsFails()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/UnbufferedBatch");

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

            Unbuffered.UnbufferedBatchCustomer validCustomer = new Unbuffered.UnbufferedBatchCustomer()
            {
                Id   = 10,
                Name = "Customer 10"
            };

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

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

            Assert.Equal(202, exception.Response.BatchStatusCode);
            Assert.Equal(1, exception.Response.Count());
        }
Ejemplo n.º 2
0
        public void CanPerformCudOperationsOnABatch()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/UnbufferedBatch");
            var client     = new Unbuffered.Container(serviceUrl);

            client.Format.UseJson();

            IList <Unbuffered.UnbufferedBatchCustomer> customers = client.UnbufferedBatchCustomer.ToList();

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

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

            client.SaveChanges(SaveChangesOptions.Batch);

            var newClient = new Unbuffered.Container(serviceUrl);
            IList <Unbuffered.UnbufferedBatchCustomer> changedCustomers = newClient.UnbufferedBatchCustomer.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);
        }
Ejemplo n.º 3
0
        public virtual void CanSetLinksInABatchWithDataServicesClient()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/UnbufferedBatch");

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

            Unbuffered.UnbufferedBatchCustomer customer = client.UnbufferedBatchCustomer.ToList().First();
            Unbuffered.UnbufferedBatchOrder    order    = new Unbuffered.UnbufferedBatchOrder()
            {
                Id = 0, PurchaseDate = DateTime.Now
            };

            client.AddToUnbufferedBatchOrder(order);

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

            client.SaveChanges(SaveChangesOptions.Batch);
        }