Esempio n. 1
0
        private static void QueryEntityInstance(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            // contextWrapper.Context.UndeclaredPropertyBehavior = UndeclaredPropertyBehavior.Support;
            contextWrapper.Configurations.ResponsePipeline
            .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading)
            .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized)
            .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized);

            var specialEmployee =
                contextWrapper.CreateQuery <Person>("Person").Where(p => p.PersonId == -10).Single() as SpecialEmployee;
            EntityDescriptor descriptor = contextWrapper.GetEntityDescriptor(specialEmployee);

            Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee.CarsLicensePlate,
                            "Unexpected CarsLicensePlate");
            Assert.AreEqual(1, specialEmployee.BonusLevel, "Unexpected BonusLevel");

            specialEmployee = contextWrapper.Execute <SpecialEmployee>(new Uri("Person(-10)", UriKind.Relative)).Single();
            Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee.CarsLicensePlate,
                            "Unexpected CarsLicensePlate");
            Assert.AreEqual(1, specialEmployee.BonusLevel, "Unexpected BonusLevel");

            DataServiceRequest[] requests = new DataServiceRequest[]
            {
                contextWrapper.CreateQuery <Person>("Person"),
                contextWrapper.CreateQuery <Customer>("Customer"),
            };

            DataServiceResponse responses = contextWrapper.ExecuteBatch(requests);
            bool personVerified           = false;
            bool customerVerified         = false;

            foreach (QueryOperationResponse response in responses)
            {
                foreach (object p in response)
                {
                    var      specialEmployee1 = p as SpecialEmployee;
                    Customer c = p as Customer;
                    if (specialEmployee1 != null)
                    {
                        Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee1.CarsLicensePlate,
                                        "Unexpected CarsLicensePlate");
                        Assert.AreEqual(1, specialEmployee1.BonusLevel, "Unexpected BonusLevel");
                        personVerified = true;
                    }

                    if (c != null)
                    {
                        Assert.IsTrue(c.Name.EndsWith("ModifyPropertyValueCustomerEntity_Materialized"),
                                      "Unexpected primitive property");
                        Assert.IsTrue(c.Auditing.ModifiedBy.Equals("ModifyPropertyValueCustomerEntity_Materialized"),
                                      "Unexpected complex property");
                        Assert.IsTrue(c.PrimaryContactInfo.EmailBag.Contains("ModifyPropertyValueCustomerEntity_Materialized"),
                                      "Unexpected collection property");
                        customerVerified = true;
                    }
                }
            }

            Assert.IsTrue(personVerified && customerVerified, "Some inner request does not completed correctly");
        }
Esempio n. 2
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);
            }
        }
        private static void QueryEntityInstanceBatchAsync(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            contextWrapper.Context.IgnoreMissingProperties = true;

            contextWrapper.Configurations.ResponsePipeline
            .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading)
            .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized)
            .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized);

            DataServiceRequest[] requests = new DataServiceRequest[]
            {
                contextWrapper.CreateQuery <Person>("Person(-10)"),
                contextWrapper.CreateQuery <Customer>("Customer"),
            };

            DataServiceResponse responses = null;
            IAsyncResult        r         = contextWrapper.BeginExecuteBatch(
                result => { responses = contextWrapper.EndExecuteBatch(result); },
                null,
                requests);

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

            bool personVerified   = false;
            bool customerVerified = false;

            foreach (QueryOperationResponse response in responses)
            {
                foreach (object p in response)
                {
                    SpecialEmployee se1 = p as SpecialEmployee;
                    Customer        c   = p as Customer;
                    if (se1 != null)
                    {
                        Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", se1.CarsLicensePlate,
                                        "Unexpected CarsLicensePlate");
                        Assert.AreEqual(1, se1.BonusLevel, "Unexpected BonusLevel");
                        personVerified = true;
                    }

                    if (c != null)
                    {
                        Assert.IsTrue(c.Name.EndsWith("ModifyPropertyValueCustomerEntity_Materialized"),
                                      "Unexpected primitive property");
                        Assert.IsTrue(c.Auditing.ModifiedBy.Equals("ModifyPropertyValueCustomerEntity_Materialized"),
                                      "Unexpected complex property");
                        Assert.IsTrue(c.PrimaryContactInfo.EmailBag.Contains("ModifyPropertyValueCustomerEntity_Materialized"),
                                      "Unexpected collection property");
                        customerVerified = true;
                    }
                }
            }

            Assert.IsTrue(personVerified && customerVerified, "Some inner request does not completed correctly");
        }
