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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }