Skip to content
Draft
Changes from all commits
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 @@ -7,6 +7,7 @@
using System.IO;
using System.IO.Pipelines;
using System.Linq;
using System.Reflection;
using System.Text.Json.Serialization.Metadata;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -841,7 +842,6 @@ static async IAsyncEnumerable<int> EmptyAsyncEnumerable()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/128766", typeof(PlatformDetection), nameof(PlatformDetection.IsAppleMobile), nameof(PlatformDetection.IsMonoRuntime))]
public async Task SerializeAsyncEnumerable_TopLevelValues_PartialItemFailure_PriorItemsAreFullyWritten()
{
// When element serialization throws mid-item, items written prior to the failure
Expand All @@ -851,13 +851,17 @@ public async Task SerializeAsyncEnumerable_TopLevelValues_PartialItemFailure_Pri

using MemoryStream stream = new();

await Assert.ThrowsAsync<InvalidOperationException>(() =>
Exception ex = await Assert.ThrowsAnyAsync<Exception>(() =>
JsonSerializer.SerializeAsyncEnumerable(
stream,
Items(),
ResolveJsonTypeInfo<ThrowingValue>(),
topLevelValues: true));

if (ex is TargetInvocationException { InnerException: { } inner })
ex = inner;
Assert.IsType<InvalidOperationException>(ex);

string actual = Encoding.UTF8.GetString(stream.ToArray());
Assert.Equal("{\"V\":1}\n{\"V\":2}\n", actual);

Expand All @@ -871,7 +875,6 @@ static async IAsyncEnumerable<ThrowingValue> Items()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/128766", typeof(PlatformDetection), nameof(PlatformDetection.IsAppleMobile), nameof(PlatformDetection.IsMonoRuntime))]
public async Task SerializeAsyncEnumerable_PipeWriter_TopLevelValues_PartialItemFailure_PriorItemsAreFullyWritten()
{
// When element serialization throws mid-item, items written prior to the failure
Expand Down Expand Up @@ -916,7 +919,11 @@ public async Task SerializeAsyncEnumerable_PipeWriter_TopLevelValues_PartialItem
}
});

await Assert.ThrowsAsync<InvalidOperationException>(() => writeTask);
Exception ex = await Assert.ThrowsAnyAsync<Exception>(() => writeTask);
if (ex is TargetInvocationException { InnerException: { } inner })
ex = inner;
Assert.IsType<InvalidOperationException>(ex);

await pipe.Writer.CompleteAsync();
byte[] bytes = await readerTask;

Expand Down
Loading