public void WebDataServiceBaseTypeContainer() { AdHocEntityType customersBase = new AdHocEntityType("CustomerBase"); AdHocEntityType customersDerived = new AdHocEntityType(customersBase) { Name = "CustomerDerived" }; AdHocEntityType referencingType = new AdHocEntityType("ReferencingType"); AdHocEntitySet customerSet = new AdHocEntitySet() { Name = "Customers", Type = customersBase }; AdHocAssociationType associationType = new AdHocAssociationType() { Name = "ReferenceToDerivedCustomerType", Ends = new List <AdHocAssociationTypeEnd>() { new AdHocAssociationTypeEnd() { Multiplicity = "1", RoleName = "Reference", Type = referencingType }, new AdHocAssociationTypeEnd() { Multiplicity = "*", RoleName = "Customer", Type = customersDerived }, } }; AdHocEntitySet referencingSet = new AdHocEntitySet() { Name = "ReferenceHolder", Type = referencingType }; AdHocContainer container = new AdHocContainer() { AssociationSets = new List <AdHocAssociationSet>() { new AdHocAssociationSet() { Name = "ReferenceToDerivedCustomer", Type = associationType, Ends = new List <AdHocAssociationSetEnd>() { new AdHocAssociationSetEnd() { EndType = associationType.Ends[0], EntitySet = referencingSet }, new AdHocAssociationSetEnd() { EndType = associationType.Ends[1], EntitySet = customerSet } }, } }, EntitySets = new List <AdHocEntitySet>() { customerSet, referencingSet }, ExtraEntityTypes = new List <AdHocEntityType>() { customersDerived }, }; associationType.AddNavigationProperties(); AdHocModel model = new AdHocModel(container) { ConceptualNs = TestXmlConstants.EdmV1Namespace }; Assembly assembly = model.GenerateModelsAndAssembly("WebDataServiceBaseTypeContainer", false /* isReflectionProviderBased */); using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = TestUtil.LoadDerivedTypeFromAssembly(assembly, typeof(System.Data.Objects.ObjectContext)); request.RequestUriString = "/$metadata"; request.SendRequest(); using (var s = new StreamReader(request.GetResponseStream())) Trace.WriteLine(s.ReadToEnd()); } using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = typeof(ContextWithBaseType); request.RequestUriString = "/$metadata"; request.SendRequest(); XmlDocument document = request.GetResponseStreamAsXmlDocument(); UnitTestsUtil.VerifyXPaths(document, "//csdl:Schema/csdl:EntityType[@Name='WebDataServiceTest_SimpleBaseType']", "//csdl:Schema/csdl:EntityType[@Name='WebDataServiceTest_ReferencingType']", "//csdl:Schema/csdl:EntityType[@Name='WebDataServiceTest_DerivedType' and @BaseType='AstoriaUnitTests.Tests.WebDataServiceTest_SimpleBaseType']", "//csdl:Schema/csdl:EntityContainer/csdl:EntitySet[@Name='B']", "//csdl:Schema/csdl:EntityContainer/csdl:EntitySet[@Name='R']/csdl:NavigationPropertyBinding[@Path='DerivedReference' and @Target='B']"); } }
// ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight public void UpdatePostInsertResourceToCollectionRepeated() { AdHocEntityType orderType = new AdHocEntityType() { Name = "OrderType", Properties = new List<AdHocProperty>() { new AdHocScalarProperty() { Name = "OrderID", Type = new AdHocPrimitiveType(typeof(string)) }, } }; orderType.KeyProperties = new List<AdHocProperty>() { orderType.Properties[0] }; AdHocEntityType customerType = new AdHocEntityType() { Name = "CustomerType", Properties = new List<AdHocProperty>() { new AdHocScalarProperty() { Name = "CustomerID", Type = new AdHocPrimitiveType(typeof(string)) }, } }; customerType.KeyProperties = new List<AdHocProperty>() { customerType.Properties[0] }; AdHocAssociationType pendingOrdersType = new AdHocAssociationType() { Name = "PendingOrdersType", Ends = new List<AdHocAssociationTypeEnd>() { new AdHocAssociationTypeEnd() { RoleName = "PendingCustomer", Multiplicity = "1", Type = customerType }, new AdHocAssociationTypeEnd() { RoleName = "PendingOrder", Multiplicity = "*", Type = orderType }, } }; AdHocAssociationType deliveredOrdersType = new AdHocAssociationType() { Name = "DeliveredOrdersType", Ends = new List<AdHocAssociationTypeEnd>() { new AdHocAssociationTypeEnd() { RoleName = "DeliveredCustomer", Multiplicity = "1", Type = customerType }, new AdHocAssociationTypeEnd() { RoleName = "DeliveredOrder", Multiplicity = "*", Type = orderType }, } }; pendingOrdersType.AddNavigationProperties(); deliveredOrdersType.AddNavigationProperties(); AdHocEntitySet customers = new AdHocEntitySet() { Name = "Customers", Type = customerType }; AdHocEntitySet orders = new AdHocEntitySet() { Name = "Orders", Type = orderType }; AdHocContainer container = new AdHocContainer() { EntitySets = new List<AdHocEntitySet>() { customers, orders }, AssociationSets = new List<AdHocAssociationSet>() { new AdHocAssociationSet() { Name = "PendingOrders", Type = pendingOrdersType, Ends = new List<AdHocAssociationSetEnd>() { new AdHocAssociationSetEnd() { EntitySet = customers, EndType = pendingOrdersType.OneEnd }, new AdHocAssociationSetEnd() { EntitySet = orders, EndType = pendingOrdersType.ManyEnd }, } }, new AdHocAssociationSet() { Name = "DeliveredOrders", Type = deliveredOrdersType, Ends = new List<AdHocAssociationSetEnd>() { new AdHocAssociationSetEnd() { EntitySet = customers, EndType = deliveredOrdersType.OneEnd }, new AdHocAssociationSetEnd() { EntitySet = orders, EndType = deliveredOrdersType.ManyEnd }, } }, } }; AdHocModel model = new AdHocModel(container) { ConceptualNs = XmlConstants.EdmOasisNamespace }; model.CreateDatabase(); try { Assembly assembly = model.GenerateModelsAndAssembly("UpdateInsertResourceToCollectionRepeated", false /* isReflectionProviderBased */); using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = TestUtil.LoadDerivedTypeFromAssembly(assembly, typeof(System.Data.Objects.ObjectContext)); request.RequestUriString = "/Customers"; request.HttpMethod = "POST"; request.RequestContentType = SerializationFormatData.JsonLight.MimeTypes[0]; request.SetRequestStreamAsText("{ CustomerID : \"C1\" }"); request.SendRequest(); // Same customer reference in to-one associations. request.RequestUriString = "/Orders"; request.SetRequestStreamAsText( "{ OrderID : \"O1\", " + " PendingCustomer : { odata.readlink : \"/Customers('C1')\" } , " + " DeliveredCustomer : { odata.readlink : \"/Customers('C1')\" } " + "}"); request.SendRequest(); // Same order reference in to-many associations. request.RequestUriString = "/Customers"; request.SetRequestStreamAsText( "{ CustomerID : \"C2\", " + " PendingOrder : [ { odata.readlink : \"/Orders('O1')\" } ], " + " DeliveredOrder : [ { odata.readlink : \"/Orders('O1')\" } ] " + "}"); request.SendRequest(); } } finally { model.DropDatabase(); } }