private static IEnumerable <string> ReadLines(params string[] lines) { WrappedMemoryStream s = Lines(lines); Task <BasicLine[]> task = BasicStream.ReadAsync(s); task.IsCompletedSuccessfully.Should().BeTrue(); s.DisposeCount.Should().Be(1); return(task.Result.Select(l => l.ToString())); }
public async Task SerializeDeserializeGenericUtf8WrappedMemoryStreamNonSeekable() { var input = Enumerable.Repeat(new AsyncTestObject { Text = "Hello World" }, 10000).ToList(); using (var ms = new WrappedMemoryStream(false)) { await JsonSerializer.Generic.Utf8.SerializeAsync(input, ms).ConfigureAwait(false); ms.Position = 0; var deserialized = await JsonSerializer.Generic.Utf8.DeserializeAsync <List <AsyncTestObject> >(ms); Assert.Equal(input, deserialized); } }
private static string Translate(string name, string inputCode) { WrappedMemoryStream stream = new WrappedMemoryStream(Encoding.UTF8.GetBytes(inputCode)); string outputCode; using (SourceCodeStream source = new SourceCodeStream(stream)) using (MemoryStream output = new MemoryStream()) { Task task = source.TranslateAsync(name, output); task.Exception.Should().BeNull(); task.IsCompletedSuccessfully.Should().BeTrue(); outputCode = Encoding.UTF8.GetString(output.ToArray()); } stream.DisposeCount.Should().Be(1); return(outputCode); }