Fix code formatting
This commit is contained in:
@@ -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<string>("noSuchProperty", "noSuchProperty default value");
|
||||
var fieldset = result.Fieldsets.First();
|
||||
var propertyValue = fieldset.GetValue<string>("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<string>("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<int>("noSuchInteger", 1234) == 1234);
|
||||
Assert.That(fieldset.GetValue<bool>("noSuchBoolean", true) == true);
|
||||
Assert.That(fieldset.GetValue<bool>("noSuchBoolean", false) == false);
|
||||
Assert.That(fieldset.GetValue<string>("noSuchString", "noSuchString default value") == "noSuchString default value");
|
||||
Assert.That(fieldset.GetValue<int>("noSuchInteger", 1234) == 1234);
|
||||
Assert.That(fieldset.GetValue<bool>("noSuchBoolean", true) == true);
|
||||
Assert.That(fieldset.GetValue<bool>("noSuchBoolean", false) == false);
|
||||
Assert.That(fieldset.GetValue<string>("noSuchString", "noSuchString default value") == "noSuchString default value");
|
||||
|
||||
var contactDetails = fieldset.GetValue<ContactDetails>("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<ContactDetails>("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()
|
||||
|
||||
@@ -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<T>();
|
||||
}
|
||||
|
||||
// issue 142: support default T value supplied by caller
|
||||
// this code would look nicer if the two GetValue<T>() methods had one common implementation.
|
||||
// however, this would require GetValue<T>(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<T>(string propertyAlias, T defaultValue)
|
||||
// issue 142: support default T value supplied by caller
|
||||
// this code would look nicer if the two GetValue<T>() methods had one common implementation.
|
||||
// however, this would require GetValue<T>(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<T>(string propertyAlias, T defaultValue)
|
||||
{
|
||||
var property = GetProperty(propertyAlias);
|
||||
|
||||
if (IsEmptyProperty(property))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (IsEmptyProperty(property))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return property.GetValue<T>();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user