Snapshot testing is done through Verify package which is setup to take in a .yaml OpenApi spec file and generate a C# output file. The test setup currently only supports spec files that would generate a single file.
Currently the new test handles the following syntnx generators:
SyntaxGeneratorContractInterface
SyntaxGeneratorContractModel
SyntaxGeneratorContractParameter
SyntaxGeneratorContractResult
SyntaxGeneratorEndpointControllers
The Verify package uses two type of files to compare the snapshot.
.verified.cs is the base truth to compare against. These files are stored in the code base.
.received.cs is the output of a failed test where the received file did not match the verified file. These files are git ignored.
Executing a single test that fails will open vs diff tool to compare between the .verified.cs and the .received.cs file.
Adding a new test
Adding a new test is done by simply adding a new openapi spec .yaml file to the relevant folder for a given syntax generator. This file will need to be reduced to only contain the minimal spec necessary to generate a single output file. Some of the test has additional asserts to verify that the spec.
The first time the test is run the test will fail and a .received.cs file is generated. The Verify package will fill your clipboard with a command line snippet to rename the received file to a verified file. This makes it a bit easier to add the output as a new base truth to compare against.
Updating all verified file
If a intentional change to ATC generator would change the output of multiple verified files, resulting in multiple failed test. Then a setting can be added to Verify setting to accept all new output and update all .verified.cs files.
Add following line to VerifySettings setup in SyntaxGeneratorTestBase.cs
var settings = new VerifySettings();
settings.AutoVerify();
Remember to remove this again. Otherwise all changes will be accepted and not test will fail.
This PR adds snapshot testing to the output of ATC Generator.
Snapshot testing is done through Verify package which is setup to take in a .yaml OpenApi spec file and generate a C# output file. The test setup currently only supports spec files that would generate a single file.
Currently the new test handles the following syntnx generators:
SyntaxGeneratorContractInterface
SyntaxGeneratorContractModel
SyntaxGeneratorContractParameter
SyntaxGeneratorContractResult
SyntaxGeneratorEndpointControllers
The Verify package uses two type of files to compare the snapshot.
.verified.cs
is the base truth to compare against. These files are stored in the code base..received.cs
is the output of a failed test where the received file did not match the verified file. These files are git ignored.Executing a single test that fails will open vs diff tool to compare between the
.verified.cs
and the.received.cs
file.Adding a new test
Adding a new test is done by simply adding a new openapi spec .yaml file to the relevant folder for a given syntax generator. This file will need to be reduced to only contain the minimal spec necessary to generate a single output file. Some of the test has additional asserts to verify that the spec.
The first time the test is run the test will fail and a
.received.cs
file is generated. The Verify package will fill your clipboard with a command line snippet to rename the received file to a verified file. This makes it a bit easier to add the output as a new base truth to compare against.Updating all verified file
If a intentional change to ATC generator would change the output of multiple verified files, resulting in multiple failed test. Then a setting can be added to Verify setting to accept all new output and update all
.verified.cs
files. Add following line toVerifySettings
setup inSyntaxGeneratorTestBase.cs
Remember to remove this again. Otherwise all changes will be accepted and not test will fail.
Additional
A tiny whitespace bug is also part of this PR.