コード例 #1
0
        public void AddObjectTestAction(ODataFormat format, MergeOption mergeOption, SaveChangesOptions saveChangesOption)
        {
            DataServiceContextWrapper <DefaultContainer> contextWrapper = this.CreateContext();

            contextWrapper.Context.MergeOption = mergeOption;
            if (format == ODataFormat.Json)
            {
                contextWrapper.Format.UseJson();
            }

            contextWrapper.Configurations.RequestPipeline
            .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Writing)
            .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntry_Writing);

            Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(1100);

            contextWrapper.AddObject("Customer", customer);

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

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


            if (format == ODataFormat.Atom)
            {
                // Make the ATOM payload order consistence with JSON.
                Assert.IsTrue(customer.Name.EndsWith("UpdatedODataEntryPropertyValueModifyPropertyValueCustomerEntry_Writing"), "Unexpected primitive property");
            }
            else
            {
                Assert.IsTrue(customer.Name.EndsWith("UpdatedODataEntryPropertyValue"), "Unexpected primitive property");
            }

            Assert.IsTrue(customer.Auditing.ModifiedBy.Equals("UpdatedODataEntryPropertyValue"), "Unexpected complex property");
            Assert.IsTrue(customer.PrimaryContactInfo.EmailBag.Contains("UpdatedODataEntryPropertyValue"));

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

            while (!r2.IsCompleted)
            {
                Thread.Sleep(1000);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
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
                .OnNavigationLinkStarting(PipelineEventsTestsHelper.ModifyNavigationLink_WritingStart)
                .OnNavigationLinkEnding(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);
            }
        }
コード例 #4
0
        internal void UpdateObjectTestAction(ODataFormat format, MergeOption mergeOption, SaveChangesOptions saveChangesOption)
        {
            DataServiceContextWrapper <DefaultContainer> contextWrapper = this.CreateContext();

            contextWrapper.Context.MergeOption = mergeOption;
            contextWrapper.Context.AddAndUpdateResponsePreference = DataServiceResponsePreference.IncludeContent;
            if (format == ODataFormat.Json)
            {
                contextWrapper.Format.UseJson();
            }

            Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(1200);

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

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

            contextWrapper.Configurations.RequestPipeline
            .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Writing)
            .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntry_Writing);

            customer.Name = "update";
            contextWrapper.UpdateObject(customer);
            IAsyncResult r2 = contextWrapper.BeginSaveChanges(
                result =>
            {
                contextWrapper.EndSaveChanges(result);
            },
                null);

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


            Assert.True(customer.Name.EndsWith("UpdatedODataEntryPropertyValue"), "Unexpected primitive property");
            Assert.True(customer.Auditing.ModifiedBy.Equals("UpdatedODataEntryPropertyValue"), "Unexpected complex property");
            Assert.Contains("UpdatedODataEntryPropertyValue", customer.PrimaryContactInfo.EmailBag);

            contextWrapper.DeleteObject(customer);
            IAsyncResult r3 = contextWrapper.BeginSaveChanges(
                result =>
            {
                contextWrapper.EndSaveChanges(result);
            },
                null);

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