Skip to content

Commit

Permalink
CopyKeyValuePairTo boolean field with 1 return true now
Browse files Browse the repository at this point in the history
  • Loading branch information
israelramosm committed Jul 11, 2018
1 parent 46c9b4f commit 184c6f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Unosquare.Swan.Lite/Components/ObjectMapper.cs
Expand Up @@ -318,6 +318,14 @@ private static void SetValue(TypeValuePair valueType, object target, PropertyInf
return;
}

if(targetProperty.PropertyType == typeof(Boolean))
{
targetProperty.SetValue(target,
Convert.ToBoolean(valueType.Value));

return;
}

// String to target type conversion
if (targetProperty.PropertyType.TryParseBasicType(valueType.Value.ToStringInvariant(),
out var targetValue))
Expand Down
4 changes: 3 additions & 1 deletion test/Unosquare.Swan.Test/ExtensionsTest.cs
Expand Up @@ -174,7 +174,8 @@ public void WithValidDictionary_CopyPropertiesToTarget()
{
{nameof(UserDto.Name), "Thrall"},
{nameof(UserDto.Email), "Warchief.Thrall@horde.com"},
{nameof(UserDto.Role), "Warchief"}
{nameof(UserDto.Role), "Warchief"},
{nameof(UserDto.IsAdmin), 1}
};

var target = new UserDto();
Expand All @@ -183,6 +184,7 @@ public void WithValidDictionary_CopyPropertiesToTarget()

Assert.AreEqual(source[nameof(UserDto.Name)].ToString(), target.Name);
Assert.AreEqual(source[nameof(UserDto.Email)], target.Email);
Assert.IsTrue(target.IsAdmin);
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/Unosquare.Swan.Test/Mocks/ObjectMapperMock.cs
Expand Up @@ -21,5 +21,7 @@ public class UserDto
public string Email { get; set; }

public string Role { get; set; }

public bool IsAdmin { get; set; }
}
}

0 comments on commit 184c6f9

Please sign in to comment.