Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/mdsource/doc-index.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [Guids](/docs/guids.md)
* [Dates](/docs/dates.md)
* [Scrubbing](/docs/scrubbers.md)
* [Solution Discovery](/docs/solution-discovery.md)
* [Counter](/docs/counter.md)
* [Members that throw](/docs/members-throw.md)
* [Ordering](/docs/ordering.md)
Expand Down
1 change: 1 addition & 0 deletions docs/mdsource/scrubbers.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,4 @@ snippet: Verify.Xunit.Tests/Scrubbers/ScrubberLevelsSample.Usage.verified.txt
* [Guid behavior](guids.md)
* [Date behavior](dates.md)
* [Numeric Ids](numeric-ids.md)
* [Solution Discovery](solution-discovery.md)
84 changes: 84 additions & 0 deletions docs/mdsource/solution-discovery.source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Solution Discovery


Verify automatically discovers solution information at build time and embeds it into the test assembly as metadata. This metadata is used to determine where to store snapshot files.


## How It Works

During the build process, Verify searches for solution files (`.slnx` or `.sln`) in the following locations (relative to the project directory):

1. Project directory
2. Parent directory
3. Parent's parent directory

If a single solution file is found, Verify extracts and stores:

- `SolutionDir` - The directory containing the solution file
- `SolutionName` - The solution file name without extension

This information is embedded in the assembly as `AssemblyMetadataAttribute` values with keys:

- `Verify.SolutionDirectory`
- `Verify.SolutionName`


## Preference Rules

- If both `.slnx` and `.sln` files exist in the same directory, `.slnx` is preferred
- If multiple `.slnx` files exist, Verify cannot auto-discover and will show a warning
- If no `.slnx` files exist but multiple `.sln` files exist, Verify cannot auto-discover and will show a warning


## Explicit Override

Explicitly set solution information via MSBuild command-line properties:

```bash
dotnet build /p:SolutionDir="C:\Path\To\Solution\" /p:SolutionName="MySolution"
```

When `SolutionDir` is explicitly provided but `SolutionName` is not, Verify will attempt to derive `SolutionName` from the solution file found in the specified `SolutionDir`.


## Warning Messages

If Verify cannot discover solution information, it will emit build warnings with guidance:


### Multiple Solution Files Found

```
Multiple solution files found. Unable to auto-discover SolutionDir and SolutionName.
Found: C:\Path\Solution1.slnx;C:\Path\Solution2.slnx;C:\Path\Solution.sln.
Verify searches for .slnx and .sln files in the project directory, parent directory, and parent's parent directory.
To resolve this, either ensure only one solution file exists in these locations, or explicitly set SolutionDir and SolutionName via command line:
/p:SolutionDir="C:\Path\To\Solution\" /p:SolutionName="MySolution"
```


### No Solution Files Found

```
No solution files found. Unable to auto-discover SolutionDir and SolutionName.
Verify searches for .slnx and .sln files in the project directory '(C:\Path\To\Project)', parent directory, and parent's parent directory.
To resolve this, either add a solution file to one of these locations, or explicitly set SolutionDir and SolutionName via command line:
/p:SolutionDir="C:\Path\To\Solution\" /p:SolutionName="MySolution"
```


### Multiple Solution Files in Explicit SolutionDir

```
Multiple solution files found in SolutionDir 'C:\Path\To\Solution\'. Unable to auto-discover SolutionName.
Found: C:\Path\To\Solution\Solution1.slnx;C:\Path\To\Solution\Solution2.sln.
To resolve this, explicitly set SolutionName via command line:
/p:SolutionName="MySolution"
```


## Build Integration

Solution discovery happens automatically as part of the build via the `Verify.props` MSBuild targets file, which is automatically imported when referencing the Verify NuGet package.

The discovery runs in the `DiscoverSolutionInfo` target, which executes before compilation, and the discovered values are written to generated source files by the `WriteVerifyAttributes` target.
1 change: 1 addition & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ To change this file edit the source file and then run MarkdownSnippets.
* [Guids](/docs/guids.md)
* [Dates](/docs/dates.md)
* [Scrubbing](/docs/scrubbers.md)
* [Solution Discovery](/docs/solution-discovery.md)
* [Counter](/docs/counter.md)
* [Members that throw](/docs/members-throw.md)
* [Ordering](/docs/ordering.md)
Expand Down
1 change: 1 addition & 0 deletions docs/scrubbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -930,3 +930,4 @@ A B C
* [Guid behavior](guids.md)
* [Date behavior](dates.md)
* [Numeric Ids](numeric-ids.md)
* [Solution Discovery](solution-discovery.md)
91 changes: 91 additions & 0 deletions docs/solution-discovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!--
GENERATED FILE - DO NOT EDIT
This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets).
Source File: /docs/mdsource/solution-discovery.source.md
To change this file edit the source file and then run MarkdownSnippets.
-->

