Skip to content

GET request parameters: retarget net10.0, drop AutoMapper, real test assertions - #2177

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/90074-pass-parameters-get
Open

GET request parameters: retarget net10.0, drop AutoMapper, real test assertions#2177
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/90074-pass-parameters-get

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Retargets aspnetcore-webapi/MultipleParametersInGetMethod to net10.0 and cleans up the sample behind the "GET Request Parameters in ASP.NET Core" article.

AutoMapper removed. Product and ProductDto declared the same six properties, same types, same order, so the mapper copied an object onto its identical twin in an article about passing parameters to a GET action. Gone: the package reference, Mapper/Map.cs, Models/ProductDto.cs, the IMapper field and constructor, and all eight Map calls. Every endpoint now returns the entity, and the JSON responses are byte-identical to before.

Program.cs moves to top-level statements, with the public partial class Program declaration WebApplicationFactory<Program> needs.

Packages. Swashbuckle.AspNetCore 6.2.3 to 10.2.3, MSTest 2.2.8 to the 4.3.3 meta package, Microsoft.NET.Test.Sdk 17.1.0 to 18.9.0, Microsoft.AspNetCore.Mvc.Testing 6.0.0 to 10.0.11, coverlet.collector 3.1.2 to 10.0.1. Newtonsoft.Json 13.0.4 is now an explicit reference: it used to arrive transitively through Microsoft.TestPlatform.TestHost 17.1.0, which declares Newtonsoft.Json 9.0.1. TestHost 18.9.0 declares no such dependency, so the tests would not compile without it.

Tests: all eight asserted nothing. Each did Assert.IsNotNull(products) and then a foreach over the response, so an empty list passed green, and there was no count assertion anywhere in the file. One of the eight really did return empty: the route-plus-query test called ?waranty=2, one r, against a warranty parameter, so the value never bound, warranty defaulted to 0, and no product matched. Spelling fixed, and every test now checks the status code, the count, and the identity of the products returned. With the misspelling still in place the corrected test fails on the count, expected 2 and actual 0.

Build clean with 0 warnings, 8 of 8 tests passing on net10.0 (SDK 10.0.302, runtime 10.0.10).

…assertions

Retarget both projects from net6.0 to net10.0.

Remove AutoMapper. Product and ProductDto declared the same six properties
in the same order, so the mapper copied an object onto its identical twin,
which taught nothing about passing parameters to a GET action. The package,
Mapper/Map.cs, Models/ProductDto.cs, the IMapper field and constructor, and
all eight Map calls are gone; every endpoint now returns the entity and the
JSON responses are byte-identical to before.

Program.cs moves to top-level statements, with the public partial class
Program declaration WebApplicationFactory<Program> needs in the test project.

Packages: Swashbuckle.AspNetCore 6.2.3 to 10.2.3, MSTest 2.2.8 to the 4.3.3
meta package, Microsoft.NET.Test.Sdk 17.1.0 to 18.9.0,
Microsoft.AspNetCore.Mvc.Testing 6.0.0 to 10.0.11, coverlet.collector 3.1.2
to 10.0.1. Newtonsoft.Json 13.0.4 is now referenced explicitly: it used to
arrive transitively through Microsoft.TestPlatform.TestHost 17.1.0, which
declared Newtonsoft.Json 9.0.1; TestHost 18.9.0 declares no such dependency,
so the tests would not compile without it.

Tests: all eight asserted nothing. Each did Assert.IsNotNull followed by a
foreach over the response, so an empty list passed green, and there was no
count assertion in the file. One of the eight really did return empty: the
route-plus-query test called ?waranty=2, one r, against a warranty parameter,
so the value never bound, warranty defaulted to 0, and no product matched.
Fixed the spelling and gave every test a status-code check, a count check and
an exact identity check on the returned products. With the misspelling still
in place the corrected test fails on the count, expected 2 and actual 0.

Build clean with 0 warnings, 8 of 8 tests passing on net10.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant