Ejemplo n.º 1
0
        private static void QueryEntitySet(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            contextWrapper.Configurations.ResponsePipeline
            .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryId_Reading)
            .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingStart)
            .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingEnd)
            .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryAction_Reading)
            .OnNestedResourceInfoEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink)
            .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized);

            var entryResultsLinq = contextWrapper.CreateQuery <Customer>("Customer").ToArray();

            foreach (var customer in entryResultsLinq)
            {
                PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer);
            }

            var entryResultsExecute = contextWrapper.Execute <Customer>(new Uri("Customer", UriKind.Relative));

            foreach (Customer customer in entryResultsExecute)
            {
                PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer);
            }

            var customerQuery = contextWrapper.CreateQuery <Customer>("Customer");
            DataServiceCollection <Customer> entryResultsCollection = new DataServiceCollection <Customer>(customerQuery);

            foreach (Customer customer in entryResultsCollection)
            {
                PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer);
            }
        }
Ejemplo n.º 2
0
        private static void QueryEntitySetExecuteAsync(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            contextWrapper.Configurations.ResponsePipeline
            .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryId_Reading)
            .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingStart)
            .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingEnd)
            .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryAction_Reading)
            .OnNestedResourceInfoEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink)
            .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized);

            IEnumerable <Customer> customers = null;
            IAsyncResult           r         = contextWrapper.BeginExecute <Customer>(
                new Uri("Customer", UriKind.Relative),
                result => { customers = contextWrapper.EndExecute <Customer>(result); },
                null);

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

            foreach (Customer customer in customers)
            {
                PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer);
            }
        }
Ejemplo n.º 3
0
        public 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(200);

            contextWrapper.AddObject("Customer", customer);
            contextWrapper.SaveChanges();

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

            customer.Name = "update";
            contextWrapper.UpdateObject(customer);
            contextWrapper.SaveChanges(saveChangesOption);

            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);
            contextWrapper.SaveChanges();
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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(100);

            contextWrapper.AddObject("Customer", customer);
            contextWrapper.SaveChanges(saveChangesOption);

            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);
            contextWrapper.SaveChanges();
        }
Ejemplo n.º 6
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);
            }

            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);
            }
        }
Ejemplo n.º 7
0
        private static void CancelRequestTest(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            contextWrapper.Configurations.RequestPipeline
            .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Writing)
            .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntry_Writing);

            Customer customer = PipelineEventsTestsHelper.CreateNewCustomer();

            contextWrapper.AddObject("Customer", customer);

            IAsyncResult result = contextWrapper.BeginSaveChanges(null, null);

            contextWrapper.CancelRequest(result);

            Assert.IsTrue(customer.Name.EndsWith("ModifyPropertyValueCustomerEntity_Writing"), "Unexpected primitive property");
        }
        public void CancelRequestTest()
        {
            this.RunOnAtomAndJsonFormats(
                this.CreateContext,
                (contextWrapper) =>
            {
                contextWrapper.Configurations.RequestPipeline
                .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Writing)
                .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntry_Writing);

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

                IAsyncResult result = contextWrapper.BeginSaveChanges(null, null);
                contextWrapper.CancelRequest(result);

                Assert.IsTrue(customer.Name.EndsWith("ModifyPropertyValueCustomerEntity_Writing"), "Unexpected primitive property");
            });
        }
Ejemplo n.º 9
0
        public void ThrowExceptionInPipelineDelegateTest()
        {
            this.RunOnAtomAndJsonFormats(
                this.CreateContext,
                (contextWrapper) =>
            {
                contextWrapper.Configurations.ResponsePipeline.OnEntryEnded(PipelineEventsTestsHelper.ThrowException_Reading);
                contextWrapper.Configurations.RequestPipeline.OnEntryEnding(PipelineEventsTestsHelper.ThrowException_Writing);

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

                var e1 = this.Throws <Exception>(() => contextWrapper.SaveChanges());
                Assert.AreEqual("ThrowException_Writing", e1.Message);

                var e2 = this.Throws <Exception>(() => contextWrapper.Execute <Customer>(new Uri("Customer", UriKind.Relative)).First());
                Assert.AreEqual("ThrowException_Reading", e2.Message);
            });
        }