# Solution Discovery


Verify automatically discovers solution information at build time and embeds it into the test assembly as metadata. This metadata is used to determine where to store snapshot files.


## How It Works

During the build process, Verify searches for solution files (`.slnx` or `.sln`) in the following locations (relative to the project directory):

1. Project directory
2. Parent directory
3. Parent's parent directory

If a single solution file is found, Verify extracts and stores:

- `SolutionDir` - The directory containing the solution file
- `SolutionName` - The solution file name without extension

This information is embedded in the assembly as `AssemblyMetadataAttribute` values with keys:

- `Verify.SolutionDirectory`
- `Verify.SolutionName`


## Preference Rules

- If both `.slnx` and `.sln` files exist in the same directory, `.slnx` is preferred
- If multiple `.slnx` files exist, Verify cannot auto-discover and will show a warning
- If no `.slnx` files exist but multiple `.sln` files exist, Verify cannot auto-discover and will show a warning


## Explicit Override

Explicitly set solution information via MSBuild command-line properties:

```bash
dotnet build /p:SolutionDir="C:\Path\To\Solution\" /p:SolutionName="MySolution"
```

When `SolutionDir` is explicitly provided but `SolutionName` is not, Verify will attempt to derive `SolutionName` from the solution file found in the specified `SolutionDir`.


## Warning Messages

If Verify cannot discover solution information, it will emit build warnings with guidance:


### Multiple Solution Files Found

```
Multiple solution files found. Unable to auto-discover SolutionDir and SolutionName.
Found: C:\Path\Solution1.slnx;C:\Path\Solution2.slnx;C:\Path\Solution.sln.
Verify searches for .slnx and .sln files in the project directory, parent directory, and parent's parent directory.
To resolve this, either ensure only one solution file exists in these locations, or explicitly set SolutionDir and SolutionName via command line:
/p:SolutionDir="C:\Path\To\Solution\" /p:SolutionName="MySolution"
```


### No Solution Files Found

```
No solution files found. Unable to auto-discover SolutionDir and SolutionName.
Verify searches for .slnx and .sln files in the project directory '(C:\Path\To\Project)', parent directory, and parent's parent directory.
To resolve this, either add a solution file to one of these locations, or explicitly set SolutionDir and SolutionName via command line:
/p:SolutionDir="C:\Path\To\Solution\" /p:SolutionName="MySolution"
```


### Multiple Solution Files in Explicit SolutionDir

```
Multiple solution files found in SolutionDir 'C:\Path\To\Solution\'. Unable to auto-discover SolutionName.
Found: C:\Path\To\Solution\Solution1.slnx;C:\Path\To\Solution\Solution2.sln.
To resolve this, explicitly set SolutionName via command line:
/p:SolutionName="MySolution"
```


## Build Integration

Solution discovery happens automatically as part of the build via the `Verify.props` MSBuild targets file, which is automatically imported when referencing the Verify NuGet package.

The discovery runs in the `DiscoverSolutionInfo` target, which executes before compilation, and the discovered values are written to generated source files by the `WriteVerifyAttributes` target.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@ To opt out of this feature, include the following in the project file:
* [Guids](/docs/guids.md)
* [Dates](/docs/dates.md)
* [Scrubbing](/docs/scrubbers.md)
* [Solution Discovery](/docs/solution-discovery.md)
* [Counter](/docs/counter.md)
* [Members that throw](/docs/members-throw.md)
* [Ordering](/docs/ordering.md)
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<PackageVersion Include="NUnit3TestAdapter" Version="5.2.0" Pinned="true" />
<PackageVersion Include="Polyfill" Version="9.7.6" />
<PackageVersion Include="ProjectDefaults" Version="1.0.170" />
<PackageVersion Include="ProjectFiles" Version="0.5.0" />
<PackageVersion Include="PublicApiGenerator" Version="11.5.4" />
<PackageVersion Include="SimpleInfoName" Version="3.2.0" />
<PackageVersion Include="System.Drawing.Common" Version="10.0.2" />
Expand Down
4 changes: 2 additions & 2 deletions src/Verify.NUnit/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static bool TryGetParent(this TestAdapter adapter, [NotNullWhen(true)] ou
return methodParameterNames;
}

var names = GetConstructorParameterNames(method.TypeInfo.Type, parent.Arguments.Length);
var names = method.TypeInfo.Type.GetConstructorParameterNames(parent.Arguments.Length);
if (methodParameterNames == null)
{
return names.ToList();
Expand Down Expand Up @@ -72,4 +72,4 @@ public static IEnumerable<string> GetConstructorParameterNames(this Type type, i

return names;
}
}
}
2 changes: 2 additions & 0 deletions src/Verify.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
global using EmptyFiles;
global using Polyfills;
global using System.Collections.ObjectModel;
global using System.Reflection.Metadata;
global using System.Reflection.PortableExecutable;
global using System.Security.Claims;
Loading