Exemplo n.º 1
0
        public void TestAssemblyInspection()
        {
            var inspector = new ModelInspector();

            // Inspect the HL7.Fhir.Model assembly
            inspector.Import(typeof(Resource).Assembly);

            // Check for presence of some basic ingredients
            Assert.IsNotNull(inspector.FindClassMappingForResource("patient"));
            Assert.IsNotNull(inspector.FindClassMappingForFhirDataType("HumanName"));
            Assert.IsNotNull(inspector.FindClassMappingForFhirDataType("code"));
            Assert.IsNotNull(inspector.FindClassMappingForFhirDataType("boolean"));

            // Verify presence of nested enumerations
            Assert.IsNotNull(inspector.FindEnumMappingByType(typeof(Address.AddressUse)));

            // Should have skipped abstract classes
            Assert.IsNull(inspector.FindClassMappingForResource("ComplexElement"));
            Assert.IsNull(inspector.FindClassMappingForResource("Element"));
            Assert.IsNull(inspector.FindClassMappingForResource("Resource"));

            // The open generic Code<> should not be there
            var codeOfT = inspector.FindClassMappingByType(typeof(Code <>));

            Assert.IsNull(codeOfT);
        }
Exemplo n.º 2
0
        private ClassMapping determineElementPropertyType(PropertyMapping mappedProperty, string memberName)
        {
            ClassMapping result = null;

            var typeName = mappedProperty.GetChoiceSuffixFromName(memberName);

            if (String.IsNullOrEmpty(typeName))
            {
                throw Error.Format("Encountered polymorph member {0}, but is does not specify the type used".FormatWith(memberName), _current);
            }

            // Exception: valueResource actually means the element is of type ResourceReference
            if (typeName == "Resource")
            {
                typeName = "Reference";
            }

            // NB: this will return the latest type registered for that name, so supports type mapping/overriding
            // Maybe we should Import the types present on the choice, to make sure they are available. For now
            // assume the caller has Imported all types in the right (overriding) order.
            result = _inspector.FindClassMappingForFhirDataType(typeName);

            if (result == null)
            {
                throw Error.Format("Encountered polymorph member {0}, which uses unknown datatype {1}".FormatWith(memberName, typeName), _current);
            }

            return(result);
        }
        public void TestAssemblyInspection()
        {
            var inspector = new ModelInspector();

            // Inspect the HL7.Fhir.Model assembly
            inspector.Import(typeof(Resource).GetTypeInfo().Assembly);

            // Check for presence of some basic ingredients
            Assert.IsNotNull(inspector.FindClassMappingForResource("patient"));
            Assert.IsNotNull(inspector.FindClassMappingForFhirDataType("HumanName"));
            Assert.IsNotNull(inspector.FindClassMappingForFhirDataType("code"));
            Assert.IsNotNull(inspector.FindClassMappingForFhirDataType("boolean"));

            // Should also have found the abstract classes
            Assert.IsNotNull(inspector.FindClassMappingForFhirDataType("Element"));
            Assert.IsNotNull(inspector.FindClassMappingForResource("Resource"));

            // The open generic Code<> should not be there
            var codeOfT = inspector.FindClassMappingByType(typeof(Code <>));

            Assert.IsNull(codeOfT);
        }
Exemplo n.º 4
0
        public void TypeDataTypeNameResolving()
        {
            var inspector = new ModelInspector();

            inspector.ImportType(typeof(AnimalName));
            inspector.ImportType(typeof(NewAnimalName));

            var result = inspector.FindClassMappingForFhirDataType("animalname");

            Assert.IsNotNull(result);
            Assert.AreEqual(result.NativeType, typeof(NewAnimalName));

            // Validate a mapping for a type will return the newest registration
            result = inspector.FindClassMappingByType(typeof(AnimalName));
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NewAnimalName), result.NativeType);
        }
Exemplo n.º 5
0
        private ClassMapping getMappingForType(PropertyMapping mappedProperty, string memberName, string typeName)
        {
            ClassMapping result = null;

            // NB: this will return the latest type registered for that name, so supports type mapping/overriding
            // Maybe we should Import the types present on the choice, to make sure they are available. For now
            // assume the caller has Imported all types in the right (overriding) order.
            result = _inspector.FindClassMappingForFhirDataType(typeName);

            if (result == null)
            {
                ComplexTypeReader.RaiseFormatError(
                    $"Encountered polymorph member {memberName}, which uses unknown datatype {typeName}", _current.Location);
            }

            return(result);
        }