示例#1
0
        public void CardinalityTest()
        {
            StructureDefinition s = this.CreateBaseObservation();

            SnapshotCreator.Create(s);
            ElementNode head = ElementNode.Create(s.Snapshot.Element);

            Assert.True(head.Slices.Any() == false);
            Assert.True(head.Children.Count() == 1);

            {
                Assert.True(head.TryGetElementNode("Observation.id", out ElementNode idNode) == true);
                Assert.True(idNode.Element.Min == 0);
                Assert.True(idNode.Element.Max == "1");
                Assert.True(idNode.Element.Base.Min == 0);
                Assert.True(idNode.Element.Base.Max == "1");
            }

            {
                Assert.True(head.TryGetElementNode("Observation.meta", out ElementNode metaNode) == true);
                Assert.True(metaNode.Element.Min == 0);
                Assert.True(metaNode.Element.Max == "1");
                Assert.True(metaNode.Element.Base.Min == 0);
                Assert.True(metaNode.Element.Base.Max == "1");
            }
            {
                Assert.True(head.TryGetElementNode("Observation.status", out ElementNode statusNode) == true);
                Assert.True(statusNode.Element.Min == 1);
                Assert.True(statusNode.Element.Max == "1");
                Assert.True(statusNode.Element.Base.Min == 1);
                Assert.True(statusNode.Element.Base.Max == "1");
            }
        }
示例#2
0
        public void should_set_value(string value, string expectedElement)
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options);

            node.Add("Hai", NodeType.Value, Metadata.Empty, x => x.Value = value);
            node.Encode().ShouldEqual(Declaration + "<Oh>{0}</Oh>".ToFormat(expectedElement));
        }
示例#3
0
        public void should_set_attribute_value_when_a_value_and_configured()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options.Create(x => x.Serialization(y => y.XmlValuesAsAttributes())));

            node.Add("Hai", NodeType.Value, Metadata.Empty, x => x.Value = "There");
            node.Encode().ShouldEqual(Declaration + "<Oh Hai=\"There\" />");
        }
示例#4
0
        public void should_set_boolean_value_as_lower_case()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options);

            node.Add("Hai", NodeType.Value, Metadata.Empty, x => x.Value = true);
            node.Encode().ShouldEqual(Declaration + "<Oh><Hai>true</Hai></Oh>");
        }
示例#5
0
        public void should_omit_xml_element()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty,
                                          Options.Create(x => x.Serialization(y => y.OmitXmlDeclaration())));

            node.Encode().ShouldEqual("<Oh />");
        }
示例#6
0
        public void should_not_set_attribute_value_when_not_a_value_and_configured(NodeType type)
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options.Create(x => x.Serialization(y => y.XmlValuesAsAttributes())));

            node.Add("Hai", type, Metadata.Empty, x => { });
            node.Encode().ShouldEqual(Declaration + "<Oh><Hai /></Oh>");
        }
示例#7
0
 public void BreastAbnormalityTest()
 {
     FhirJsonParser      fjp      = new FhirJsonParser();
     String              jsonText = File.ReadAllText(@"TestFiles\breastrad-BreastAbnormality.json");
     StructureDefinition s        = fjp.Parse <StructureDefinition>(jsonText);
     ElementNode         head     = ElementNode.Create(s.Snapshot.Element);
 }
示例#8
0
        public void should_set_default_namespace()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options.Create(x => x.Serialization(y => y
                                                                                                    .WithDefaultXmlNamespace("http://namespace.org"))));

            node.Add("Hai", NodeType.Value, Metadata.Empty, x => x.Value = "There");
            node.Encode().ShouldEqual(Declaration + "<Oh xmlns=\"http://namespace.org\"><Hai>There</Hai></Oh>");
        }
示例#9
0
        public void should_set_default_namespace_with_value_attributes()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options.Create(x => x.Serialization(y => y
                                                                                                    .WithDefaultXmlNamespace("http://namespace.org").XmlValuesAsAttributes())));

            node.Add("Hai", NodeType.Value, Metadata.Empty, x => x.Value = "There");
            node.Encode().ShouldEqual(Declaration + "<Oh Hai=\"There\" xmlns=\"http://namespace.org\" />");
        }
