Пример #1
0
        public async Task SendsIndividualErrorWhenOneOfTheRequestsFails()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/DefaultBatch");

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

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

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

            client.AddToDefaultBatchCustomer(validCustomer);
            client.AddToDefaultBatchCustomer(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);
        }
Пример #2
0
        public async Task CanPerformCudOperationsOnABatch()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/DefaultBatch");
            var client     = new DefaultBatchProxy.Container(serviceUrl);

            client.Format.UseJson();

            var customers = await client.DefaultBatchCustomer.ExecuteAsync();

            List <DefaultBatchProxy.DefaultBatchCustomer> customerList = customers.ToList();

            DefaultBatchProxy.DefaultBatchCustomer customerToUpdate = customerList[1];
            DefaultBatchProxy.DefaultBatchCustomer customerToDelete = customerList[9];
            DefaultBatchProxy.DefaultBatchCustomer customerToAdd    = new DefaultBatchProxy.DefaultBatchCustomer {
                Id = 10, Name = "Customer 10"
            };

            client.DeleteObject(customerToDelete);

            customerToUpdate.Name = "Updated customer name";
            client.UpdateObject(customerToUpdate);

            client.AddToDefaultBatchCustomer(customerToAdd);

            var response = await client.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset);

            var newClient        = new DefaultBatchProxy.Container(serviceUrl);
            var changedCustomers = await newClient.DefaultBatchCustomer.ExecuteAsync();

            List <DefaultBatchProxy.DefaultBatchCustomer> changedCustomersList = changedCustomers.ToList();

            Assert.DoesNotContain(changedCustomersList, (x) => x.Id == customerToDelete.Id);
            Assert.Equal(customerToUpdate.Name, changedCustomersList.Single(x => x.Id == customerToUpdate.Id).Name);
            Assert.Single(changedCustomersList, x => x.Id == 10);
        }
Пример #3
0
        public async Task CanBatchQueriesWithDataServicesClient()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/DefaultBatch");

            DefaultBatchProxy.Container client = new DefaultBatchProxy.Container(serviceUrl);
            client.Format.UseJson();
            Uri customersRequestUri = new Uri(BaseAddress + "/DefaultBatch/DefaultBatchCustomer");
            DataServiceRequest <DefaultBatchProxy.DefaultBatchCustomer> customersRequest = new DataServiceRequest <DefaultBatchProxy.DefaultBatchCustomer>(customersRequestUri);
            Uri singleCustomerRequestUri = new Uri(BaseAddress + "/DefaultBatch/DefaultBatchCustomer(0)");
            DataServiceRequest <DefaultBatchProxy.DefaultBatchCustomer> singleCustomerRequest = new DataServiceRequest <DefaultBatchProxy.DefaultBatchCustomer>(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 <DefaultBatchProxy.DefaultBatchCustomer>().Count(), 10, 14);
                    continue;
                }
                if (response.Query.RequestUri == singleCustomerRequestUri)
                {
                    Assert.Single(response.Cast <DefaultBatchProxy.DefaultBatchCustomer>());
                    continue;
                }
            }
        }
        public void SendsIndividualErrorWhenOneOfTheRequestsFails()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/DefaultBatch");

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

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

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

            client.AddToDefaultBatchCustomer(validCustomer);
            client.AddToDefaultBatchCustomer(invalidCustomer);
            var aggregate = Assert.Throws <AggregateException>(() =>
            {
                DataServiceResponse response = client.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset).Result;
            });

            var exception = aggregate.InnerExceptions.Single() as DataServiceRequestException;

            Assert.NotNull(exception);
            Assert.Equal(200, exception.Response.BatchStatusCode);
            Assert.Equal(1, exception.Response.Count());
        }
Пример #5
0
        public async Task CanSetLinksInABatchWithDataServicesClient()
        {
            Uri serviceUrl = new Uri(BaseAddress + "/DefaultBatch");

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

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

            client.AddToDefaultBatchOrder(order);

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

            var response = await client.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset);

            Assert.Equal(200, response.BatchStatusCode);
        }