Skip to content

Commit

Permalink
Added tests for CborReaderTests.ReadNull
Browse files Browse the repository at this point in the history
  • Loading branch information
mcatanzariti authored Apr 5, 2024
1 parent 0f3892e commit 8879e0a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Dahomey.Cbor.Tests/CborReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public void ReadDecimalFromString()
[InlineData("63666F6F", "foo", null)]
[InlineData("7F6166616F616FFF", "foo", typeof(NotSupportedException))]
[InlineData("F6", null, null)]
[InlineData("C6F6", null, null)] // semantig tag 6 + null
[InlineData("60", "", null)]
[InlineData("68C3A9C3A0C3AAC3AF", "éàêï", null)]
public void ReadString(string hexBuffer, string expectedValue, Type expectedExceptionType)
Expand Down Expand Up @@ -368,5 +369,13 @@ public void DataAvailable()
{
Helper.TestDataAvailable();
}

[Theory]
[InlineData("F6", true, null)]
[InlineData("C6F6", true, null)]
public void ReadNull(string hexBuffer, bool expectedValue, Type expectedExceptionType)
{
Helper.TestRead(nameof(CborReader.ReadNull), hexBuffer, expectedValue, expectedExceptionType);
}
}
}
25 changes: 25 additions & 0 deletions src/Dahomey.Cbor.Tests/ObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,5 +495,30 @@ public void UnhandledNameTest(string hexBuffer)
Assert.NotNull(obj);
Assert.Equal(1, obj.IntValue);
}

public class StringObject
{
public string String { get; set; }
}

[Theory]
[InlineData("A166537472696E67F6")]
[InlineData("A166537472696E67C6F6")]
public void ReadWithNullStringProperty(string hexBuffer)
{
StringObject obj = Helper.Read<StringObject>(hexBuffer);
Assert.NotNull(obj);
Assert.Null(obj.String);
}

[Theory]
[InlineData("A1664F626A656374F6")]
[InlineData("A1664F626A656374C6F6")]
public void ReadWithNullObjectProperty(string hexBuffer)
{
ObjectWithObject obj = Helper.Read<ObjectWithObject>(hexBuffer);
Assert.NotNull(obj);
Assert.Null(obj.Object);
}
}
}

0 comments on commit 8879e0a

Please sign in to comment.