public void JsonContent_CopyTo_Succeeds() { Person person = Person.Create(); using JsonContent content = JsonContent.Create(person); using MemoryStream stream = new MemoryStream(); // HttpContent.CopyTo internally calls overriden JsonContent.SerializeToStream, which is the targeted method of this test. content.CopyTo(stream, context: null, cancellationToken: default); stream.Seek(0, SeekOrigin.Begin); using StreamReader reader = new StreamReader(stream); string json = reader.ReadToEnd(); Assert.Equal(person.Serialize(JsonOptions.DefaultSerializerOptions), json); }