public void CreateWriter_ResultIsNull_ThrowsArgumentNullException(INdjsonWriterFactory ndjsonWriterFactory) { Assert.Throws <ArgumentNullException>("result", () => { ndjsonWriterFactory.CreateWriter <ValueType>(PrepareActionContext(), null); }); }
public void CreateWriter_ContextIsNull_ThrowsArgumentNullException(INdjsonWriterFactory ndjsonWriterFactory) { Assert.Throws <ArgumentNullException>("context", () => { ndjsonWriterFactory.CreateWriter <ValueType>(null, OK_RESULT); }); }
public void CreateWriter_CreatesWriter(INdjsonWriterFactory ndjsonWriterFactory) { ActionContext actionContext = PrepareActionContext(); INdjsonWriter <ValueType> ndjsonWriter = ndjsonWriterFactory.CreateWriter <ValueType>(actionContext, OK_RESULT); Assert.NotNull(ndjsonWriter); }
public void CreateWriter_ResponseStatusCodeIsProvided(INdjsonWriterFactory ndjsonWriterFactory) { ActionContext actionContext = PrepareActionContext(); ndjsonWriterFactory.CreateWriter <ValueType>(actionContext, OK_RESULT); Assert.Equal(OK_RESULT.StatusCode, actionContext.HttpContext.Response.StatusCode); }
public void CreateWriter_ResponseContentTypeIsSetToNdjsonWithUtf8Encoding(INdjsonWriterFactory ndjsonWriterFactory) { ActionContext actionContext = PrepareActionContext(); ndjsonWriterFactory.CreateWriter <ValueType>(actionContext, OK_RESULT); Assert.Equal(CONTENT_TYPE, actionContext.HttpContext.Response.ContentType); }
public void CreateWriter_DisablesResponseBuffering(INdjsonWriterFactory ndjsonWriterFactory) { Mock <StreamResponseBodyFeature> httpResponseBodyFeatureMock = new (Stream.Null); ActionContext actionContext = PrepareActionContext(httpResponseBodyFeatureMock.Object); ndjsonWriterFactory.CreateWriter <ValueType>(actionContext, OK_RESULT); httpResponseBodyFeatureMock.Verify(m => m.DisableBuffering(), Times.Once); }
public override async Task ExecuteResultAsync(ActionContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } INdjsonWriterFactory ndjsonTextWriterFactory = context.HttpContext.RequestServices.GetRequiredService <INdjsonWriterFactory>(); using (_ndjsonTextWriter = ndjsonTextWriterFactory.CreateWriter(context, this)) { _readyTaskCompletionSource.SetResult(true); await _completeTaskCompletionSource.Task; } }
/// <summary> /// Executes the result operation of the action method asynchronously. This method is called by MVC to process the result of an action method. /// </summary> /// <param name="context">The <see cref="ActionContext"/> in which the result is executed. The context information includes information about the action that was executed and request information.</param> /// <returns>A <see cref="Task"/> that represents the asynchronous execute operation.</returns> public override async Task ExecuteResultAsync(ActionContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } INdjsonWriterFactory ndjsonTextWriterFactory = context.HttpContext.RequestServices.GetRequiredService <INdjsonWriterFactory>(); using (INdjsonWriter ndjsonTextWriter = ndjsonTextWriterFactory.CreateWriter(context, this)) { await foreach (object value in _values) { await ndjsonTextWriter.WriteAsync(value); } } }
/// <summary> /// Executes the result operation of the action method asynchronously. This method is called by MVC to process the result of an action method. /// </summary> /// <param name="context">The <see cref="ActionContext"/> in which the result is executed. The context information includes information about the action that was executed and request information.</param> /// <returns>A <see cref="Task"/> that represents the asynchronous execute operation.</returns> public override async Task ExecuteResultAsync(ActionContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } INdjsonWriterFactory ndjsonTextWriterFactory = context.HttpContext.RequestServices.GetRequiredService <INdjsonWriterFactory>(); using INdjsonWriter <T> ndjsonTextWriter = ndjsonTextWriterFactory.CreateWriter <T>(context, this); try { await foreach (T value in _values.WithCancellation(context.HttpContext.RequestAborted)) { await ndjsonTextWriter.WriteAsync(value, context.HttpContext.RequestAborted); } } catch (OperationCanceledException) when(context.HttpContext.RequestAborted.IsCancellationRequested) { } }