コード例 #1
0
        private static void AddUpdateBatchTest(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            contextWrapper.Configurations.RequestPipeline
            .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Writing)
            .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntry_Writing);

            Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(300);

            contextWrapper.AddObject("Customer", customer);

            Customer customer2 = PipelineEventsTestsHelper.CreateNewCustomer(301);

            contextWrapper.AddObject("Customer", customer2);

            Order order = PipelineEventsTestsHelper.CreateNewOrder(300);

            contextWrapper.AddRelatedObject(customer, "Orders", order);

            contextWrapper.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);

            Assert.IsTrue(customer.Name.EndsWith("UpdatedODataEntryPropertyValue"), "Unexpected primitive property");
            Assert.IsTrue(customer2.Name.EndsWith("UpdatedODataEntryPropertyValue"), "Unexpected primitive property");

            contextWrapper.DeleteObject(customer);
            contextWrapper.DeleteObject(customer2);
            contextWrapper.DeleteObject(order);
            contextWrapper.SaveChanges();
        }
コード例 #2
0
        public void AddObjectSetLinkTest()
        {
            this.RunOnAtomAndJsonFormats(
                this.CreateContext,
                (contextWrapper) =>
            {
                // These delegates are invoked when the client sends a single request for AddObject+SetLink
                contextWrapper.Configurations.RequestPipeline
                .OnNavigationLinkStarting(PipelineEventsTestsHelper.ModifyNavigationLink_WritingStart)
                .OnNavigationLinkEnding(PipelineEventsTestsHelper.ModifyNavigationLink_WritingEnd)
                .OnEntityReferenceLink(PipelineEventsTestsHelper.ModifyReferenceLink);

                Customer customer  = PipelineEventsTestsHelper.CreateNewCustomer(400);
                Customer customer2 = PipelineEventsTestsHelper.CreateNewCustomer(401);
                Customer customer3 = PipelineEventsTestsHelper.CreateNewCustomer(402);
                Customer customer4 = PipelineEventsTestsHelper.CreateNewCustomer(403);
                contextWrapper.AddObject("Customer", customer);
                contextWrapper.AddObject("Customer", customer2);
                contextWrapper.AddObject("Customer", customer3);
                contextWrapper.AddObject("Customer", customer4);
                contextWrapper.SaveChanges();

                Order order = PipelineEventsTestsHelper.CreateNewOrder(400);
                contextWrapper.AddObject("Order", order);
                contextWrapper.SetLink(order, "Customer", customer);
                contextWrapper.SaveChanges();

                Assert.AreEqual(400, order.OrderId, "OrderId should not be altered in the pipeline delegates");
                Customer relatedCustomer = contextWrapper.Execute <Customer>(new Uri("Order(400)/Customer", UriKind.Relative)).Single();
                Assert.AreEqual(402, relatedCustomer.CustomerId, "Associated CustomerId should be altered in the pipeline delegates");

                contextWrapper.DeleteObject(customer);
                contextWrapper.DeleteObject(customer2);
                contextWrapper.DeleteObject(customer3);
                contextWrapper.DeleteObject(customer4);
                contextWrapper.DeleteObject(order);
                contextWrapper.SaveChanges();
            });
        }
