public void GivenConfigurationWithResolvableKeys_and_MultipleValueResolvers_ReturnAttributesWithConcatanatedValues() { // Arrange var contentItem = JObject.Parse(validJsonWithMultipleRelatedKeys); var attributesResolver = new GroupByPrefixTokenGridSettingsAttributesResolver("_"); var defaultValueResolver = new StringConcatGridSettingValueResolver(" "); var valueResolvers = new Dictionary <string, IGridSettingsAttributeValueResolver>() { { "data-csv", new StringConcatGridSettingValueResolver(",") }, { "data-hyphenated", new StringConcatGridSettingValueResolver("-") } }; var service = new GridSettingsAttributesService(attributesResolver, defaultValueResolver, valueResolvers); // Act var attributes = service.GetSettingsAttributes(contentItem); // Assert Assert.IsTrue(attributes.ContainsKey("data-csv")); Assert.IsTrue(attributes.ContainsKey("data-hyphenated")); Assert.IsTrue(attributes.ContainsKey("data-default")); Assert.AreEqual("first,second,third", attributes["data-csv"]); Assert.AreEqual("first-second-third", attributes["data-hyphenated"]); Assert.AreEqual("first second third", attributes["data-default"]); }
public void GivenValidConfigurationWithStylesAndConfig_ReturnAttributes() { // Arrange var contentItem = JObject.Parse(validJsonWithStylesAndConfig); var service = new GridSettingsAttributesService(); // Act var attributes = service.GetAllAttributes(contentItem); // Assert Assert.AreEqual(3, attributes.Count); }
public void GivenNoConfiguration_ReturnNoAttributes() { // Arrange var contentItem = new JObject(); var service = new GridSettingsAttributesService(); // Act var attributes = service.GetAllAttributes(contentItem); // Assert Assert.IsEmpty(attributes); }
public void GivenConfigurationWithBlankKeyOrValues_ReturnOnlyValidAttributes() { // Arrange var contentItem = JObject.Parse(validJson); var service = new GridSettingsAttributesService(); // Act var attributes = service.GetSettingsAttributes(contentItem); // Assert Assert.AreEqual(2, attributes.Count); }
public void GivenValidConfiguration_ReturnValidAttribute() { // Arrange var contentItem = JObject.Parse(jsonWithBlankValuesAndKeys); var service = new GridSettingsAttributesService(); // Act var attributes = service.GetSettingsAttributes(contentItem); // Assert Assert.AreEqual(2, attributes.Count); }
public void GivenNoConfiguration_ReturnInvalidAttribute() { // Arrange var contentItem = new JObject(); var service = new GridSettingsAttributesService(); // Act var styleAttribute = service.GetStyleAttribute(contentItem); // Assert Assert.IsFalse(styleAttribute.IsValid()); }
public void GivenValidConfiguration_ReturnValidAttribute() { // Arrange var contentItem = JObject.Parse(validJson); var service = new GridSettingsAttributesService(); // Act var styleAttribute = service.GetStyleAttribute(contentItem); // Assert Assert.AreEqual("background-position:right top; background-repeat:no-repeat;", styleAttribute.Value); }
public void GivenValidConfigurationWithOnlyStyles_ReturnOnlyStyleAttribute() { // Arrange var contentItem = JObject.Parse(validJsonWithOnlyStyles); var service = new GridSettingsAttributesService(); // Act var attributes = service.GetAllAttributes(contentItem); // Assert Assert.AreEqual(1, attributes.Count); Assert.IsTrue(attributes.ContainsKey("style")); }
public void GivenConfigurationWithResolvableKeys_and_NoAttributeResolver_ReturnAttributesWithoutConcatanatedValues() { // Arrange var contentItem = JObject.Parse(validJsonWithRelatedKeys); var service = new GridSettingsAttributesService(); // Act var attributes = service.GetSettingsAttributes(contentItem); // Assert Assert.AreEqual(3, attributes.Count); }
public void GivenConfigurationWithoutResolvableKeys_and_AnAttributeResolver_ReturnAttributes() { // Arrange var contentItem = JObject.Parse(validJson); var attributesResolver = new GroupByPrefixTokenGridSettingsAttributesResolver("_"); var service = new GridSettingsAttributesService(attributesResolver); // Act var attributes = service.GetSettingsAttributes(contentItem); // Assert Assert.AreEqual(2, attributes.Count); }
public void GivenConfigurationWithResolvableKeys_and_CsvValueResolver_ReturnAttributesWithCsvConcatanatedValues() { // Arrange var contentItem = JObject.Parse(validJsonWithRelatedKeysAndCsv); var attributesResolver = new GroupByPrefixTokenGridSettingsAttributesResolver("_"); var defaultValueResolver = new StringConcatGridSettingValueResolver(","); var service = new GridSettingsAttributesService(attributesResolver, defaultValueResolver); // Act var attributes = service.GetSettingsAttributes(contentItem); // Assert Assert.IsTrue(attributes.ContainsKey("data-csv")); Assert.AreEqual("first,second,third", attributes["data-csv"]); }
/// <summary> /// Renders the Settings & Styles associated with the current <see cref="JObject"/>. /// </summary> /// <param name="helper">The <see cref="HtmlHelper"/> instance.</param> /// <param name="contentItem">The <see cref="JObject"/> item which holds the configuration for Settings & Styles. This is typically an area or row in the Umbraco Grid.</param> /// <param name="attributesResolver">Optional Attributes Resolver: this provides bespoke logic for grouping attributes together.</param> /// <param name="attributeValueResolvers">Optional Attribute Value Resolver: Once attributes are grouped Attribute Value Resolvers can tailor the output of a given grouping.</param> /// <param name="defaultAttributeValueResolver">Optional Default Attribute Value Resolver: If an <see cref="IGridSettingsAttributeValueResolver"/> can not be found for a specific property this <see cref="IGridSettingsAttributeValueResolver"/> is used insteads.</param> /// <returns>A <see cref="MvcHtmlString" /> containing all the resolved attributes with their values.</returns> public static MvcHtmlString RenderGridSettingAttributes(this HtmlHelper helper, JObject contentItem, IGridSettingsAttributesResolver attributesResolver = null, IDictionary <string, IGridSettingsAttributeValueResolver> attributeValueResolvers = null, IGridSettingsAttributeValueResolver defaultAttributeValueResolver = null) { var attributesService = new GridSettingsAttributesService(attributesResolver, defaultAttributeValueResolver, attributeValueResolvers); return(helper.RenderGridSettingAttributes(contentItem, attributesService)); }