Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed ID deserialization (#1004)
  • Loading branch information
michaelstaib committed Aug 12, 2019
1 parent c6bffc2 commit be38565
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
58 changes: 58 additions & 0 deletions src/Core/Types.Tests/Types/Scalars/IdTypeTests.cs
Expand Up @@ -116,6 +116,64 @@ public void Serialize_Null()
Assert.Null(serializedValue);
}

[Fact]
public void Deserialize_String()
{
// arrange
var type = new IdType();
var serialized = "123456";

// act
bool success = type.TryDeserialize(serialized, out object value);

// assert
Assert.True(success);
Assert.Equal("123456", Assert.IsType<string>(value));
}

[Fact]
public void Deserialize_Int()
{
// arrange
var type = new IdType();
var serialized = 123456;

// act
bool success = type.TryDeserialize(serialized, out object value);

// assert
Assert.True(success);
Assert.Equal("123456", Assert.IsType<string>(value));
}

[Fact]
public void Deserialize_Null()
{
// arrange
var type = new IdType();
object serialized = null;

// act
bool success = type.TryDeserialize(serialized, out object value);

// assert
Assert.Null(value);
}

[Fact]
public void Deserialize_Float()
{
// arrange
var type = new IdType();
float serialized = 1.1f;

// act
bool success = type.TryDeserialize(serialized, out object value);

// assert
Assert.False(success);
}

[Fact]
public void Serialize_Wrong_Type_Throws()
{
Expand Down
10 changes: 8 additions & 2 deletions src/Core/Types/Types/Scalars/IdType.cs
Expand Up @@ -108,9 +108,15 @@ public override bool TryDeserialize(object serialized, out object value)
return true;
}

if (serialized is string s)
if (serialized is string)
{
value = s;
value = serialized;
return true;
}

if (TryConvertSerialized(serialized, ScalarValueKind.Integer, out string c))
{
value = c;
return true;
}

Expand Down

0 comments on commit be38565

Please sign in to comment.