Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serialization] More useful throw when missing parameterless ctor #2098

Merged
merged 5 commits into from
Jan 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,24 @@ public void DeserializeWithRepeatedSubObjects()
Assert.Equal(22, family.Mother.Age);
}

[Fact]
public void ThrowWithoutEmptyCtor()
{
try
{
SerializeThenDeserialize(new ClassWithNonEmptyCtor(default));
}
catch (Exception ex)
{
Assert.True(ex.InnerException is DefaultObjectFactory.InstanceCreationException);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant you use here Assert.Throws?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at it initially but didn't find an overload for inner exceptions ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.That(ex.InnerException, Is.TypeOf<BadException>() ); mybe that one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to that one instead Assert.IsType<DefaultObjectFactory.InstanceCreationException>(ex.InnerException);, no API for .That()

}
}

class ClassWithNonEmptyCtor
{
public ClassWithNonEmptyCtor(bool parameter) { }
}


[Fact]
public void DeserializeEmptyDocument()
Expand Down