Esempio n. 4
0
        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)
            .OnNestedResourceInfoEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink)
            .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized);

            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);
            }
        }
Esempio n. 5
0
        [Ignore]  // there is not feed id when using json format.
        public void ErrorResponseTest()
        {
            DataServiceContextWrapper <DefaultContainer> contextWrapper = this.CreateWrappedContext <DefaultContainer>();

            //contextWrapper.Format.UseAtom();
            contextWrapper.Configurations.ResponsePipeline
            .OnFeedStarted(this.SetOnCustomerFeedStartedCalled)
            .OnEntryStarted(this.SetOnCustomerEntryStartedCalled);

            // regular error response
            this.ResetDelegateFlags();
            this.Throws <Exception>(() => contextWrapper.Execute <Customer>(new Uri("Customer(1234)", UriKind.Relative)).Single());
            Assert.IsFalse(OnCustomerEntryStartedCalled, "Unexpected OnEntryEndedCalled");

            // inner response error in a batch
            DataServiceRequest[] requests = new DataServiceRequest[] {
                contextWrapper.CreateQuery <Order>("Order"),
                contextWrapper.CreateQuery <Customer>("Customer(-1234)"),
            };
            this.ResetDelegateFlags();
            this.Throws <Exception>(() =>
            {
                DataServiceResponse responses = contextWrapper.ExecuteBatch(requests);
                foreach (QueryOperationResponse response in responses)
                {
                    foreach (object p in response)
                    {
                    }
                }
            });
            Assert.IsFalse(OnCustomerFeedStartedCalled, "Unexpected OnCustomerFeedStartedCalled");
            Assert.IsFalse(OnCustomerEntryStartedCalled, "Unexpected OnEntryEndedCalled");
            Assert.IsTrue(OnOrderFeedStartedCalled, "Unexpected OnOrderFeedStartedCalled");
            Assert.IsTrue(OnOrderEntryStartedCalled, "Unexpected OnOrderEntryStartedCalled");

            // in-stream error in response
            this.ResetDelegateFlags();
            this.Throws <Exception>(() => contextWrapper.Execute <Customer>(new Uri("InStreamErrorGetCustomer", UriKind.Relative)).ToArray());
            Assert.IsTrue(OnCustomerFeedStartedCalled, "Unexpected OnCustomerFeedStartedCalled");
            Assert.IsTrue(OnCustomerEntryStartedCalled, "Unexpected OnEntryEndedCalled");
        }
Esempio n. 6
0
        private void InsertNewRowRoundtrip(DataServiceContextWrapper <DefaultContainer> contextWrapper, Row newRow)
        {
            Guid newRowId = newRow.Id;

            contextWrapper.Context.AddToRow(newRow);
            contextWrapper.SaveChanges();

            var retrievedRow = contextWrapper.CreateQuery <Row>("Row").Where(r => r.Id == newRowId).SingleOrDefault();

            Assert.IsNotNull(retrievedRow, "Failed to retrieve new row");
            AssertAreEqual(newRow, retrievedRow);
        }
Esempio n. 7
0
        private static void PagingQueryTest(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            contextWrapper.Configurations.ResponsePipeline
            .OnFeedStarted(PipelineEventsTestsHelper.ModifyFeedId_ReadingFeed)
            .OnFeedEnded(PipelineEventsTestsHelper.ModifyNextlink_ReadingFeed);

            var entryResultsLinq =
                contextWrapper.CreateQuery <Customer>("Customer").Execute() as QueryOperationResponse <Customer>;

            entryResultsLinq.ToArray();
            Assert.AreEqual("http://modifyfeedidmodifynextlink/",
                            entryResultsLinq.GetContinuation().NextLinkUri.AbsoluteUri, "Unexpected next link");
        }
Esempio n. 8
0
        private void UpdateRowRoundtrip(DataServiceContextWrapper <DefaultContainer> contextWrapper, Guid rowId, Action <Row> updateRow)
        {
            Row testRow = contextWrapper.Context.Row.Where(r => r.Id == rowId).Single();

            updateRow(testRow);
            contextWrapper.UpdateObject(testRow);
            contextWrapper.SaveChanges();

            var retrievedRow = contextWrapper.CreateQuery <Row>("Row").Where(r => r.Id == rowId).SingleOrDefault();

            Assert.IsNotNull(retrievedRow, "Failed to retrieve updated row");
            AssertAreEqual(testRow, retrievedRow);
        }
