private static DSPMetadata CreateMetadataForXFeatureEntity(bool isMLE = false) { DSPMetadata metadata = new DSPMetadata("CollectionCrossFeatureTests", "AstoriaUnitTests.Tests"); var entityType = metadata.AddEntityType("XFeatureTestsEntity", typeof(DSPResourceWithCollectionProperty), null, false); if (isMLE) { entityType.IsMediaLinkEntry = true; } metadata.AddKeyProperty(entityType, "ID", typeof(int)); metadata.AddPrimitiveProperty(entityType, "Description", typeof(string)); metadata.AddCollectionProperty(entityType, "Strings", typeof(string)); var complexType = metadata.AddComplexType("UnitTestModule+CollectionTest+XFeatureTestsComplexType", typeof(DSPResourceWithCollectionProperty), null, false); metadata.AddPrimitiveProperty(complexType, "Text", typeof(string)); metadata.AddCollectionProperty(entityType, "Structs", complexType); var resourceSet = metadata.AddResourceSet("Entities", entityType); metadata.AddResourceReferenceProperty(entityType, "NextTestEntity", resourceSet, entityType); metadata.SetReadOnly(); return metadata; }
private DSPMetadata PreferHeader_CreateMetadata() { DSPMetadata metadata = new DSPMetadata("Test", "TestNS"); var entityType = metadata.AddEntityType("Item", typeof(DSPSelfmodifyingResource), null, false); metadata.AddKeyProperty(entityType, "ID", typeof(int)); metadata.AddPrimitiveProperty(entityType, "ETagProperty", typeof(int?), true); metadata.AddPrimitiveProperty(entityType, "TriggerModification", typeof(string)); var entitySet = metadata.AddResourceSet("Items", entityType); metadata.AddResourceReferenceProperty(entityType, "Self", entitySet, entityType); var collectionEntity = metadata.AddEntityType("Collection", null, null, false); metadata.AddKeyProperty(collectionEntity, "ID", typeof(int)); metadata.AddPrimitiveProperty(collectionEntity, "Rating", typeof(int?)); metadata.AddPrimitiveProperty(collectionEntity, "Description", typeof(string)); metadata.AddCollectionProperty(collectionEntity, "CollectionProperty", typeof(int?)); metadata.AddResourceSet("Collection", collectionEntity); var streamEntity = metadata.AddEntityType("Stream", typeof(DSPSelfmodifyingResource), null, false); metadata.AddKeyProperty(streamEntity, "ID", typeof(int)); metadata.AddPrimitiveProperty(streamEntity, "ETagProperty", typeof(int?), true); metadata.AddPrimitiveProperty(streamEntity, "TriggerModification", typeof(string)); streamEntity.IsMediaLinkEntry = true; metadata.AddResourceSet("Streams", streamEntity); var namedStreamEntity = metadata.AddEntityType("NamedStream", typeof(DSPSelfmodifyingResource), null, false); metadata.AddKeyProperty(namedStreamEntity, "ID", typeof(int)); namedStreamEntity.AddProperty(new provider.ResourceProperty("NamedStream1", provider.ResourcePropertyKind.Stream, provider.ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream)))); metadata.AddResourceSet("NamedStreams", namedStreamEntity); return metadata; }
private static DSPMetadata GetModel(bool openType, bool namedStreams, Action<DSPMetadata> metadataModifier = null) { #region Model Definition // Navigation Collection Property: Client - Entity, Server - NonEntity DSPMetadata metadata = new DSPMetadata("ModelWithDerivedNavProperties", "AstoriaUnitTests.Tests"); var peopleType = metadata.AddEntityType("PeopleType", null, null, false); peopleType.IsOpenType = openType; metadata.AddKeyProperty(peopleType, "ID", typeof(int)); if (!openType) { metadata.AddPrimitiveProperty(peopleType, "Name", typeof(string)); } var peopleSet = metadata.AddResourceSet("People", peopleType); var employeeType = metadata.AddEntityType("EmployeeType", null, peopleType, false); if (namedStreams) { metadata.AddNamedStreamProperty(employeeType, "Photo"); } ResourceProperty fullNameProperty = null; if (!openType) { fullNameProperty = new ResourceProperty("FullName", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string))) { CanReflectOnInstanceTypeProperty = false }; employeeType.AddProperty(fullNameProperty); } var managerType = metadata.AddEntityType("ManagerType", null, employeeType, false); var customerType = metadata.AddEntityType("CustomerType", null, peopleType, false); if (namedStreams) { metadata.AddNamedStreamProperty(customerType, "Photo"); } if (!openType) { Assert.IsTrue(fullNameProperty != null, "fullNameProperty != null"); customerType.AddProperty(fullNameProperty); } var baseAddressType = metadata.AddEntityType("AddressType", null, null, false); baseAddressType.IsOpenType = openType; metadata.AddKeyProperty(baseAddressType, "ID", typeof(int)); if (!openType) { metadata.AddPrimitiveProperty(baseAddressType, "Street", typeof(string)); metadata.AddPrimitiveProperty(baseAddressType, "City", typeof(string)); metadata.AddPrimitiveProperty(baseAddressType, "State", typeof(string)); metadata.AddPrimitiveProperty(baseAddressType, "ZipCode", typeof(string)); } var customerAddressType = metadata.AddEntityType("CustomerAddressType", null, baseAddressType, false); var employeeAddressType = metadata.AddEntityType("EmployeeAddressType", null, baseAddressType, false); var addressSet = metadata.AddResourceSet("Addresses", baseAddressType); var drProperty = metadata.AddResourceSetReferenceProperty(managerType, "DirectReports", employeeType); var managerProperty = metadata.AddResourceReferenceProperty(employeeType, "Manager", managerType); metadata.AddResourceAssociationSet(new ResourceAssociationSet( "Manager_DirectReports", new ResourceAssociationSetEnd(peopleSet, employeeType, managerProperty), new ResourceAssociationSetEnd(peopleSet, managerType, drProperty))); var customerAddressProperty = metadata.AddResourceReferenceProperty(customerType, "Address", customerAddressType); metadata.AddResourceAssociationSet(new ResourceAssociationSet( "Customer_Address", new ResourceAssociationSetEnd(peopleSet, customerType, customerAddressProperty), new ResourceAssociationSetEnd(addressSet, customerAddressType, null))); var employeeAddressProperty = metadata.AddResourceReferenceProperty(employeeType, "Address", employeeAddressType); metadata.AddResourceAssociationSet(new ResourceAssociationSet( "Employee_Address", new ResourceAssociationSetEnd(peopleSet, employeeType, employeeAddressProperty), new ResourceAssociationSetEnd(addressSet, employeeAddressType, null))); if (metadataModifier != null) { metadataModifier(metadata); } metadata.SetReadOnly(); #endregion Model Definition return metadata; }
internal static DSPServiceDefinition SetUpNamedStreamService() { DSPMetadata metadata = new DSPMetadata("NamedStreamIDSPContainer", "NamedStreamTest"); // entity with streams ResourceType entityWithNamedStreams = metadata.AddEntityType("EntityWithNamedStreams", null, null, false); metadata.AddKeyProperty(entityWithNamedStreams, "ID", typeof(int)); metadata.AddPrimitiveProperty(entityWithNamedStreams, "Name", typeof(string)); ResourceProperty streamInfo1 = new ResourceProperty("Stream1", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(Stream))); entityWithNamedStreams.AddProperty(streamInfo1); ResourceProperty streamInfo2 = new ResourceProperty("Stream2", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(Stream))); entityWithNamedStreams.AddProperty(streamInfo2); // entity1 with streams ResourceType entityWithNamedStreams1 = metadata.AddEntityType("EntityWithNamedStreams1", null, null, false); metadata.AddKeyProperty(entityWithNamedStreams1, "ID", typeof(int)); metadata.AddPrimitiveProperty(entityWithNamedStreams1, "Name", typeof(string)); ResourceProperty refStreamInfo1 = new ResourceProperty("RefStream1", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(Stream))); entityWithNamedStreams1.AddProperty(refStreamInfo1); // entity2 with streams ResourceType entityWithNamedStreams2 = metadata.AddEntityType("EntityWithNamedStreams2", null, null, false); metadata.AddKeyProperty(entityWithNamedStreams2, "ID", typeof(string)); metadata.AddPrimitiveProperty(entityWithNamedStreams2, "Name", typeof(string)); ResourceProperty collectionStreamInfo = new ResourceProperty("ColStream", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(Stream))); entityWithNamedStreams2.AddProperty(collectionStreamInfo); ResourceSet set1 = metadata.AddResourceSet("MySet1", entityWithNamedStreams); ResourceSet set2 = metadata.AddResourceSet("MySet2", entityWithNamedStreams1); ResourceSet set3 = metadata.AddResourceSet("MySet3", entityWithNamedStreams2); // add navigation property to entityWithNamedStreams metadata.AddResourceReferenceProperty(entityWithNamedStreams, "Ref", set2, entityWithNamedStreams1); metadata.AddResourceSetReferenceProperty(entityWithNamedStreams, "Collection", set3, entityWithNamedStreams2); metadata.AddResourceSetReferenceProperty(entityWithNamedStreams2, "Collection1", set2, entityWithNamedStreams1); DSPServiceDefinition service = new DSPServiceDefinition(); service.Metadata = metadata; service.MediaResourceStorage = new DSPMediaResourceStorage(); service.SupportMediaResource = true; service.SupportNamedStream = true; service.ForceVerboseErrors = true; service.PageSizeCustomizer = (config, type) => { config.SetEntitySetPageSize("MySet3", 1); }; // populate data DSPContext context = new DSPContext(); DSPResource entity1 = new DSPResource(entityWithNamedStreams); { context.GetResourceSetEntities("MySet1").Add(entity1); entity1.SetValue("ID", 1); entity1.SetValue("Name", "Foo"); DSPMediaResource namedStream1 = service.MediaResourceStorage.CreateMediaResource(entity1, streamInfo1); namedStream1.ContentType = "image/jpeg"; byte[] data1 = new byte[] { 0, 1, 2, 3, 4 }; namedStream1.GetWriteStream().Write(data1, 0, data1.Length); DSPMediaResource namedStream2 = service.MediaResourceStorage.CreateMediaResource(entity1, streamInfo2); namedStream2.ContentType = "image/jpeg"; byte[] data2 = new byte[] { 0, 1, 2, 3, 4 }; namedStream2.GetWriteStream().Write(data2, 0, data2.Length); } DSPResource entity2 = new DSPResource(entityWithNamedStreams1); { context.GetResourceSetEntities("MySet2").Add(entity2); entity2.SetValue("ID", 3); entity2.SetValue("Name", "Bar"); DSPMediaResource refNamedStream1 = service.MediaResourceStorage.CreateMediaResource(entity2, refStreamInfo1); refNamedStream1.ContentType = "image/jpeg"; byte[] data1 = new byte[] { 0, 1, 2, 3, 4 }; refNamedStream1.GetWriteStream().Write(data1, 0, data1.Length); // set the navigation property entity1.SetValue("Ref", entity2); } { DSPResource entity3 = new DSPResource(entityWithNamedStreams2); context.GetResourceSetEntities("MySet3").Add(entity3); entity3.SetValue("ID", "ABCDE"); entity3.SetValue("Name", "Bar"); DSPMediaResource stream = service.MediaResourceStorage.CreateMediaResource(entity3, collectionStreamInfo); stream.ContentType = "image/jpeg"; byte[] data1 = new byte[] { 0, 1, 2, 3, 4 }; stream.GetWriteStream().Write(data1, 0, data1.Length); entity3.SetValue("Collection1", new List<DSPResource>() { entity2 }); DSPResource entity4 = new DSPResource(entityWithNamedStreams2); context.GetResourceSetEntities("MySet3").Add(entity4); entity4.SetValue("ID", "XYZ"); entity4.SetValue("Name", "Foo"); DSPMediaResource stream1 = service.MediaResourceStorage.CreateMediaResource(entity3, collectionStreamInfo); stream1.ContentType = "image/jpeg"; stream1.GetWriteStream().Write(data1, 0, data1.Length); entity4.SetValue("Collection1", new List<DSPResource>() { entity2 }); entity1.SetValue("Collection", new List<DSPResource>() { entity3, entity4 }); } service.DataSource = context; return service; }
private static DSPServiceDefinition ModelWithDerivedNavigationProperties() { // Navigation Collection Property: Client - Entity, Server - NonEntity DSPMetadata metadata = new DSPMetadata("ModelWithDerivedNavProperties", "AstoriaUnitTests.Tests.DerivedProperty"); var peopleType = metadata.AddEntityType("Person", null, null, false); metadata.AddKeyProperty(peopleType, "ID", typeof(int)); metadata.AddPrimitiveProperty(peopleType, "Name", typeof(string)); var bestFriendProperty = metadata.AddResourceReferenceProperty(peopleType, "BestFriend", peopleType); var friendsProperty = metadata.AddResourceSetReferenceProperty(peopleType, "Friends", peopleType); var aquaintancesProperty = metadata.AddResourceSetReferenceProperty(peopleType, "Aquaintances", peopleType); var peopleSet = metadata.AddResourceSet("People", peopleType); var officeType = metadata.AddComplexType("Office", null, null, false); metadata.AddPrimitiveProperty(officeType, "Building", typeof(string)); metadata.AddPrimitiveProperty(officeType, "OfficeNumber", typeof(int)); var vacationType = metadata.AddComplexType("Vacation", null, null, false); metadata.AddPrimitiveProperty(vacationType, "Description", typeof(string)); metadata.AddPrimitiveProperty(vacationType, "StartDate", typeof(DateTimeOffset)); metadata.AddPrimitiveProperty(vacationType, "EndDate", typeof(DateTimeOffset)); var employeeType = metadata.AddEntityType("Employee", null, peopleType, false); metadata.AddCollectionProperty(employeeType, "Vacations", vacationType); metadata.AddComplexProperty(employeeType, "Office", officeType); metadata.AddCollectionProperty(employeeType, "Skills", ResourceType.GetPrimitiveResourceType(typeof(string))); metadata.AddNamedStreamProperty(employeeType, "Photo"); var managerType = metadata.AddEntityType("PeopleManager", null, employeeType, false); var drProperty = metadata.AddResourceSetReferenceProperty(managerType, "DirectReports", employeeType); var managerProperty = metadata.AddResourceReferenceProperty(employeeType, "Manager", managerType); var colleaguesProperty = metadata.AddResourceSetReferenceProperty(employeeType, "Colleagues", employeeType); metadata.AddResourceAssociationSet(new ResourceAssociationSet( "Manager_DirectReports", new ResourceAssociationSetEnd(peopleSet, employeeType, managerProperty), new ResourceAssociationSetEnd(peopleSet, managerType, drProperty))); metadata.AddResourceAssociationSet(new ResourceAssociationSet( "BestFriend", new ResourceAssociationSetEnd(peopleSet, peopleType, bestFriendProperty), new ResourceAssociationSetEnd(peopleSet, peopleType, null))); metadata.AddResourceAssociationSet(new ResourceAssociationSet( "Friends", new ResourceAssociationSetEnd(peopleSet, peopleType, friendsProperty), new ResourceAssociationSetEnd(peopleSet, peopleType, null))); metadata.AddResourceAssociationSet(new ResourceAssociationSet( "Colleagues", new ResourceAssociationSetEnd(peopleSet, employeeType, colleaguesProperty), new ResourceAssociationSetEnd(peopleSet, employeeType, null))); metadata.AddResourceAssociationSet(new ResourceAssociationSet( "Aquaintances", new ResourceAssociationSetEnd(peopleSet, peopleType, aquaintancesProperty), new ResourceAssociationSetEnd(peopleSet, peopleType, null))); metadata.SetReadOnly(); DSPContext context = new DSPContext(); DSPResource people1 = new DSPResource(peopleType); people1.SetValue("ID", 1); people1.SetValue("Name", "Foo"); people1.SetValue("Friends", new List<DSPResource>()); DSPResource thanksgivingVacation = new DSPResource(vacationType); thanksgivingVacation.SetValue("Description", "Thanksgiving"); thanksgivingVacation.SetValue("StartDate", new DateTime(2011, 11, 19)); thanksgivingVacation.SetValue("EndDate", new DateTime(2011, 11, 27)); DSPResource christmasVacation = new DSPResource(vacationType); christmasVacation.SetValue("Description", "Christmas"); christmasVacation.SetValue("StartDate", new DateTime(2011, 12, 24)); christmasVacation.SetValue("EndDate", new DateTime(2012, 1, 2)); DSPResource andy = new DSPResource(managerType); andy.SetValue("ID", 2); andy.SetValue("Name", "Andy"); andy.SetValue("Vacations", new List<DSPResource>() { thanksgivingVacation, christmasVacation }); var office = new DSPResource(officeType); office.SetValue("Building", "Building 18"); office.SetValue("OfficeNumber", 100); andy.SetValue("Office", office); andy.SetValue("Skills", new List<string>() { "CSharp", "VB", "SQL" }); andy.SetValue("Friends", new List<DSPResource>() { people1 }); andy.SetValue("Aquaintences", new List<DSPResource>()); DSPResource pratik = new DSPResource(employeeType); pratik.SetValue("ID", 3); pratik.SetValue("Name", "Pratik"); pratik.SetValue("Manager", andy); pratik.SetValue("Vacations", new List<DSPResource>() { christmasVacation }); office = new DSPResource(officeType); office.SetValue("Building", "Building 18"); office.SetValue("OfficeNumber", 101); pratik.SetValue("Office", office); pratik.SetValue("Skills", new List<string>() { "CSharp", "VB", "SQL" }); pratik.SetValue("Friends", new List<DSPResource>() { people1 }); pratik.SetValue("Aquaintences", new List<DSPResource>()); DSPResource jimmy = new DSPResource(employeeType); jimmy.SetValue("ID", 4); jimmy.SetValue("Name", "Jimmy"); jimmy.SetValue("Manager", andy); jimmy.SetValue("Vacations", new List<DSPResource>() { thanksgivingVacation, christmasVacation }); office = new DSPResource(officeType); office.SetValue("Building", "Building 18"); office.SetValue("OfficeNumber", 102); jimmy.SetValue("Office", office); jimmy.SetValue("Skills", new List<string>() { "CSharp", "SQL" }); jimmy.SetValue("Friends", new List<DSPResource>() { people1 }); jimmy.SetValue("Aquaintences", new List<DSPResource>()); andy.SetValue("DirectReports", new List<DSPResource>() { pratik, jimmy }); DSPResource shyam = new DSPResource(managerType); shyam.SetValue("ID", 5); shyam.SetValue("Name", "Shyam"); shyam.SetValue("Manager", shyam); shyam.SetValue("Vacations", new List<DSPResource>() { thanksgivingVacation, christmasVacation }); office = new DSPResource(officeType); office.SetValue("Building", "Building 18"); office.SetValue("OfficeNumber", 103); shyam.SetValue("Office", office); shyam.SetValue("Skills", new List<string>()); shyam.SetValue("Friends", new List<DSPResource>() { people1 }); shyam.SetValue("Aquaintences", new List<DSPResource>()); DSPResource marcelo = new DSPResource(employeeType); marcelo.SetValue("ID", 6); marcelo.SetValue("Name", "Marcelo"); marcelo.SetValue("Manager", shyam); marcelo.SetValue("Vacations", new List<DSPResource>()); office = new DSPResource(officeType); office.SetValue("Building", "Building 18"); office.SetValue("OfficeNumber", 104); marcelo.SetValue("Office", office); marcelo.SetValue("Skills", new List<string>() { "CSharp", "VB", "SQL" }); marcelo.SetValue("Friends", new List<DSPResource>() { people1 }); marcelo.SetValue("Aquaintences", new List<DSPResource>()); andy.SetValue("Manager", shyam); shyam.SetValue("DirectReports", new List<DSPResource>() { andy, marcelo }); pratik.SetValue("BestFriend", andy); andy.SetValue("BestFriend", shyam); shyam.SetValue("BestFriend", marcelo); marcelo.SetValue("BestFriend", jimmy); jimmy.SetValue("BestFriend", people1); people1.SetValue("BestFriend", pratik); andy.SetValue("Colleagues", new List<DSPResource>() { marcelo }); pratik.SetValue("Colleagues", new List<DSPResource>() { jimmy }); jimmy.SetValue("Colleagues", new List<DSPResource>() { pratik }); marcelo.SetValue("Colleagues", new List<DSPResource>() { andy }); shyam.SetValue("Colleagues", new List<DSPResource>()); people1.SetValue("Aquaintances", new List<DSPResource>() { pratik, andy, jimmy, shyam, marcelo }); var people = context.GetResourceSetEntities("People"); people.Add(people1); people.Add(andy); people.Add(pratik); people.Add(jimmy); people.Add(shyam); people.Add(marcelo); DSPServiceDefinition service = new DSPServiceDefinition() { Metadata = metadata, CreateDataSource = (m) => context, ForceVerboseErrors = true, MediaResourceStorage = new DSPMediaResourceStorage(), SupportNamedStream = true, Writable = true, DataServiceBehavior = new OpenWebDataServiceDefinition.OpenWebDataServiceBehavior() { IncludeRelationshipLinksInResponse = true }, }; return service; }