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>());
        }
Exemplo n.º 2
0
        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 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)
            {
            }
        }