예제 #1
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);
        }
예제 #2
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);
        }
        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());
        }
예제 #4
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);
        }