diff --git a/app/Umbraco/Archetype.Tests/Models/FieldsetTests.cs b/app/Umbraco/Archetype.Tests/Models/FieldsetTests.cs index ca9e169..d699500 100644 --- a/app/Umbraco/Archetype.Tests/Models/FieldsetTests.cs +++ b/app/Umbraco/Archetype.Tests/Models/FieldsetTests.cs @@ -35,16 +35,17 @@ namespace Archetype.Tests.Models Assert.That(propertyValue == "Box 1 Title"); } - [Test] - public void Can_Get_Fieldset_Property_Default_Value_By_Alias() { - var converter = new ArchetypeValueConverter(); - var result = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, _sampleJson, false); + [Test] + public void Can_Get_Fieldset_Property_Default_Value_By_Alias() + { + var converter = new ArchetypeValueConverter(); + var result = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, _sampleJson, false); - var fieldset = result.Fieldsets.First(); - var propertyValue = fieldset.GetValue("noSuchProperty", "noSuchProperty default value"); + var fieldset = result.Fieldsets.First(); + var propertyValue = fieldset.GetValue("noSuchProperty", "noSuchProperty default value"); - Assert.That(propertyValue == "noSuchProperty default value"); - } + Assert.That(propertyValue == "noSuchProperty default value"); + } [Test] public void Can_Convert_Property_Value_Types() @@ -59,22 +60,23 @@ namespace Archetype.Tests.Models Assert.That(fieldset.GetValue("blurb") == "A blurb here"); } - [Test] - public void Can_Convert_Property_Default_Value_Types() { - var converter = new ArchetypeValueConverter(); - var result = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, _sampleJson, false); + [Test] + public void Can_Convert_Property_Default_Value_Types() + { + var converter = new ArchetypeValueConverter(); + var result = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, _sampleJson, false); - var fieldset = result.Fieldsets.First(); + var fieldset = result.Fieldsets.First(); - Assert.That(fieldset.GetValue("noSuchInteger", 1234) == 1234); - Assert.That(fieldset.GetValue("noSuchBoolean", true) == true); - Assert.That(fieldset.GetValue("noSuchBoolean", false) == false); - Assert.That(fieldset.GetValue("noSuchString", "noSuchString default value") == "noSuchString default value"); + Assert.That(fieldset.GetValue("noSuchInteger", 1234) == 1234); + Assert.That(fieldset.GetValue("noSuchBoolean", true) == true); + Assert.That(fieldset.GetValue("noSuchBoolean", false) == false); + Assert.That(fieldset.GetValue("noSuchString", "noSuchString default value") == "noSuchString default value"); - var contactDetails = fieldset.GetValue("noSuchContact", new ContactDetails { Address = "some street, some city", Name = "someone" }); - Assert.That(contactDetails.Address == "some street, some city"); - Assert.That(contactDetails.Name == "someone"); - } + var contactDetails = fieldset.GetValue("noSuchContact", new ContactDetails { Address = "some street, some city", Name = "someone" }); + Assert.That(contactDetails.Address == "some street, some city"); + Assert.That(contactDetails.Name == "someone"); + } [Test] public void Returns_String_When_No_Type_Specified() diff --git a/app/Umbraco/Umbraco.Archetype/Models/ArchetypeFieldsetModel.cs b/app/Umbraco/Umbraco.Archetype/Models/ArchetypeFieldsetModel.cs index f8b3edf..2026dbd 100644 --- a/app/Umbraco/Umbraco.Archetype/Models/ArchetypeFieldsetModel.cs +++ b/app/Umbraco/Umbraco.Archetype/Models/ArchetypeFieldsetModel.cs @@ -29,35 +29,35 @@ namespace Archetype.Models { var property = GetProperty(propertyAlias); - if (IsEmptyProperty(property)) - { - return default(T); - } + if (IsEmptyProperty(property)) + { + return default(T); + } return property.GetValue(); } - // issue 142: support default T value supplied by caller - // this code would look nicer if the two GetValue() methods had one common implementation. - // however, this would require GetValue(string propertyAlias) to call the common implementation - // with a default(T) value, which could in theory result in a performance hit, if T for some reason - // is costly to instantiate. - public T GetValue(string propertyAlias, T defaultValue) + // issue 142: support default T value supplied by caller + // this code would look nicer if the two GetValue() methods had one common implementation. + // however, this would require GetValue(string propertyAlias) to call the common implementation + // with a default(T) value, which could in theory result in a performance hit, if T for some reason + // is costly to instantiate. + public T GetValue(string propertyAlias, T defaultValue) { var property = GetProperty(propertyAlias); - if (IsEmptyProperty(property)) - { - return defaultValue; - } + if (IsEmptyProperty(property)) + { + return defaultValue; + } return property.GetValue(); } - private bool IsEmptyProperty(ArchetypePropertyModel property) - { - return (property == null || property.Value == null || string.IsNullOrEmpty(property.Value.ToString())); - } + private bool IsEmptyProperty(ArchetypePropertyModel property) + { + return (property == null || property.Value == null || string.IsNullOrEmpty(property.Value.ToString())); + } public bool HasProperty(string propertyAlias) {