コード例 #1
0
        public async Task InitializeAsync_CalledTwice_InvalidOperationException()
        {
            // Arrange

            using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Views\200-success.json");

            using var viewResult = new BlockViewResult <dynamic, dynamic>(HttpStatusCode.OK, "OK", stream, new DefaultSerializer());

            // Act/Assert

            await viewResult.InitializeAsync().ConfigureAwait(false);

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await viewResult.InitializeAsync().ConfigureAwait(false)).ConfigureAwait(false);
        }
コード例 #2
0
        public async Task Test_Message()
        {
            const string message    = "message";
            var          stream     = ResourceHelper.ReadResourceAsStream(ViewResultResourceName);
            var          serializer = new DefaultSerializer();
            var          response   = new BlockViewResult <dynamic, dynamic>(HttpStatusCode.OK, message, stream, serializer);
            await response.InitializeAsync();

            Assert.Equal(message, response.Message);
        }
コード例 #3
0
        public async Task Test_StatusCode()
        {
            const HttpStatusCode statusCode = HttpStatusCode.Accepted;
            var stream     = ResourceHelper.ReadResourceAsStream(ViewResultResourceName);
            var serializer = new DefaultSerializer();
            var response   = new BlockViewResult <dynamic, dynamic>(statusCode, string.Empty, stream, serializer);
            await response.InitializeAsync();

            Assert.Equal(statusCode, response.StatusCode);
        }
コード例 #4
0
        public async Task Test_TotalRows()
        {
            var stream     = ResourceHelper.ReadResourceAsStream(ViewResultResourceName);
            var serializer = new DefaultSerializer();
            var response   = new BlockViewResult <dynamic, dynamic>(HttpStatusCode.OK, string.Empty, stream, serializer);
            await response.InitializeAsync();

            await foreach (var row in response)
            {
                // noop
            }

            Assert.Equal(4u, response.MetaData.TotalRows);
        }
コード例 #5
0
        public async Task GetAsyncEnumerator_CalledTwice_StreamAlreadyReadException(string filename)
        {
            // Arrange

            using var stream = ResourceHelper.ReadResourceAsStream(filename);

            using var viewResult = new BlockViewResult <dynamic, dynamic>(HttpStatusCode.OK, "OK", stream, new DefaultSerializer());
            await viewResult.InitializeAsync().ConfigureAwait(false);

            // Act/Assert

            await viewResult.ToListAsync().ConfigureAwait(false);

            await Assert.ThrowsAsync <StreamAlreadyReadException>(() => viewResult.ToListAsync().AsTask()).ConfigureAwait(false);
        }
コード例 #6
0
        public async Task GetAsyncEnumerator_NoStream_Empty()
        {
            // Arrange

            using var viewResult = new BlockViewResult <dynamic, dynamic>(HttpStatusCode.OK, "OK", new DefaultSerializer());

            // Act

            await viewResult.InitializeAsync().ConfigureAwait(false);

            var result = await viewResult.ToListAsync().ConfigureAwait(false);

            // Assert

            Assert.Empty(result);
        }
コード例 #7
0
        public async Task InitializeAsync_Success_PreResultFieldsPresent()
        {
            // Arrange

            using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Views\200-success.json");

            using var viewResult = new BlockViewResult <dynamic, dynamic>(HttpStatusCode.OK, "OK", stream, new DefaultSerializer());

            // Act

            await viewResult.InitializeAsync().ConfigureAwait(false);

            // Assert

            Assert.Equal(4u, viewResult.MetaData.TotalRows);
        }
コード例 #8
0
        public async Task GetAsyncEnumerator_HasInitialized_GetsResults()
        {
            // Arrange

            using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Views\200-success.json");

            using var viewResult = new BlockViewResult <dynamic, dynamic>(HttpStatusCode.OK, "OK", stream, new DefaultSerializer());
            await viewResult.InitializeAsync().ConfigureAwait(false);

            // Act

            var result = await viewResult.ToListAsync().ConfigureAwait(false);

            // Assert

            Assert.NotEmpty(result);
        }
コード例 #9
0
        public async Task GetAsyncEnumerator_AfterEnumeration_PreResultFieldsStillPresent()
        {
            // Arrange

            using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Views\200-success.json");

            using var viewResult = new BlockViewResult <dynamic, dynamic>(HttpStatusCode.OK, "OK", stream, new DefaultSerializer());
            await viewResult.InitializeAsync();

            // Act

            await viewResult.ToListAsync();

            // Assert

            Assert.Equal(4u, viewResult.MetaData.TotalRows);
        }