示例#10
0
        public void should_set_namespace_prefix_from_xml_attribute(Attribute attribute)
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options.Create(x => x.Serialization(y => y
                                                                                                    .AddXmlNamespace("abc", "http://namespace.org"))));

            node.Add("Hai", NodeType.Value, new Metadata(attribute), x => { });
            node.Encode().ShouldEqual(Declaration + "<Oh xmlns:abc=\"http://namespace.org\"><abc:Hai /></Oh>");
        }
示例#11
0
        public void should_add_items_to_parent_when_passed_xml_siblings_attribute()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options);

            node.ShouldExecuteCallback <INode>(
                (x, c) => x.Add("Hai", NodeType.Value, new Metadata(new XmlSiblingsAttribute()), c),
                x => x.ShouldBeSameAs(node));
        }
示例#12
0
        public void should_pretty_print()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty,
                                          Options.Create(x => x.Serialization(y => y.PrettyPrint())));

            node.Add("Hai", NodeType.Value, Metadata.Empty, x => { });
            node.Encode().ShouldEqual(Declaration +
                                      "\r\n<Oh>\r\n" +
                                      "\t<Hai />\r\n" +
                                      "</Oh>");
        }
示例#13
0
        public void should_insert_xml_element()
        {
            var parent = ElementNode.Create("Oh", Metadata.Empty, Options);
            var node   = ElementNode.Create("Hai", Metadata.Empty, Options);

            parent.ShouldNotExecuteCallback <INode>((s, c) => s.Add(node, c));
            var child = parent.Cast <ElementNode>().First();

            child.Element.Name.ShouldEqual(node.Element.Name);
            child.Parent.ShouldBeSameAs(parent);
        }
示例#14
0
        public void should_add_and_set_namespace()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options.Create());

            node.Add("Hai", NodeType.Value, Metadata.Empty, x =>
            {
                x.Value = "There";
                x.As <XmlNodeBase>().SetNamespace("http://namespace.org");
            });
            node.Encode().ShouldEqual(Declaration + "<Oh><Hai xmlns=\"http://namespace.org\">There</Hai></Oh>");
        }
示例#15
0
        public void should_insert_xml_attribute()
        {
            var parent = ElementNode.Create("Oh", Metadata.Empty, Options);
            var node   = new AttributeNode(new XAttribute("Hai", "yada"), (ElementNode)parent, Options);

            parent.ShouldNotExecuteCallback <INode>((s, c) => s.Add(node, c));
            var child = parent.Cast <AttributeNode>().First();

            child.Attribute.Name.ShouldEqual(node.Attribute.Name);
            child.Attribute.Value.ShouldEqual(node.Attribute.Value);
            child.Parent.ShouldBeSameAs(parent);
        }
示例#16
0
        public void should_add_and_set_namespace_prefix()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options.Create(x => x.Serialization(y => y
                                                                                                    .AddXmlNamespace("abc", "http://namespace.org"))));

            node.Add("Hai", NodeType.Value, Metadata.Empty, x =>
            {
                x.Value = "There";
                x.As <XmlNodeBase>().SetNamespacePrefix("abc");
            });
            node.Encode().ShouldEqual(Declaration + "<Oh xmlns:abc=\"http://namespace.org\"><abc:Hai>There</abc:Hai></Oh>");
        }
示例#17
0
        public void should_add_and_set_namespace()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options.Create(x => x
                                                                               .Serialization(y => y.XmlValuesAsAttributes())));

            node.Add("Hai", NodeType.Value, Metadata.Empty, x =>
            {
                x.Value = "There";
                x.As <XmlNodeBase>().SetNamespace("http://namespace.org");
            });
            node.Encode().ShouldEqual(Declaration + "<Oh p1:Hai=\"There\" xmlns:p1=\"http://namespace.org\" />");
        }
示例#18
0
        public void should_add_named_node_as_element()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options);

            node.ShouldExecuteCallback <INode>(
                (x, c) => x.Add("Hai", NodeType.Value, Metadata.Empty, c),
                x =>
            {
                x.ShouldBeType <ElementNode>();
                x.Name.ShouldEqual("Hai");
                x.NodeType.ShouldEqual(NodeType.Variable);
                x.Parent.ShouldBeSameAs(node);
            });
        }
