Beispiel #1
0
        public void CanBatchQueriesWithDataServicesClient()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/UnbufferedBatch");

            Unbuffered.Container client = new Unbuffered.Container(serviceUrl);
            client.Format.UseJson();
            Uri customersRequestUri = new Uri(BaseAddress + "/UnbufferedBatch/UnbufferedBatchCustomer");
            DataServiceRequest <Unbuffered.UnbufferedBatchCustomer> customersRequest = new DataServiceRequest <Unbuffered.UnbufferedBatchCustomer>(customersRequestUri);
            Uri singleCustomerRequestUri = new Uri(BaseAddress + "/UnbufferedBatch/UnbufferedBatchCustomer(0)");
            DataServiceRequest <Unbuffered.UnbufferedBatchCustomer> singleCustomerRequest = new DataServiceRequest <Unbuffered.UnbufferedBatchCustomer>(singleCustomerRequestUri);

            DataServiceResponse batchResponse = client.ExecuteBatch(customersRequest, singleCustomerRequest);

            if (batchResponse.IsBatchResponse)
            {
                Assert.Equal(202, batchResponse.BatchStatusCode);
            }

            foreach (QueryOperationResponse response in batchResponse)
            {
                Assert.Equal(200, response.StatusCode);
                if (response.Query.RequestUri == customersRequestUri)
                {
                    Assert.Equal(10, response.Cast <Unbuffered.UnbufferedBatchCustomer>().Count());
                    continue;
                }
                if (response.Query.RequestUri == singleCustomerRequestUri)
                {
                    Assert.Equal(1, response.Cast <Unbuffered.UnbufferedBatchCustomer>().Count());
                    continue;
                }
            }
        }
Beispiel #2
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());
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }