public void PrimitiveChildMatching() { var boolean = _source.FindStructureDefinitionForCoreType(FHIRDefinedType.Boolean); var boolDefNav = ElementDefinitionNavigator.ForSnapshot(boolean); boolDefNav.MoveToFirstChild(); var data = SourceNode.Valued("active", "true", SourceNode.Node("extension", SourceNode.Valued("value", "4")), SourceNode.Node("nonExistant") ).ToTypedElement(new PocoStructureDefinitionSummaryProvider(), type: "boolean", settings: new TypedElementSettings { ErrorMode = TypedElementSettings.TypeErrorMode.Passthrough }); var matches = ChildNameMatcher.Match(boolDefNav, new ScopedNode(data)); Assert.Single(matches.UnmatchedInstanceElements); Assert.Equal(3, matches.Matches.Count()); // id, extension, value Assert.Empty(matches.Matches[0].InstanceElements); // id Assert.Single(matches.Matches[1].InstanceElements); // extension Assert.Single(matches.Matches[2].InstanceElements); // value Assert.Equal("extension", matches.Matches[1].InstanceElements.First().Name); Assert.Equal("extension", matches.Matches[1].Definition.PathName); Assert.Equal("active", matches.Matches[2].InstanceElements.First().Name); Assert.Equal("value", matches.Matches[2].Definition.PathName); }
public void FromNodeClonesCorrectly() { var child1 = SourceNode.Valued("child1", "a value"); child1.AddAnnotation("The first annotation"); var root = SourceNode.Node("TestRoot", child1); root.ResourceType = "TestR"; var annotationTypes = new[] { typeof(string) }; var copiedRoot = SourceNode.FromNode(root, recursive: false, annotationsToCopy: annotationTypes); Assert.False(copiedRoot.Children().Any()); Assert.Equal(root.Name, copiedRoot.Name); Assert.Equal(root.Location, copiedRoot.Location); Assert.Equal(root.Text, copiedRoot.Text); Assert.Equal(root.ResourceType, copiedRoot.ResourceType); Assert.Null((root as IAnnotated).Annotation <string>()); copiedRoot = SourceNode.FromNode(root, recursive: true, annotationsToCopy: annotationTypes); Assert.True(copiedRoot.Children().Any()); Assert.Null((root as IAnnotated).Annotation <string>()); var copiedChild = copiedRoot.Children().Single(); Assert.False(copiedChild.Children().Any()); Assert.Equal(child1.Name, copiedChild.Name); Assert.Equal(child1.Location, copiedChild.Location); Assert.Equal(child1.Text, copiedChild.Text); Assert.Equal("The first annotation", (copiedChild as IAnnotated).Annotation <string>()); }
internal Base Deserialize(ClassMapping mapping, Base existing = null) { if (mapping == null) { throw Error.ArgumentNull(nameof(mapping)); } if (existing == null) { var fac = new DefaultModelFactory(); existing = (Base)fac.Create(mapping.NativeType); } else { if (mapping.NativeType != existing.GetType()) { throw Error.Argument(nameof(existing), "Existing instance is of type {0}, but data indicates resource is a {1}".FormatWith(existing.GetType().Name, mapping.NativeType.Name)); } } var members = _current.Text != null ? new[] { SourceNode.Valued("value", _current.Text) }.Union(_current.Children()) : _current.Children(); read(mapping, members, existing); return(existing); }
public async Task DocumentOperationCanIncludeCustomResources() { var composition = CreateTestCompositionInclCustomResource(); var compositionSearchResult = new SearchResult(new List <IResource>() { composition }, 1, 1); var customResourceTest = SourceNode.Resource("CustomBasic", "CustomBasic"); customResourceTest.Add(SourceNode.Valued("id", Guid.NewGuid().ToString())); var customResourceSearchResults = new SearchResult(new List <IResource> { customResourceTest.ToIResource(VonkConstants.Model.FhirR3) }, 1, 1); _searchMock.Setup(repo => repo.Search(It.Is <IArgumentCollection>(arg => arg.GetArgument("_type").ArgumentValue.Equals("Composition")), It.IsAny <SearchOptions>())).ReturnsAsync(compositionSearchResult); _searchMock.Setup(repo => repo.Search(It.Is <IArgumentCollection>(arg => arg.GetArgument("_type").ArgumentValue.Equals("CustomBasic")), It.IsAny <SearchOptions>())).ReturnsAsync(customResourceSearchResults); var testContext = new VonkTestContext(VonkInteraction.instance_custom); testContext.Arguments.AddArguments(new[] { new Argument(ArgumentSource.Path, ArgumentNames.resourceType, "Composition"), new Argument(ArgumentSource.Path, ArgumentNames.resourceId, "test") }); testContext.TestRequest.CustomOperation = "document"; testContext.TestRequest.Method = "GET"; await _documentService.DocumentInstanceGET(testContext); testContext.Response.HttpResult.Should().Be(StatusCodes.Status200OK, "$document should return HTTP 200 - OK when all references in the composition (incl. recursive references) can be resolved"); testContext.Response.Payload.SelectNodes("entry.resource").Count().Should().Be(2, "Expected Composition and CustomBasic to be in the document"); }
public void TestDynaBinding() { #pragma warning disable CS0618 // Type or member is internal var input = SourceNode.Node("root", SourceNode.Valued("child", "Hello world!"), SourceNode.Valued("child", "4")).ToTypedElement(); #pragma warning restore CS0618 // Type or member is internal Assert.AreEqual("ello", input.Scalar(@"$this.child[0].substring(1,%context.child[1].toInteger())")); }
public void NameMatching() { var data = SourceNode.Valued("active", "true") .ToTypedElement(new PocoStructureDefinitionSummaryProvider(), "boolean"); Assert.True(ChildNameMatcher.NameMatches("active", data)); Assert.True(ChildNameMatcher.NameMatches("activeBoolean", data)); Assert.False(ChildNameMatcher.NameMatches("activeDateTime", data)); Assert.True(ChildNameMatcher.NameMatches("active[x]", data)); Assert.False(ChildNameMatcher.NameMatches("activate", data)); }
public void ValidateCardinality() { var boolSd = _source.FindStructureDefinitionForCoreType(FHIRDefinedType.Boolean); var data = SourceNode.Valued("active", "true", SourceNode.Valued("id", "myId1"), SourceNode.Valued("id", "myId2"), SourceNode.Node("extension", SourceNode.Valued("valueInteger", "4"))) .ToTypedElement(new PocoStructureDefinitionSummaryProvider(), "boolean"); var report = _validator.Validate(data, boolSd); Assert.Equal(2, report.ListErrors().Count()); }
public ElementNodeTests() { var annotatedNode = SourceNode.Valued("id", "myId1"); (annotatedNode as IAnnotatable).AddAnnotation("a string annotation"); patient = SourceNode.Node("Patient", SourceNode.Resource("contained", "Observation", SourceNode.Valued("valueBoolean", "true")), SourceNode.Valued("active", "true", annotatedNode, SourceNode.Valued("id", "myId2"), SourceNode.Node("extension", SourceNode.Valued("value", "4")), SourceNode.Node("extension", SourceNode.Valued("value", "world!")))); }
private GenericBundle CreateEmptyBundle() { var bundleResourceNode = SourceNode.Resource("Bundle", "Bundle", SourceNode.Valued("type", "searchset")); var identifier = SourceNode.Node("identifier"); identifier.Add(SourceNode.Valued("system", "urn:ietf:rfc:3986")); identifier.Add(SourceNode.Valued("value", Guid.NewGuid().ToString())); bundleResourceNode.Add(identifier); var documentBundle = GenericBundle.FromBundle(bundleResourceNode); documentBundle = documentBundle.Meta(Guid.NewGuid().ToString(), DateTimeOffset.Now); return(documentBundle); }
public void IgnoreElements() { var patient = SourceNode.Resource("Patient", "Patient", SourceNode.Valued("id", "pat1")); var jsonBare = patient.ToTypedElement(new PocoStructureDefinitionSummaryProvider()).ToJson(new FhirJsonSerializationSettings { IgnoreUnknownElements = false }); Assert.IsTrue(jsonBare.Contains("pat1")); patient.Add(SourceNode.Valued("unknownElement", "someValue")); var jsonUnknown = patient.ToTypedElement(new PocoStructureDefinitionSummaryProvider(), settings: new TypedElementSettings { ErrorMode = TypedElementSettings.TypeErrorMode.Ignore }).ToJson(new FhirJsonSerializationSettings { IgnoreUnknownElements = true }); Assert.IsFalse(jsonUnknown.Contains("unknownElement")); }
public void CannotUseAbstractType() { var bundleJson = "{\"resourceType\":\"Bundle\", \"entry\":[{\"fullUrl\":\"http://example.org/Patient/1\"}]}"; var bundle = FhirJsonNode.Parse(bundleJson); var typedBundle = bundle.ToTypedElement(provider, "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(provider, "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; }