Example #1
0
        public void null_values_are_propagated()
        {
            var customer = new Customer();
            var textbox  = XHtml.TextBox(() => customer.FirstName);

            textbox.Value.ShouldBeNull();
        }
Example #2
0
        public void the_property_type_is_set_to_text()
        {
            var customer = (new Customer {
                FirstName = "John"
            });
            var textbox  = XHtml.TextBox(() => customer.FirstName);

            textbox.Type.ShouldBe(InputType.Text);
        }
Example #3
0
        public void the_property_name_is_written_correctly()
        {
            var customer = new Customer {
                FirstName = "John"
            };
            var textbox = XHtml.TextBox(() => customer.FirstName);

            textbox.Name.ShouldBe("Customer.FirstName");
        }
Example #4
0
        public void a_nullable_enum_property_sets_to_null_selects_an_empty_option_element_in_first_position()
        {
            var target = new Test();
            var select = XHtml.Select(() => target.NullableEnum);

            select.Name.ShouldBe("Test.NullableEnum");
            select.ChildNodes.Cast <IOptionElement>().SingleOrDefault(x => x.InnerText == "")
            .ShouldNotBeNull()
            .Selected.ShouldBeTrue();
            select.ChildNodes.Count.ShouldBe(Enum.GetNames(typeof(AttributeTargets)).Length + 1);
        }
        /// <summary>
        /// Parse Narrative
        /// </summary>
        public static Hl7.Fhir.Model.Narrative ParseNarrative(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Narrative existingInstance = null)
        {
            Hl7.Fhir.Model.Narrative result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Narrative();
            string currentElementName       = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element status
                else if (atName == "status")
                {
                    result.StatusElement = CodeParser.ParseCode <Hl7.Fhir.Model.Narrative.NarrativeStatus>(reader, errors);
                }

                // Parse element div
                else if (atName == "div")
                {
                    result.DivElement = XHtml.Parse(reader.ReadPrimitiveContents(typeof(XHtml)));
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
Example #6
0
        [Test] public void a_checkbox_has_the_value_specified_in_the_property()
        {
            var target = new Test {
                IsSelected = true
            };
            var checkbox = XHtml.CheckBox(() => target.IsSelected);

            checkbox.Type.ShouldBe(InputType.CheckBox);
            checkbox.Checked.ShouldBeTrue();
            checkbox.Name.ShouldBe("Test.IsSelected");
            checkbox.ToString().ShouldContain("<input type=\"checkbox\"");
        }
Example #7
0
        public void an_enum_property_gets_enumeration_values_set()
        {
            var target = new Test {
                Enum = AttributeTargets.All
            };
            var select = XHtml.Select(() => target.Enum);

            select.Name.ShouldBe("Test.Enum");
            select.ChildNodes.Cast <IOptionElement>().SingleOrDefault(x => x.InnerText == "All")
            .ShouldNotBeNull()
            .Selected.ShouldBeTrue();
            select.ChildNodes.Count.ShouldBe(Enum.GetNames(typeof(AttributeTargets)).Length);
        }
Example #8
0
        public void the_correct_html_fragment_is_generated()
        {
            var customer = new Customer {
                FirstName = "John"
            };
            var textbox = XHtml.TextBox(() => customer.FirstName);

            textbox.OuterXml.ShouldContain("<input", Case.Sensitive);
            textbox.OuterXml.ShouldContain("type=\"text\"", Case.Sensitive);
            textbox.OuterXml.ShouldContain("value=\"John\"", Case.Sensitive);
            textbox.OuterXml.ShouldContain("name=\"Customer.FirstName\"", Case.Sensitive);
            textbox.OuterXml.ShouldContain("/>", Case.Sensitive);
        }
Example #9
0
        public void Process(HtmlConvertPipelineArgs args)
        {
            if (string.IsNullOrEmpty(args.InputText))
            {
                return;
            }
            using (var scope = AutofacConfig.ServiceLocator.BeginLifetimeScope())
            {
                var charMap = scope.Resolve <ISpecialCharacterMapper>();
                var parser  = new CustomHtmlNodeParser {
                    SpecialCharacterMapper = charMap
                };

                parser.ParseNode(XHtml.LoadHtmlDocument(args.InputText, false).DocumentNode, args.OutputXml, args.ParseContext,
                                 null);
            }
        }
Example #10
0
        public void a_dictionary_is_rendered_as_options()
        {
            var t      = new Test();
            var select = XHtml.Select(() => t.Enum,
                                      new Dictionary <string, string> {
                { "key1", "value1" }, { "key2", "value2" }
            });
            var first = select.ChildNodes[0].ShouldBeOfType <IOptionElement>();

            first.InnerText.ShouldBe("value1");
            first.Value.ShouldBe("key1");

            var second = select.ChildNodes[1].ShouldBeOfType <IOptionElement>();

            second.InnerText.ShouldBe("value2");
            second.Value.ShouldBe("key2");
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(ValidationResult.Success);
            }

            if (value.GetType() != typeof(string))
            {
                throw new ArgumentException("CodePatternAttribute can only be applied to string properties");
            }

            if (XHtml.IsValidValue(value as string))
            {
                return(ValidationResult.Success);
            }
            else
            {
                return(DotNetAttributeValidation.BuildResult(validationContext, "Xml can not be parsed or is not valid according to the (limited) FHIR scheme"));
            }
        }
        public void ToStringTest()
        {
            const string _xml =
            @"<?xml version=""1.0"" encoding=""utf-8""?>
            <!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
            <html lang=""ja-JP"" xml:lang=""ja-JP"" xmlns=""http://www.w3.org/1999/xhtml"">
            <head>
            <meta http-equiv=""content-type"" content=""text/html; charset=utf-8"" />
            <meta http-equiv=""content-style-type"" content=""text/css; charset=utf-8"" />
            <title>title1</title>
            <style type=""text/css""> </style>
            </head>
            <body />
            </html>";

            var html = new XHtml();
            Assert.AreEqual(_xml, html.ToString());
        }
        public void Test1()
        {
            const string _xml =
            @"<?xml version=""1.0"" encoding=""utf-8""?>
            <!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
            <html lang=""ja-JP"" xml:lang=""ja-JP"" xmlns=""http://www.w3.org/1999/xhtml"">
            <head>
            <meta http-equiv=""content-type"" content=""text/html; charset=utf-8"" />
            <meta http-equiv=""content-style-type"" content=""text/css; charset=utf-8"" />
            <title>title1</title>
            <style type=""text/css"">body { font-size: medium; }</style>
            </head>
            <body>
            <ul>
            <li>aaa</li>
            <li>bbb</li>
            </ul>
            </body>
            </html>";
            _tempDir.Create();
            var fileName1 = _tempDir.GetFullPath("test.xml");
            var fileName2 = _tempDir.GetFullPath("test2.xml");

            FileUtility.Save(fileName1, _xml);

            var doc = new XHtml();
            doc.Body.Add(XHtml.Element
            (
                "ul",
                XHtml.Element("li", "aaa"),
                XHtml.Element("li", "bbb")
            ));

            doc.Title = "title1";
            doc.Style = "body { font-size: medium; }";

            FileUtility.SaveXml(fileName2, doc.Document);

            FileAssert.AreEqual(fileName1, fileName2);
        }
Example #14
0
 public void a_value_type_property_is_identified_correctly()
 {
     XHtml.TextBox <Customer>(c => c.DateOfBirth.Day)
     .Name
     .ShouldBe("Customer.DateOfBirth.Day");
 }
Example #15
0
 public void a_reference_type_property_is_identified_correctly_on_password()
 {
     XHtml.Password <Customer>(c => c.FirstName)
     .Name
     .ShouldBe("Customer.FirstName");
 }
Example #16
0
 public void a_reference_type_property_is_identified_correctly()
 {
     XHtml.TextBox <Customer>(c => c.FirstName)
     .Name
     .ShouldBe("Customer.FirstName");
 }