Пример #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");
        }
Пример #2
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");
        }