public void Data_attributes_containing_primitive_values_are_properly_quoted() { var attr = new HtmlAttributes(); attr.Data("string", "name"); attr.Data("int", 123); attr.Data("double", 1.23); attr.ToString().Should().Contain("data-int='123'"); attr.ToString().Should().Contain("data-double='1.23'"); attr.ToString().Should().Contain("data-string=\"name\""); }
public void Data_prepends_the_word_data_if_specified_attribute_name_does_not_start_with_the_word_data() { var attributes = new HtmlAttributes(); attributes.Data("widget", new { Id = 789, Name = "The Stanley", Price = 24.99m }); attributes.ToString() .Should() .Be("data-widget='{\"Id\":789,\"Name\":\"The Stanley\",\"Price\":24.99}'"); }
public void Data_attributes_containing_json_can_be_added() { var attributes = new HtmlAttributes(); attributes.Data("data-widget", new { Id = 789, Name = "The Stanley", Price = 24.99m }); attributes.ToString() .Should() .Be("data-widget='{\"Id\":789,\"Name\":\"The Stanley\",\"Price\":24.99}'"); }
public void Data_attributes_containing_IHtmlContent_are_not_reencoded() { var attr = new HtmlAttributes(); attr.Data("bind", new { name = "Felix" }.SerializeToJson()); attr.ToString() .Should() .Be("data-bind='{\"name\":\"Felix\"}'"); }