Ejemplo n.º 10
0
        public void QueryEntitySet()
        {
            this.RunOnAtomAndJsonFormats(
                this.CreateContext,
                (contextWrapper) =>
            {
                contextWrapper.Configurations.ResponsePipeline
                .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryId_Reading)
                .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingStart)
                .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingEnd)
                .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryAction_Reading)
                .OnNavigationLinkEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink)
                .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized);

                // cover this for Json
                if (contextWrapper.Format.ODataFormat == ODataFormat.Atom)
                {
                    contextWrapper.Configurations.ResponsePipeline.OnNavigationLinkStarted(PipelineEventsTestsHelper.ModifyLinkName_ReadingNavigationLink);
                }

                var entryResultsLinq = contextWrapper.CreateQuery <Customer>("Customer").ToArray();
                foreach (var customer in entryResultsLinq)
                {
                    PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer);
                }

                var entryResultsExecute = contextWrapper.Execute <Customer>(new Uri("Customer", UriKind.Relative));
                foreach (Customer customer in entryResultsExecute)
                {
                    PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer);
                }

                var customerQuery = contextWrapper.CreateQuery <Customer>("Customer");
                DataServiceCollection <Customer> entryResultsCollection = new DataServiceCollection <Customer>(customerQuery);
                foreach (Customer customer in entryResultsCollection)
                {
                    PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer);
                }
            });
        }
        public void QueryEntitySetExecuteAsync()
        {
            this.RunOnAtomAndJsonFormats(
                this.CreateContext,
                (contextWrapper) =>
            {
                contextWrapper.Configurations.ResponsePipeline
                .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryId_Reading)
                .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingStart)
                .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingEnd)
                .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryAction_Reading)
                .OnNavigationLinkEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink)
                .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized);

                // cover this for Json
                if (contextWrapper.Format.ODataFormat == ODataFormat.Atom)
                {
                    contextWrapper.Configurations.ResponsePipeline.OnNavigationLinkStarted(PipelineEventsTestsHelper.ModifyLinkName_ReadingNavigationLink);
                }

                IEnumerable <Customer> customers = null;
                IAsyncResult r = contextWrapper.BeginExecute <Customer>(
                    new Uri("Customer", UriKind.Relative),
                    result =>
                {
                    customers = contextWrapper.EndExecute <Customer>(result);
                },
                    null);

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

                foreach (Customer customer in customers)
                {
                    PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer);
                }
            });
        }
Ejemplo n.º 12
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();
            });
        }
Ejemplo n.º 13
0
        public void AddUpdateObjectStreamTest()
        {
            this.RunOnAtomAndJsonFormats(
                this.CreateContext,
                (contextWrapper) =>
            {
                contextWrapper.Configurations.RequestPipeline
                .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCarEntity_Writing)
                .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCarEntry_Writing);

                Car car = PipelineEventsTestsHelper.CreateNewCar();
                contextWrapper.AddObject("Car", car);
                contextWrapper.SetSaveStream(car, new MemoryStream(new byte[] { 66, 67 }), true, "text/plain", "slug");
                contextWrapper.SetSaveStream(car, "Photo", new MemoryStream(new byte[] { 66 }), true, new DataServiceRequestArgs()
                {
                    ContentType = "text/plain"
                });
                contextWrapper.SaveChanges();

                // when DataServiceResponsePreference.IncludeContent is not set, property modified in OnEntryEnding will not be updated in client
                Assert.IsTrue(car.Description.EndsWith("ModifyPropertyValueCarEntity_Writing"), "Unexpected primitive property");

                contextWrapper.SetSaveStream(car, new MemoryStream(new byte[] { 68, 69 }), true, "text/plain", "slug");
                contextWrapper.SetSaveStream(car, "Video", new MemoryStream(new byte[] { 66 }), true, new DataServiceRequestArgs()
                {
                    ContentType = "text/plain"
                });
                car.Description = "update";
                contextWrapper.UpdateObject(car);
                contextWrapper.SaveChanges();

                // when DataServiceResponsePreference.IncludeContent is not set, property modified in OnEntryEnding will not be updated in client
                Assert.IsTrue(car.Description.EndsWith("ModifyPropertyValueCarEntity_Writing"), "Unexpected primitive property");

                contextWrapper.DeleteObject(car);
                contextWrapper.SaveChanges();
            });
        }
Ejemplo n.º 14
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();
            });
        }
        private static void QueryEntitySetLinqAsync(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            contextWrapper.Configurations.ResponsePipeline
            .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryId_Reading)
            .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingStart)
            .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingEnd)
            .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryAction_Reading)
            .OnNavigationLinkEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink)
            .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized);

            // cover this for Json
            if (contextWrapper.Format.ODataFormat == ODataFormat.Atom)
            {
                contextWrapper.Configurations.ResponsePipeline.OnNavigationLinkStarted(
                    PipelineEventsTestsHelper.ModifyLinkName_ReadingNavigationLink);
            }

            var query = contextWrapper.CreateQuery <Customer>("Customer");

            var customers = Enumerable.Empty <Customer>();
            var r         = query.BeginExecute(
                result =>
            {
                customers = query.EndExecute(result);
            }, null);

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

            foreach (Customer customer in customers)
            {
                PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer);
            }
        }
        public 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);
            }

            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 r3 = contextWrapper.BeginSaveChanges(
                result =>
            {
                contextWrapper.EndSaveChanges(result);
            },
                null);

            while (!r3.IsCompleted)
            {
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 17
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);
            }
        }