/// <summary> /// Sets up an ODataJsonLightCollectionSerializer, /// then runs the given test code asynchronously, /// then flushes and reads the stream back as a string for customized verification. /// </summary> private async Task <string> SetupJsonLightCollectionWriterAndRunTestAsync( Func <ODataJsonLightCollectionWriter, Task> func, IEdmModel model, IEdmTypeReference itemTypeReference) { var stream = new MemoryStream(); var jsonLightOutputContext = CreateJsonLightOutputContext(stream, model, /* writingResponse */ true, /* synchronous */ false); var jsonLightCollectionWriter = new ODataJsonLightCollectionWriter(jsonLightOutputContext, itemTypeReference); await func(jsonLightCollectionWriter); stream.Position = 0; return(await new StreamReader(stream).ReadToEndAsync()); }
private void WriteAndValidateSync(IEdmTypeReference itemTypeReference, ODataCollectionStart collectionStart, IEnumerable <object> items, string expectedPayload, bool writingResponse) { MemoryStream stream = new MemoryStream(); var outputContext = CreateJsonLightOutputContext(stream, this.model, writingResponse, synchronous: true); var collectionWriter = new ODataJsonLightCollectionWriter(outputContext, itemTypeReference); collectionWriter.WriteStart(collectionStart); foreach (object item in items) { collectionWriter.WriteItem(item); } collectionWriter.WriteEnd(); ValidateWrittenPayload(stream, expectedPayload); }