Esempio n. 9
0
        private static void ExpandNullEntry(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            contextWrapper.Configurations.ResponsePipeline
            .OnEntryStarted(PipelineEventsTestsHelper.ModifyNullableEntryId_Reading)
            .OnEntryEnded(PipelineEventsTestsHelper.ModifyNullalbeEntryEditLink_ReadingEnd);

            var entries = contextWrapper.CreateQuery <License>("License").Expand("Driver").Where(c => c.Name == "3").ToArray();

            Assert.IsTrue(entries.Count() == 1, "Wrong count");
            var license = entries[0];

            Assert.IsNull(license.Driver, "Driver is not null");

            EntityDescriptor descriptor = contextWrapper.GetEntityDescriptor(license);

            Assert.IsTrue(descriptor.Identity.OriginalString.Contains("ModifyEntryId"), "Wrong Id");
            Assert.IsTrue(descriptor.EditLink.AbsoluteUri.Contains("ModifyEntryEditLink"), "Wrong EditLink");
        }
        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);
            }
        }
        private void UpdateRowRoundtrip(DataServiceContextWrapper<DefaultContainer> contextWrapper, Guid rowId, Action<Row> updateRow)
        {
            Row testRow = contextWrapper.Context.Row.Where(r => r.Id == rowId).Single();
            updateRow(testRow);
            contextWrapper.UpdateObject(testRow);
            contextWrapper.SaveChanges();

            var retrievedRow = contextWrapper.CreateQuery<Row>("Row").Where(r => r.Id == rowId).SingleOrDefault();
            Assert.IsNotNull(retrievedRow, "Failed to retrieve updated row");
            AssertAreEqual(testRow, retrievedRow);
        }
        private void InsertNewRowRoundtrip(DataServiceContextWrapper<DefaultContainer> contextWrapper, Row newRow)
        {
            Guid newRowId = newRow.Id;
            contextWrapper.Context.AddToRow(newRow);
            contextWrapper.SaveChanges();

            var retrievedRow = contextWrapper.CreateQuery<Row>("Row").Where(r => r.Id == newRowId).SingleOrDefault();
            Assert.IsNotNull(retrievedRow, "Failed to retrieve new row");
            AssertAreEqual(newRow, retrievedRow);
        }
        private static void QueryEntityInstanceBatchAsync(DataServiceContextWrapper<DefaultContainer> contextWrapper)
        {
            contextWrapper.Context.IgnoreMissingProperties = true;

            contextWrapper.Configurations.ResponsePipeline
                .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading)
                .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized)
                .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized);

            DataServiceRequest[] requests = new DataServiceRequest[]
            {
                contextWrapper.CreateQuery<Person>("Person(-10)"),
                contextWrapper.CreateQuery<Customer>("Customer"),
            };

            DataServiceResponse responses = null;
            IAsyncResult r = contextWrapper.BeginExecuteBatch(
                result => { responses = contextWrapper.EndExecuteBatch(result); },
                null,
                requests);

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

            bool personVerified = false;
            bool customerVerified = false;
            foreach (QueryOperationResponse response in responses)
            {
                foreach (object p in response)
                {
                    SpecialEmployee se1 = p as SpecialEmployee;
                    Customer c = p as Customer;
                    if (se1 != null)
                    {
                        Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", se1.CarsLicensePlate,
                            "Unexpected CarsLicensePlate");
                        Assert.AreEqual(1, se1.BonusLevel, "Unexpected BonusLevel");
                        personVerified = true;
                    }

                    if (c != null)
                    {
                        Assert.IsTrue(c.Name.EndsWith("ModifyPropertyValueCustomerEntity_Materialized"),
                            "Unexpected primitive property");
                        Assert.IsTrue(c.Auditing.ModifiedBy.Equals("ModifyPropertyValueCustomerEntity_Materialized"),
                            "Unexpected complex property");
                        Assert.IsTrue(c.PrimaryContactInfo.EmailBag.Contains("ModifyPropertyValueCustomerEntity_Materialized"),
                            "Unexpected collection property");
                        customerVerified = true;
                    }
                }
            }

            Assert.IsTrue(personVerified && customerVerified, "Some inner request does not completed correctly");
        }