public void TestReflectMany() { var ods = MetadataReflector.ReflectMetadata(typeof(X)).Types.Values.ToList(); Assert.AreEqual(17, ods.Count); // Make sure all of the other tests pass as well var od = ods.Single(o => o.FullName == "Y"); Assert.AreEqual("Y", od.FullName); Assert.AreEqual(3, od.PropertyDefinitions.Count); var stringA = od.PropertyDefinitions.Single(pd => pd.FullName == "StringA"); Assert.AreEqual("StringA", stringA.FullName); Assert.AreEqual("System.String", stringA.PropertyType); Assert.AreEqual(1, stringA.MaxOccurs); var strings = od.PropertyDefinitions.Single(pd => pd.FullName == "MyStrings"); Assert.AreEqual("MyStrings", strings.FullName); Assert.AreEqual("System.String", strings.PropertyType); Assert.AreEqual(-1, strings.MaxOccurs); var refProp = od.PropertyDefinitions.Single(pd => pd.FullName == "XXX"); Assert.AreEqual("MyX", refProp.PropertyType); Assert.AreEqual(1, refProp.MaxOccurs); }
public void TestRequiresWorks() { var od = MetadataReflector.Define <Xyz>(); var prop = od.PropertyDefinitions.First(); Assert.AreEqual(true, prop.RequiredInActionInput); }
internal static DataEntity ToDataEntity <T>(T a, QueryEntity queryEntity = null) { var assembly = Assembly.GetAssembly(typeof(T)); var m = MetadataReflector.GetAllObjectDefHeaders(assembly); var ods = new ObjDefs(m.Values); return(ToDataEntity(a, queryEntity, ods)); }
internal static KeyValuePair <string, Func <object, object> > BuildGetter(PropertyInfo pi) { var candidate = pi.GetCustomAttribute <PropertyDefinitionAttribute>(); var propDef = MetadataReflector.BuildByMemberInfo(pi, candidate); var prop = propDef as IFullProp; return(new KeyValuePair <string, Func <object, object> >(propDef.Name, x => prop.Get(x))); }
public void TestUseAttributeNameForObjectDefName() { var od = MetadataReflector.Define <X>(); Assert.AreEqual("MyX", od.FullName); Assert.AreEqual(1, od.PropertyDefinitions.Count); Assert.AreEqual("StringA", od.PropertyDefinitions.First().FullName); Assert.AreEqual("System.String", od.PropertyDefinitions.First().PropertyType); }
public void TestToDataEntity() { var ox = new ObjX { Abc = "asdf" }; var o = MetadataReflector.BuildObjectDefHeader(typeof(ObjX)); var enricher = new ObjDefs(new[] { o }); var dataEntity = ObjDefConverter.To(ox, enricher); var objx = ObjDefConverter.From <ObjX>(dataEntity, enricher); Assert.AreEqual(1, dataEntity.Properties.Count); Assert.AreEqual("ObjX", dataEntity.ObjectDefinitionFullName); Assert.AreEqual("asdf", objx.Abc); Assert.AreNotSame(ox, objx); }
public void TestMutuallyRecursieveGettingAndSetting() { var o1 = MetadataReflector.BuildObjectDefHeader(typeof(A)); var o2 = MetadataReflector.BuildObjectDefHeader(typeof(B)); var enricher = new ObjDefs(new[] { o1, o2 }); var dataEntity = ObjDefConverter.To( Helper.MakeA(), enricher); var a = ObjDefConverter.From <A>(dataEntity, enricher); Assert.AreEqual(1, dataEntity.Properties.Count); Assert.AreEqual("A", dataEntity.ObjectDefinitionFullName); Assert.AreEqual("XYZ", a.S); Assert.AreEqual("ABC", a.B.A.S); }
public void TestDefaultPropertyAttributes() { var od = MetadataReflector.Define <TestAllAttributes>(); var p = od.PropertyDefinitions.Single(pd => pd.FullName == "a"); Assert.AreEqual(false, p.RequiredInActionInput, "Default for Required is false."); Assert.AreEqual(true, p.UsedInActionInput, "Default for Input is true."); Assert.AreEqual(true, p.UsedInActionOutput, "Default for Output is true."); Assert.AreEqual(false, p.UsedInLookupCondition, "Default for TargetFilter(LookupCondition) is false."); Assert.AreEqual(false, p.UsedInQueryConstraint, "Default for QueryFilter(QueryConstraint) is false."); Assert.AreEqual(true, p.UsedInQuerySelect, "Default for Selectable is true."); // Questionable -- probably should be false Assert.AreEqual(true, p.UsedInQuerySequence, "Default for Orderable by (QuerySequence) is true."); Assert.AreEqual(string.Empty, p.Description, "Default for Description is an empty string."); Assert.AreEqual(p.FullName, p.Name, "Name always should equal FullName."); Assert.AreEqual(p.FullName, p.Name, "Name always should equal FullName."); Assert.AreEqual(0, p.Size, "Size is 0."); }
public void TestGettingNullLists() { var o1 = MetadataReflector.BuildObjectDefHeader(typeof(A)); var o2 = MetadataReflector.BuildObjectDefHeader(typeof(HasLists)); var ob = MetadataReflector.BuildObjectDefHeader(typeof(B)); var enricher = new ObjDefs(new[] { o1, o2, ob }); var hl = new HasLists { As = null }; var dataEntity = ObjDefConverter.To( hl, enricher); var a = ObjDefConverter.From <HasLists>(dataEntity, enricher); Assert.AreEqual(0, dataEntity.Properties.Count); Assert.AreEqual("HasLists", dataEntity.ObjectDefinitionFullName); Assert.IsTrue(a.As.Count == 0); }
public void TestRecursieveGettingAndSetting() { var oxchild = new Recurser2 { S = "asdf" }; var oxRoot = new Recurser2 { S = "qwer", R = oxchild }; var o = MetadataReflector.BuildObjectDefHeader(typeof(Recurser2)); var enricher = new ObjDefs(new[] { o }); var dataEntity = ObjDefConverter.To(oxRoot, enricher); var objx = ObjDefConverter.From <Recurser2>(dataEntity, enricher); Assert.AreEqual(1, dataEntity.Properties.Count); Assert.AreEqual("Recurser2", dataEntity.ObjectDefinitionFullName); Assert.AreEqual("qwer", objx.S); Assert.AreNotSame(oxRoot, objx); Assert.AreEqual("asdf", objx.R.S); }
public void TestComplexLists() { var o1 = MetadataReflector.BuildObjectDefHeader(typeof(A)); var o2 = MetadataReflector.BuildObjectDefHeader(typeof(HasLists)); var ob = MetadataReflector.BuildObjectDefHeader(typeof(B)); var enricher = new ObjDefs(new[] { o1, o2, ob }); var hl = new HasLists { As = new List <A> { Helper.MakeA() } }; var dataEntity = ObjDefConverter.To(hl, enricher); var a = ObjDefConverter.From <HasLists>(dataEntity, enricher); Assert.AreEqual(0, dataEntity.Properties.Count); Assert.AreEqual("HasLists", dataEntity.ObjectDefinitionFullName); Assert.AreEqual("XYZ", a.As.First().S); Assert.AreEqual("ABC", a.As.First().B.A.S); }
public void TestPropertyCollections() { var od = MetadataReflector.Define <Y>(); Assert.AreEqual("Y", od.FullName); Assert.AreEqual(3, od.PropertyDefinitions.Count); var stringA = od.PropertyDefinitions.Single(pd => pd.FullName == "StringA"); Assert.AreEqual("StringA", stringA.FullName, "The name should be StringA."); Assert.AreEqual("System.String", stringA.PropertyType); Assert.AreEqual(1, stringA.MaxOccurs); var strings = od.PropertyDefinitions.Single(pd => pd.FullName == "MyStrings"); Assert.AreEqual("MyStrings", strings.FullName, "The name should be MyStrings."); Assert.AreEqual("System.String", strings.PropertyType); Assert.AreEqual(-1, strings.MaxOccurs); var refProp = od.PropertyDefinitions.Single(pd => pd.FullName == "XXX"); Assert.AreEqual("MyX", refProp.PropertyType); Assert.AreEqual(1, refProp.MaxOccurs); }
public void TestSupportsUpdate() { var od = MetadataReflector.Define <Y>(); Assert.AreEqual(2, od.SupportedActionFullNames.Count); }
public void TestRecursivePropertyDef() { var x = MetadataReflector.BuildObjectDefHeader(typeof(Recurser)); Assert.AreEqual(1, x.Properties.Values.Count()); }
public Reflector(Assembly assembly) { this.objectDefHeaders = MetadataReflector.GetAllObjectDefHeaders(assembly); this.objDefsEnriched = new ObjDefs(this.objectDefHeaders.Values); this.metadata = MetadataReflector.ReflectMetadata(this.objectDefHeaders); }
public void TestSupportsQuery() { var od = MetadataReflector.Define <X>(); Assert.AreEqual(1, od.SupportedActionFullNames.Count); }
//public static T From<T>(DataEntity de, ObjDefs e) where T : new() //{ // var data = new T(); // // TODO: Consider getting this from the type instead of DataEntity // var od = e.GetOrBuild(de.ObjectDefinitionFullName); // foreach (var property in de.Properties) // { // var propertySetter = od.Properties[property.Key]; // propertySetter?.Set(data, property.Value); // } // foreach (var c in de.Children) // { // var dataEntityProp = od.Properties[c.Key] as IDataEntityProperty; // if (dataEntityProp != null) // { // var dataEntity = c.Value.FirstOrDefault(); // if (dataEntity != null) // { // dataEntityProp.Set(data, dataEntity); // } // } // var dataEntityListProp = od.Properties[c.Key] as IDataEntityListProperty; // if (dataEntityListProp != null) // { // var dataEntity = c.Value; // if (dataEntity != null) // { // dataEntityListProp.Set(data, dataEntity); // } // } // } // return data; //} public static DataEntity To <T>(T data, ObjDefs e, QueryEntity qe = null) { if (data == null) { return(null); } var stub = MetadataReflector.GetObjectDefStubFromType(typeof(T)); var od = e.GetOrBuild(stub.Name); var de = new DataEntity(od.Name); var props = new EntityProperties(); var children = new EntityChildren(); foreach (var keyValuePair in od.Properties) { var name = keyValuePair.Key; var getter = keyValuePair.Value; if (!getter.IsObjectDefProp) { if (qe == null || qe.PropertyList.Contains(name)) { props.Add(name, getter.Get(data)); } } else { var dataEntityGetter = getter as IDataEntityProperty; if (dataEntityGetter != null) { if (qe == null) { var cde = dataEntityGetter.Get(data); var v = cde == null ? new List <DataEntity>() : new List <DataEntity> { cde }; children.Add(name, v); } else { var propQe = qe.ChildList.FirstOrDefault(q => q.Name == name); if (propQe != null) { var cde = dataEntityGetter.Get(data, propQe); var v = cde == null ? new List <DataEntity>() : new List <DataEntity> { cde }; children.Add(name, v); } } } var dataEntityListGetter = getter as IDataEntityListProperty; if (dataEntityListGetter != null) { if (qe == null) { var cde = dataEntityListGetter.Get(data); // Workaround fopr CORE Bug if (cde == null) { cde = new List <DataEntity>(); } children.Add(name, cde); } else { var propQe = qe.ChildList.FirstOrDefault(q => q.Name == name); if (propQe != null) { var cde = dataEntityListGetter.Get(data, propQe); // Workaround fopr CORE Bug if (cde == null) { cde = new List <DataEntity>(); } children.Add(name, cde); } } } } } de.Properties = props; de.Children = children; return(de); }