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(); }
private void ExecuteActions(DataServiceContextWrapper<DefaultContainer> context, IEnumerable<OperationDescriptor> operationDescriptors) { foreach (OperationDescriptor od in operationDescriptors) { context.Execute(od.Target, "POST"); } }
private static void QueryEntityInstance(DataServiceContextWrapper <DefaultContainer> contextWrapper) { contextWrapper.Context.IgnoreMissingProperties = true; 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"); }