示例#19
0
        public void should_add_named_node_as_attribute_when_passed_system_xml_attribute_attribute()
        {
            var node = ElementNode.Create("Oh", Metadata.Empty, Options);

            node.ShouldExecuteCallback <INode>(
                (x, c) => x.Add("Hai", NodeType.Value, new Metadata(new System.Xml.Serialization.XmlAttributeAttribute()), c),
                x =>
            {
                x.ShouldBeType <AttributeNode>();
                x.Name.ShouldEqual("Hai");
                x.NodeType.ShouldEqual(NodeType.Value);
                x.Parent.ShouldBeSameAs(node);
            });
        }
示例#20
0
        public void SliceDiscriminatorTest()
        {
            StructureDefinition s = this.CreateBaseObservation();
            ElementDefinition   e = new ElementDefinition
            {
                ElementId = "Observation.component",
                Path      = "Observation.component",
                Slicing   = new ElementDefinition.SlicingComponent
                {
                    ElementId = "5",
                    Ordered   = false,
                    Rules     = ElementDefinition.SlicingRules.Open
                }
            };

            e.Slicing.Discriminator.Add(new ElementDefinition.DiscriminatorComponent
            {
                Type = ElementDefinition.DiscriminatorType.Value,
                Path = "code.coding.code"
            });
            s.Differential.Element.Add(e);

            SnapshotCreator.Create(s);
            ElementNode head = ElementNode.Create(s.Snapshot.Element);

            Assert.True(head.Slices.Any() == false);
            Assert.True(head.Children.Count() == 1);

            Assert.True(head.TryGetElementNode("Observation.component", out ElementNode observationComponent) == true);
            Assert.True(observationComponent.Path == "Observation.component");
            Assert.True(observationComponent.Slices.Any() == false);
            Assert.True(observationComponent.Element.Slicing.ElementId == "5");
            Assert.True(observationComponent.Element.Slicing.Ordered == false);
            Assert.True(observationComponent.Element.Slicing.Rules == ElementDefinition.SlicingRules.Open);
            Assert.True(observationComponent.Element.Slicing.Discriminator.Count == 1);
            Assert.True(observationComponent.Element.Slicing.Discriminator[0].Type == ElementDefinition.DiscriminatorType.Value);
            Assert.True(observationComponent.Element.Slicing.Discriminator[0].Path == "code.coding.code");
        }
示例#21
0
        public void Setup()
        {
            var json = File.ReadAllText(@"../../Performance/model.json");

            _jsonNode = new JsonNode(json);

            Enumerable.Range(0, 10).ForEach(x =>
            {
                _object = Bender.Deserializer.Create().Deserialize(_jsonNode, typeof(Model <string>));
                Bender.Serializer.Create().SerializeNodes(_object, (n, o) =>
                                                          new JsonNode(n.NodeType, new Options()), JsonNode.NodeFormat);
            });

            var xml = File.ReadAllText(@"../../Performance/model.xml");

            _xmlNode = ElementNode.Parse(xml, Options.Create());

            Enumerable.Range(0, 10).ForEach(x =>
            {
                _object = Bender.Deserializer.Create().Deserialize(_xmlNode, typeof(Model <string>));
                Bender.Serializer.Create().SerializeNodes(_object, (n, o) =>
                                                          ElementNode.Create(n.Name, Metadata.Empty, Options.Create()), XmlNodeBase.NodeFormat);
            });
        }
示例#22
0
        // Bytes

        public byte[] SerializeXmlBytes(object source, Encoding encoding = null)
        {
            return(SerializeBytes(source, (s, o) => ElementNode.Create(s.Name, s.Metadata, o), XmlNodeBase.NodeFormat, encoding));
        }
示例#23
0
 public Stream SerializeXmlStream(object source, Type type, Encoding encoding = null)
 {
     return(SerializeStream(source, type, (s, o) => ElementNode.Create(s.Name, s.Metadata, o), XmlNodeBase.NodeFormat, encoding));
 }