コード例 #3
0
        public void AddUpdateBatchTest()
        {
            this.RunOnAtomAndJsonFormats(
                this.CreateContext,
                (contextWrapper) =>
            {
                contextWrapper.Configurations.RequestPipeline
                .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Writing)
                .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntry_Writing);

                Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(300);
                contextWrapper.AddObject("Customer", customer);

                Customer customer2 = PipelineEventsTestsHelper.CreateNewCustomer(301);
                contextWrapper.AddObject("Customer", customer2);

                Order order = PipelineEventsTestsHelper.CreateNewOrder(300);
                contextWrapper.AddRelatedObject(customer, "Orders", order);

                contextWrapper.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);

                if (contextWrapper.Format.ODataFormat == ODataFormat.Atom)
                {
                    Assert.IsTrue(customer.Name.EndsWith("UpdatedODataEntryPropertyValueModifyPropertyValueCustomerEntry_Writing"), "Unexpected primitive property");
                    Assert.IsTrue(customer2.Name.EndsWith("UpdatedODataEntryPropertyValueModifyPropertyValueCustomerEntry_Writing"), "Unexpected primitive property");
                }
                else
                {
                    Assert.IsTrue(customer.Name.EndsWith("UpdatedODataEntryPropertyValue"), "Unexpected primitive property");
                    Assert.IsTrue(customer2.Name.EndsWith("UpdatedODataEntryPropertyValue"), "Unexpected primitive property");
                }

                contextWrapper.DeleteObject(customer);
                contextWrapper.DeleteObject(customer2);
                contextWrapper.DeleteObject(order);
                contextWrapper.SaveChanges();
            });
        }
コード例 #4
0
        private static void AddObjectSetLinkTestAsync(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            // These delegates are invoked when the client sends a single request for AddObject+SetLink
            contextWrapper.Configurations.RequestPipeline
            .OnNestedResourceInfoStarting(PipelineEventsTestsHelper.ModifyNavigationLink_WritingStart)
            .OnNestedResourceInfoEnding(PipelineEventsTestsHelper.ModifyNavigationLink_WritingEnd)
            .OnEntityReferenceLink(PipelineEventsTestsHelper.ModifyReferenceLink);

            Customer customer  = PipelineEventsTestsHelper.CreateNewCustomer(1300);
            Customer customer2 = PipelineEventsTestsHelper.CreateNewCustomer(1301);
            Customer customer3 = PipelineEventsTestsHelper.CreateNewCustomer(1302);
            Customer customer4 = PipelineEventsTestsHelper.CreateNewCustomer(1303);

            contextWrapper.AddObject("Customer", customer);
            contextWrapper.AddObject("Customer", customer2);
            contextWrapper.AddObject("Customer", customer3);
            contextWrapper.AddObject("Customer", customer4);

            IAsyncResult r1 = contextWrapper.BeginSaveChanges(
                result => { contextWrapper.EndSaveChanges(result); },
                null);

            while (!r1.IsCompleted)
            {
                Thread.Sleep(1000);
            }

            Order order = PipelineEventsTestsHelper.CreateNewOrder(1300);

            contextWrapper.AddObject("Order", order);
            contextWrapper.SetLink(order, "Customer", customer);

            IAsyncResult r2 = contextWrapper.BeginSaveChanges(
                result => { contextWrapper.EndSaveChanges(result); },
                null);

            while (!r2.IsCompleted)
            {
                Thread.Sleep(1000);
            }

            Assert.AreEqual(1300, order.OrderId, "OrderId should not be altered in the pipeline delegates");

            Customer     relatedCustomer = null;
            IAsyncResult r3 = contextWrapper.BeginExecute <Customer>(
                new Uri("Order(1300)/Customer", UriKind.Relative),
                result => { relatedCustomer = contextWrapper.EndExecute <Customer>(result).Single(); },
                null);

            while (!r3.IsCompleted)
            {
                Thread.Sleep(1000);
            }

            Assert.AreEqual(1302, relatedCustomer.CustomerId,
                            "Associated CustomerId should be altered in the pipeline delegates");

            contextWrapper.DeleteObject(customer);
            contextWrapper.DeleteObject(customer2);
            contextWrapper.DeleteObject(customer3);
            contextWrapper.DeleteObject(customer4);
            contextWrapper.DeleteObject(order);
            IAsyncResult r4 = contextWrapper.BeginSaveChanges(
                result => { contextWrapper.EndSaveChanges(result); },
                null);

            while (!r4.IsCompleted)
            {
                Thread.Sleep(1000);
            }
        }