diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..95b159a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,84 @@ + +[*.{cs,vb}] +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case +dotnet_style_operator_placement_when_wrapping = beginning_of_line +tab_width = 4 +indent_size = 4 +end_of_line = crlf +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion +dotnet_style_namespace_match_folder = true:suggestion + +[*.cs] +csharp_indent_labels = one_less_than_current +csharp_using_directive_placement = outside_namespace:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_prefer_braces = true:silent +csharp_style_namespace_declarations = block_scoped:silent +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +csharp_space_around_binary_operators = before_and_after \ No newline at end of file diff --git a/FluentAssertions.Web.sln b/FluentAssertions.Web.sln index 99b8315..7410898 100644 --- a/FluentAssertions.Web.sln +++ b/FluentAssertions.Web.sln @@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{B6E9 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7F2E3E40-CDC2-413A-9527-802DD4973A96}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig .gitignore = .gitignore appveyor.yml = appveyor.yml common.dependencies.props = common.dependencies.props diff --git a/samples/Sample.Api.Shared/Controllers/ValuesController.cs b/samples/Sample.Api.Shared/Controllers/ValuesController.cs index ae66b9a..bae58c3 100644 --- a/samples/Sample.Api.Shared/Controllers/ValuesController.cs +++ b/samples/Sample.Api.Shared/Controllers/ValuesController.cs @@ -1,5 +1,7 @@ -using Microsoft.AspNetCore.Mvc; +using System; +using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; +using System.Linq; namespace Sample.Api.Controllers { @@ -11,6 +13,16 @@ public class ValuesController : ControllerBase [HttpGet] public ActionResult> Get() => new string[] { "value1", "value2" }; + // GET api/values/generated/1 + [HttpGet("generated/{howMuchData}")] + public ActionResult> GetData(int howMuchData) => Enumerable.Range(0, howMuchData).Select(c => + new + { + item1 = c, + item2 = Guid.NewGuid(), + item3 = $"item-{Guid.NewGuid()}" + }).ToList(); + // GET api/values/5 [HttpGet("{id}")] public ActionResult Get(int id) => "value"; diff --git a/samples/Sample.Api.Tests/ValuesControllerTests.cs b/samples/Sample.Api.Tests/ValuesControllerTests.cs index 841e68c..71874dc 100644 --- a/samples/Sample.Api.Tests/ValuesControllerTests.cs +++ b/samples/Sample.Api.Tests/ValuesControllerTests.cs @@ -30,6 +30,25 @@ public async Task Get_ReturnsOkResponse() response.Should().Be200Ok(); } + [Theory] + [InlineData(1)] + [InlineData(10)] + [InlineData(50)] + [InlineData(100)] + [InlineData(1000)] // this is not truncated + [InlineData(2000)] // this is not truncated + public async Task GetData_ReturnsOkResponse(int howMuchData) + { + // Arrange + var client = _factory.CreateClient(); + + // Act + var response = await client.GetAsync($"/api/values/generated/{howMuchData}"); + + // Assert + response.Should().Be200Ok(); + } + [Fact] public async Task Get_WithId_ReturnsOkResponse() { @@ -49,7 +68,7 @@ public async Task Get_WithId_ReturnsOk_And_Expected_Model() // Arrange var client = _factory.CreateClient(); client.DefaultRequestHeaders - .Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + .Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Act var response = await client.GetAsync("/api/values/1"); @@ -74,18 +93,18 @@ public async Task Patch_Returns404NotFound() #endif #if NETCOREAPP3_0 || NETCOREAPP3_1 - [Fact] - public async Task Patch_ReturnsMethodNotAllowed() - { - // Arrange - var client = _factory.CreateClient(); - - // Act - var response = await client.PatchAsync("/api/values", new StringContent("", Encoding.UTF32, "application/json")); - - // Assert - response.Should().Be405MethodNotAllowed(); - } + [Fact] + public async Task Patch_ReturnsMethodNotAllowed() + { + // Arrange + var client = _factory.CreateClient(); + + // Act + var response = await client.PatchAsync("/api/values", new StringContent("", Encoding.UTF32, "application/json")); + + // Assert + response.Should().Be405MethodNotAllowed(); + } #endif [Fact] @@ -112,11 +131,11 @@ public async Task Post_WithNoContent_ReturnsBadRequest() // Assert #if NETCOREAPP2_2 || NET5_0_OR_GREATER - response.Should().Be400BadRequest() - .And.HaveErrorMessage("A non-empty request body is required."); + response.Should().Be400BadRequest() + .And.HaveErrorMessage("A non-empty request body is required."); #elif NETCOREAPP3_0 || NETCOREAPP3_1 - response.Should().Be400BadRequest() - .And.HaveErrorMessage("*The input does not contain any JSON tokens*"); + response.Should().Be400BadRequest() + .And.HaveErrorMessage("*The input does not contain any JSON tokens*"); #endif } diff --git a/src/FluentAssertions.Web/Internal/ContentFormatterOptions.cs b/src/FluentAssertions.Web/Internal/ContentFormatterOptions.cs index 6d23140..1d0c7d0 100644 --- a/src/FluentAssertions.Web/Internal/ContentFormatterOptions.cs +++ b/src/FluentAssertions.Web/Internal/ContentFormatterOptions.cs @@ -2,7 +2,7 @@ { internal static class ContentFormatterOptions { - public const int MaximumReadableBytes = 1024; // 1KB holds like 500 words + public const int MaximumReadableBytes = 128 * 1024; // 1KB holds like 500 words public const string WarningMessageWhenDisposed = "***** Content is disposed so it cannot be read. *****"; public const string WarningMessageWhenContentIsTooLarge = "***** Content is too large to display and only a part is printed. *****"; public const string ContentIsOfABinaryEncodedTypeHavingLength = "***** Content is of a binary encoded like type having the length {0}. *****";