示例#24
0
        // To Stream

        public void SerializeXmlStream(object source, Stream stream, Encoding encoding = null)
        {
            SerializeStream(source, (s, o) => ElementNode.Create(s.Name, s.Metadata, o), XmlNodeBase.NodeFormat, stream, encoding);
        }
示例#25
0
 public void profile_serialize_xml()
 {
     _xmlNode = Bender.Serializer.Create().SerializeNodes(_object, (n, o) =>
                                                          ElementNode.Create(n.Name, Metadata.Empty, Options.Create()), XmlNodeBase.NodeFormat);
 }
示例#26
0
 public string SerializeXml(object source, Type type)
 {
     return(SerializeString(source, type, (s, o) => ElementNode.Create(s.Name, s.Metadata, o), XmlNodeBase.NodeFormat));
 }
示例#27
0
 public void SerializeXmlFile(object source, Type type, string path, Encoding encoding = null)
 {
     SerializeStream(source, type, (s, o) => ElementNode.Create(s.Name, s.Metadata, o), XmlNodeBase.NodeFormat, encoding).SaveToFile(path);
 }
示例#28
0
 public ElementNode SerializeXmlNodes(object source, Type type)
 {
     return((ElementNode)SerializeNodes(source, type, (s, o) => ElementNode.Create(s.Name, s.Metadata, o), XmlNodeBase.NodeFormat));
 }
示例#29
0
        public void SliceTest()
        {
            StructureDefinition s = this.CreateBaseObservation();

            {
                ElementDefinition e = new ElementDefinition
                {
                    ElementId = "Observation.code.coding",
                    Path      = "Observation.code.coding",
                    Min       = 0,
                    Max       = "*",
                    Slicing   = new ElementDefinition.SlicingComponent
                    {
                        ElementId = "4",
                        Ordered   = false,
                        Rules     = ElementDefinition.SlicingRules.Open
                    }
                };
                e.Slicing.Discriminator.Add(new ElementDefinition.DiscriminatorComponent
                {
                    Type = ElementDefinition.DiscriminatorType.Value,
                    Path = "code"
                });
                s.Differential.Element.Add(e);
            }

            {
                ElementDefinition e = new ElementDefinition
                {
                    ElementId = "Observation.code.coding:Slice",
                    SliceName = "Slice",
                    Path      = "Observation.code.coding",
                    Min       = 1,
                    Max       = "1"
                };
                e.Type.Add(new ElementDefinition.TypeRefComponent {
                    Code = "Coding"
                });
                s.Differential.Element.Add(e);
            }


            {
                ElementDefinition e = new ElementDefinition
                {
                    ElementId = "Observation.code.coding:Slice.system",
                    Path      = "Observation.code.coding.system",
                    Min       = 0,
                    Max       = "1",
                    Fixed     = new FhirUri("http://hl7.org/fhir/us/breast-radiology/CodeSystem/breastrad-BreastAbnormalityCodesCS")
                };
                e.Type.Add(new ElementDefinition.TypeRefComponent {
                    Code = "code"
                });
                s.Differential.Element.Add(e);
            }

            {
                ElementDefinition e = new ElementDefinition
                {
                    ElementId = "Observation.code.coding:Slice.code",
                    Path      = "Observation.code.coding.code",
                    Min       = 0,
                    Max       = "1",
                    Fixed     = new Code("BreastAbnormalityObservationCode")
                };
                e.Type.Add(new ElementDefinition.TypeRefComponent {
                    Code = "code"
                });
                s.Differential.Element.Add(e);
            }

            SnapshotCreator.Create(s);
            ElementNode head = ElementNode.Create(s.Snapshot.Element);

            Assert.True(head.Slices.Any() == false);
            Assert.True(head.Children.Count() == 1);

            Assert.True(head.TryGetElementNode("Observation.code.coding", out ElementNode coding) == true);
            Assert.True(coding.Slices.Count() == 1);

            Assert.True(head.TryGetElementNode("Observation.code.coding:Slice.code", out coding) == true);
        }
