public void AnnotationsFromParsingTest() { var _sdsProvider = new PocoStructureDefinitionSummaryProvider(); var patientJson = "{\"resourceType\":\"Patient\", \"active\":\"true\"}"; var patient = FhirJsonNode.Parse(patientJson); var typedPatient = patient.ToTypedElement(_sdsProvider, "Patient"); var sourceNode = typedPatient.ToSourceNode(); var result = patient.Annotation <ISourceNode>(); Assert.IsNotNull(result); Assert.AreEqual(typeof(FhirJsonNode), result.GetType(), "ISourceNode is provided by FhirJsonNode"); Assert.AreSame(patient, result); var result2 = sourceNode.Annotation <ISourceNode>(); Assert.IsNotNull(result2); Assert.AreEqual(typeof(TypedElementToSourceNodeAdapter), result2.GetType(), "Now ISourceNode is provided by TypedElementToSourceNodeAdapter"); Assert.AreSame(sourceNode, result2); var result3 = sourceNode.Annotation <IResourceTypeSupplier>(); Assert.IsNotNull(result3); Assert.AreEqual(typeof(TypedElementToSourceNodeAdapter), result3.GetType()); }
internal PocoElementNode(Base root, string rootName = null) { Current = root; _mySD = (PocoComplexTypeSerializationInfo)PocoStructureDefinitionSummaryProvider.Provide(Current.GetType()); InstanceType = InstanceType = ModelInfo.IsProfiledQuantity(root.TypeName) ? "Quantity" : root.TypeName; Definition = Specification.ElementDefinitionSummary.ForRoot(_mySD, rootName ?? root.TypeName); Location = InstanceType; ShortPath = InstanceType; }
private PocoElementNode(Base instance, PocoElementNode parent, IElementDefinitionSummary definition, string location, string shortPath) { Current = instance; _mySD = (PocoComplexTypeSerializationInfo)PocoStructureDefinitionSummaryProvider.Provide(Current.GetType()); InstanceType = determineInstanceType(Current, definition); Definition = definition ?? throw Error.ArgumentNull(nameof(definition)); ExceptionHandler = parent.ExceptionHandler; Location = location; ShortPath = shortPath; }
internal PocoElementNode(Base parent, PocoStructureDefinitionSummaryProvider provider, string rootName = null) { Current = parent; InstanceType = parent.TypeName; var typeInfo = provider.Provide(parent.GetType()); Definition = Specification.ElementDefinitionSummary.ForRoot(rootName ?? parent.TypeName, typeInfo); Location = InstanceType; ShortPath = InstanceType; ArrayIndex = 0; Provider = provider; }
public void SummaryData() { var tpXml = File.ReadAllText(Path.Combine("TestData", "mask-text.xml")); var typeinfo = new PocoStructureDefinitionSummaryProvider().Provide("ValueSet"); var nav = new ScopedNode(getXmlNode(tpXml)); var masker = MaskingNode.ForData(nav); var output = masker.ToXml(); var maskedChildren = masker.Descendants().Count(); Assert.AreEqual(nav.Descendants().Count() - 3, maskedChildren); }
private PocoElementNode(object instance, PocoElementNode parent, string location, string shortPath, int arrayIndex, IElementDefinitionSummary summary) { Current = instance; InstanceType = determineInstanceType(instance, summary); Provider = parent.Provider; ExceptionHandler = parent.ExceptionHandler; Definition = summary; Location = location; ShortPath = shortPath; ArrayIndex = arrayIndex; Provider = parent.Provider; }
public void Summary() { var tpXml = File.ReadAllText(Path.Combine("TestData", "fp-test-patient.xml")); var typeinfo = new PocoStructureDefinitionSummaryProvider().Provide("Patient"); var inSummary = typeinfo.GetElements().Where(e => e.InSummary).ToList(); var nav = new ScopedNode(getXmlNode(tpXml)); var masker = MaskingNode.ForSummary(nav); var output = masker.ToXml(); var maskedChildren = masker.Children().ToList(); Assert.IsTrue(maskedChildren.Count < inSummary.Count); Assert.IsTrue(maskedChildren.Select(c => c.Name).All(c => inSummary.Any(s => s.ElementName == c))); }
public void SourceNodeFromElementNodeReturnsResourceTypeSupplier() { var _sdsProvider = new PocoStructureDefinitionSummaryProvider(); var patientJson = "{\"resourceType\":\"Patient\", \"active\":\"true\"}"; var patientNode = FhirJsonNode.Parse(patientJson); var typedPatient = patientNode.ToTypedElement(_sdsProvider, "Patient"); var elementNode = ElementNode.FromElement(typedPatient); var adapter = elementNode.ToSourceNode(); Assert.AreEqual(typeof(TypedElementToSourceNodeAdapter), adapter.GetType(), "ISourceNode is provided by TypedElementToSourceNodeAdapter"); var result = adapter.Annotation <IResourceTypeSupplier>(); Assert.IsNotNull(result); Assert.AreEqual(typeof(TypedElementToSourceNodeAdapter), result.GetType()); Assert.AreEqual("Patient", adapter.GetResourceTypeIndicator()); Assert.AreSame(adapter, result); }
public void CannotUseAbstractType() { var _sdsProvider = new PocoStructureDefinitionSummaryProvider(); var bundleJson = "{\"resourceType\":\"Bundle\", \"entry\":[{\"fullUrl\":\"http://example.org/Patient/1\"}]}"; var bundle = FhirJsonNode.Parse(bundleJson); var typedBundle = bundle.ToTypedElement(_sdsProvider, "Bundle"); //Type of entry is BackboneElement, but you can't set that, see below. Assert.Equal("BackboneElement", typedBundle.Select("$this.entry[0]").First().InstanceType); var entry = SourceNode.Node("entry", SourceNode.Valued("fullUrl", "http://example.org/Patient/1")); try { var typedEntry = entry.ToTypedElement(_sdsProvider, "Element"); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Fail("Should have thrown on invalid Div format"); } catch (ArgumentException) { } }
public void CanUseBackboneTypeForEntry() { var _sdsProvider = new PocoStructureDefinitionSummaryProvider(); var bundleJson = "{\"resourceType\":\"Bundle\", \"entry\":[{\"fullUrl\":\"http://example.org/Patient/1\"}]}"; var bundle = FhirJsonNode.Parse(bundleJson); var typedBundle = bundle.ToTypedElement(_sdsProvider, "Bundle"); //Type of entry is BackboneElement, but you can't set that, see below. Assert.Equal("BackboneElement", typedBundle.Select("$this.entry[0]").First().InstanceType); var entry = SourceNode.Node("entry", SourceNode.Valued("fullUrl", "http://example.org/Patient/1")); //What DOES work: var typedEntry = entry.ToTypedElement(_sdsProvider, "Element"); //But you can't use BackboneElement here, see below. Assert.Equal("Element", typedEntry.InstanceType); //But this leads to a System.ArgumentException: //Type BackboneElement is not a mappable Fhir datatype or resource //Parameter name: type typedEntry = entry.ToTypedElement(_sdsProvider, "BackboneElement"); Assert.Equal("BackboneElement", typedEntry.InstanceType); // Expected to be able to use BackboneElement as type for the entry SourceNode; }