Skip to content

Commit eab6a8f

Browse files
authored
Merge pull request #104 from adrianiftode/issues/output-size
Increase the minimum length for the outputted contents as it is too small
2 parents 3b7986d + 9151ed6 commit eab6a8f

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

samples/Sample.Api.Shared/Controllers/ValuesController.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using System;
2+
using Microsoft.AspNetCore.Mvc;
23
using System.Collections.Generic;
4+
using System.Linq;
35

46
namespace Sample.Api.Controllers
57
{
@@ -11,6 +13,16 @@ public class ValuesController : ControllerBase
1113
[HttpGet]
1214
public ActionResult<IEnumerable<string>> Get() => new string[] { "value1", "value2" };
1315

16+
// GET api/values/generated/1
17+
[HttpGet("generated/{howMuchData}")]
18+
public ActionResult<IEnumerable<object>> GetData(int howMuchData) => Enumerable.Range(0, howMuchData).Select(c =>
19+
new
20+
{
21+
item1 = c,
22+
item2 = Guid.NewGuid(),
23+
item3 = $"item-{Guid.NewGuid()}"
24+
}).ToList();
25+
1426
// GET api/values/5
1527
[HttpGet("{id}")]
1628
public ActionResult<string> Get(int id) => "value";

samples/Sample.Api.Tests/ValuesControllerTests.cs

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ public async Task Get_ReturnsOkResponse()
3030
response.Should().Be200Ok();
3131
}
3232

33+
[Theory]
34+
[InlineData(1)]
35+
[InlineData(10)]
36+
[InlineData(50)]
37+
[InlineData(100)]
38+
[InlineData(1000)] // this is not truncated
39+
[InlineData(2000)] // this is not truncated
40+
public async Task GetData_ReturnsOkResponse(int howMuchData)
41+
{
42+
// Arrange
43+
var client = _factory.CreateClient();
44+
45+
// Act
46+
var response = await client.GetAsync($"/api/values/generated/{howMuchData}");
47+
48+
// Assert
49+
response.Should().Be200Ok();
50+
}
51+
3352
[Fact]
3453
public async Task Get_WithId_ReturnsOkResponse()
3554
{
@@ -49,7 +68,7 @@ public async Task Get_WithId_ReturnsOk_And_Expected_Model()
4968
// Arrange
5069
var client = _factory.CreateClient();
5170
client.DefaultRequestHeaders
52-
.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
71+
.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
5372

5473
// Act
5574
var response = await client.GetAsync("/api/values/1");
@@ -74,18 +93,18 @@ public async Task Patch_Returns404NotFound()
7493
#endif
7594

7695
#if NETCOREAPP3_0 || NETCOREAPP3_1
77-
[Fact]
78-
public async Task Patch_ReturnsMethodNotAllowed()
79-
{
80-
// Arrange
81-
var client = _factory.CreateClient();
82-
83-
// Act
84-
var response = await client.PatchAsync("/api/values", new StringContent("", Encoding.UTF32, "application/json"));
85-
86-
// Assert
87-
response.Should().Be405MethodNotAllowed();
88-
}
96+
[Fact]
97+
public async Task Patch_ReturnsMethodNotAllowed()
98+
{
99+
// Arrange
100+
var client = _factory.CreateClient();
101+
102+
// Act
103+
var response = await client.PatchAsync("/api/values", new StringContent("", Encoding.UTF32, "application/json"));
104+
105+
// Assert
106+
response.Should().Be405MethodNotAllowed();
107+
}
89108
#endif
90109

91110
[Fact]
@@ -112,11 +131,11 @@ public async Task Post_WithNoContent_ReturnsBadRequest()
112131

113132
// Assert
114133
#if NETCOREAPP2_2 || NET5_0_OR_GREATER
115-
response.Should().Be400BadRequest()
116-
.And.HaveErrorMessage("A non-empty request body is required.");
134+
response.Should().Be400BadRequest()
135+
.And.HaveErrorMessage("A non-empty request body is required.");
117136
#elif NETCOREAPP3_0 || NETCOREAPP3_1
118-
response.Should().Be400BadRequest()
119-
.And.HaveErrorMessage("*The input does not contain any JSON tokens*");
137+
response.Should().Be400BadRequest()
138+
.And.HaveErrorMessage("*The input does not contain any JSON tokens*");
120139
#endif
121140
}
122141

src/FluentAssertions.Web/Internal/ContentFormatterOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
internal static class ContentFormatterOptions
44
{
5-
public const int MaximumReadableBytes = 1024; // 1KB holds like 500 words
5+
public const int MaximumReadableBytes = 128 * 1024; // 1KB holds like 500 words
66
public const string WarningMessageWhenDisposed = "***** Content is disposed so it cannot be read. *****";
77
public const string WarningMessageWhenContentIsTooLarge = "***** Content is too large to display and only a part is printed. *****";
88
public const string ContentIsOfABinaryEncodedTypeHavingLength = "***** Content is of a binary encoded like type having the length {0}. *****";

0 commit comments

Comments
 (0)