示例#30
0
        public void Setup()
        {
            var benchmarks = new Benchmarks
            {
                // Json

                new BenchmarkSerializer(Benchmarks.BenderSerializer, Format.Json,
                                        x => new JsonNode(x),
                                        (n, t) => Bender.Deserializer.Create().Deserialize(n, t),
                                        x => Bender.Serializer.Create().SerializeNodes(x, (n, o) =>
                                                                                       new JsonNode(n.NodeType, new Options()), JsonNode.NodeFormat),
                                        x => x.Encode().ReadToEnd()),

                new BenchmarkSerializer("JavaScriptSerializer", Format.Json,
                                        (s, t) => new JavaScriptSerializer().Deserialize(s, t),
                                        x => new JavaScriptSerializer().Serialize(x)),

                new BenchmarkSerializer("DataContractJsonSerializer", Format.Json,
                                        (s, t) => new DataContractJsonSerializer(t).Deserialize(s, t),
                                        x => new DataContractJsonSerializer(x.GetType()).Serialize(x)),

                new BenchmarkSerializer("JSON.NET", Format.Json,
                                        JsonConvert.DeserializeObject,
                                        JsonConvert.SerializeObject),

                new BenchmarkSerializer("ServiceStack", Format.Json,
                                        JsonSerializer.DeserializeFromString,
                                        JsonSerializer.SerializeToString),

                new BenchmarkSerializer("fastJSON", Format.Json,
                                        (s, t) => JSON.Instance.ToObject(s, t),
                                        x => JSON.Instance.ToJSON(x, new JSONParameters {
                    UseExtensions = false
                })),

                // Xml

                new BenchmarkSerializer(Benchmarks.BenderSerializer, Format.Xml,
                                        x => ElementNode.Parse(x, Options.Create()),
                                        (n, t) => Bender.Deserializer.Create().Deserialize(n, t),
                                        x => Bender.Serializer.Create().SerializeNodes(x, (n, o) =>
                                                                                       ElementNode.Create(n.Name, Metadata.Empty, Options.Create()), XmlNodeBase.NodeFormat),
                                        x => x.Encode().ReadToEnd()),

                new BenchmarkSerializer("XmlSerializer", Format.Xml,
                                        (s, t) => new XmlSerializer(t).Deserialize(s, t),
                                        x => new XmlSerializer(x.GetType()).Serialize(x)),

                new BenchmarkSerializer("DataContractSerializer", Format.Xml,
                                        (s, t) => new DataContractSerializer(t).Deserialize(s, t),
                                        x => new DataContractSerializer(x.GetType()).Serialize(x)),

                new BenchmarkSerializer("ServiceStack", Format.Xml,
                                        ServiceStack.Text.XmlSerializer.DeserializeFromString,
                                        ServiceStack.Text.XmlSerializer.SerializeToString)
            };

            benchmarks.Run(typeof(Model <>), Format.Xml, "Performance/model.xml");
            benchmarks.Run(typeof(Model <>), Format.Json, "Performance/model.json");

            const string benchmarkPath = "Performance/Benchmarks/";

            Console.Write(benchmarks.GetTextSummaryReport());
            Console.WriteLine();
            Console.Write(benchmarks.GetTextDetailReport());
            Console.WriteLine();
            Console.Write(benchmarks.GetTextDetailReport(benchmarkPath + "Report.Detail.txt"));

            benchmarks.SaveSummaryGraph(benchmarkPath + "All.png");
            benchmarks.SaveSummaryGraph(benchmarkPath + "Cold.png", warm: false);
            benchmarks.SaveSummaryGraph(benchmarkPath + "Warm.png", false);

            benchmarks.SaveJsonSummaryReport(benchmarkPath + "Report.json");
            benchmarks.SaveTextSummaryReport(benchmarkPath + "Report.txt");
            benchmarks.SaveTextDetailReport(benchmarkPath + "Report.Detail.txt");

            var results = benchmarks.GetResults().OrderBy(x => x.Name).ToList();

            _xmlResults  = results.Where(x => x.Format == Format.Xml).ToList();
            _jsonResults = results.Where(x => x.Format == Format.Json).ToList();
        }