public async Task ObjectResult_AsyncEnumeration_AtLimit()
        {
            // Arrange
            var count    = 24;
            var executor = CreateExecutor(options: new MvcOptions {
                MaxIAsyncEnumerableBufferLimit = count
            });
            var result    = new ObjectResult(AsyncEnumerable(count: count));
            var formatter = new TestJsonOutputFormatter();

            result.Formatters.Add(formatter);

            var actionContext = new ActionContext()
            {
                HttpContext = GetHttpContext(),
            };

            // Act
            await executor.ExecuteAsync(actionContext, result);

            // Assert
            var formatterContext = formatter.LastOutputFormatterContext;
            var value            = Assert.IsType <List <string> >(formatterContext.Object);

            Assert.Equal(24, value.Count);
        }
        public async Task ObjectResult_ReadsAsyncEnumerables()
        {
            // Arrange
            var executor  = CreateExecutor();
            var result    = new ObjectResult(AsyncEnumerable());
            var formatter = new TestJsonOutputFormatter();

            result.Formatters.Add(formatter);

            var actionContext = new ActionContext()
            {
                HttpContext = GetHttpContext(),
            };

            // Act
            await executor.ExecuteAsync(actionContext, result);

            // Assert
            var formatterContext = formatter.LastOutputFormatterContext;

            Assert.Equal(typeof(List <string>), formatterContext.ObjectType);
            var value = Assert.IsType <List <string> >(formatterContext.Object);

            Assert.Equal(new[] { "Hello 0", "Hello 1", "Hello 2", "Hello 3", }, value);
        }
        public async Task ObjectResult_Throws_IfEnumerableThrows()
        {
            // Arrange
            var executor  = CreateExecutor();
            var result    = new ObjectResult(AsyncEnumerable(throwError: true));
            var formatter = new TestJsonOutputFormatter();

            result.Formatters.Add(formatter);

            var actionContext = new ActionContext()
            {
                HttpContext = GetHttpContext(),
            };

            // Act & Assert
            await Assert.ThrowsAsync <TimeZoneNotFoundException>(() => executor.ExecuteAsync(actionContext, result));
        }
        public async Task ObjectResult_Throws_IfEnumerationExceedsLimit(int count)
        {
            // Arrange
            var executor = CreateExecutor(options: new MvcOptions {
                MaxIAsyncEnumerableBufferLimit = 24
            });
            var result    = new ObjectResult(AsyncEnumerable(count: count));
            var formatter = new TestJsonOutputFormatter();

            result.Formatters.Add(formatter);

            var actionContext = new ActionContext()
            {
                HttpContext = GetHttpContext(),
            };

            // Act & Assert
            var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => executor.ExecuteAsync(actionContext, result));
        }
    public async Task ObjectResult_NullValue()
    {
        // Arrange
        var executor  = CreateExecutor();
        var result    = new ObjectResult(value: null);
        var formatter = new TestJsonOutputFormatter();

        result.Formatters.Add(formatter);

        var actionContext = new ActionContext()
        {
            HttpContext = GetHttpContext(),
        };

        // Act
        await executor.ExecuteAsync(actionContext, result);

        // Assert
        var formatterContext = formatter.LastOutputFormatterContext;

        Assert.Null(formatterContext.Object);
    }