Skip to content

Improve JSON output when encountering errors serializing sub-properties #39

@michael-sterling

Description

@michael-sterling

Motivation:

When we encounter an error serializing a property on a context object, other properties still might be useful to the reader. Further, readers might be confused that the serialization error is what caused their test to fail, when in fact the serialization error only happened after the test failed for another reason.

To Repro:

		[Test]
		public void BadPropertySerialization()
		{
			var foo = new FooDto { Id = 1 };

			AssertEx.IsTrue(() => foo == null);
		}

		private sealed class FooDto
		{
			public int Id { get; set; }
			public string Bad => throw new Exception("Bad!");
		}

Expected Output:

Expected:
	foo == null

Actual:
	foo = { Id: 1, Bad: [Newtonsoft.Json.JsonSerializationException: Error getting value from 'Bad' on 'Logos.AccountServices.Tests.IntegrationTests.Accounts.V1.PinTests+FooDto'.] }

Actual Output:

Expected:
	foo == null

Actual:
	foo = <Logos.AccountServices.Tests.IntegrationTests.Accounts.V1.PinTests+FooDto> [Newtonsoft.Json.JsonSerializationException: Error getting value from 'Bad' on 'Logos.AccountServices.Tests.IntegrationTests.Accounts.V1.PinTests+FooDto'.]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions