Esempio n. 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();
        }
        public static void AddConcrete(this DataServiceContextWrapper context, Type concreteType, object instance)
        {
            typeof(BaseEntityType).GetProperty("Context", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(instance, context);

            context.AddObject(concreteType.Name + "s", instance);
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
        }
        public void AddOpenTypeWithUndeclaredProperties()
        {
            SetContextWrapper();

            var row = Row.CreateRow(Guid.NewGuid());

            contextWrapper.Configurations.RequestPipeline.OnEntryStarting(ea => EntryStarting(ea));

            contextWrapper.AddObject("Row", row);
            contextWrapper.SaveChanges();
            // All clear if no exception is thrown
        }
Esempio n. 6
0
        private static void AddObjectSetLinkTest(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(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();
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
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");
        }
Esempio n. 9
0
        private static void AddUpdateObjectStreamTest(DataServiceContextWrapper <DefaultContainer> 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();
        }
Esempio n. 10
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);
            }
        }
        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);
            }
        }
        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");
        }
        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);
            }
        }