diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5996f658a..12963ef30 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,12 +9,9 @@ on: permissions: contents: read -env: - DOTNET_NOLOGO: true - jobs: build: - name: Build + name: Build, test and package runs-on: ubuntu-latest steps: @@ -26,15 +23,15 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v5 with: - dotnet-version: 3.1.x + dotnet-version: 10.x - name: Install GitVersion uses: gittools/actions/gitversion/setup@v4 - with: - versionSpec: 6.x - name: Calculate version uses: gittools/actions/gitversion/execute@v4 - name: Build - run: ./build.sh + env: + VERSION: ${{ env.GitVersion_SemVer }} + run: ./build.sh build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c6412fb7d..622a1f5dd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,12 +9,9 @@ permissions: contents: read id-token: write -env: - DOTNET_NOLOGO: true - jobs: build: - name: Publish + name: Build and publish runs-on: ubuntu-latest steps: @@ -32,7 +29,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v5 with: - dotnet-version: 3.1.x + dotnet-version: 10.x - name: Install GitVersion uses: gittools/actions/gitversion/setup@v4 @@ -44,5 +41,6 @@ jobs: - name: Deploy env: + VERSION: ${{ env.GitVersion_SemVer }} NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }} run: ./build.sh publish diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..d74a4b724 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,37 @@ +# Machine.Specificaitons Agent Guide +**Machine.Specifications** is also known as **MSpec**. + +## Project architecture +All code for MSpec lives in `src` or `tests`. Documentation is in `docs`, and logos for NuGet are in `assets`. + +The below source projects are in use by this project, along with test projects. You should **ignore** any other project that is not referenced in the `.slnx` file in the repo root. + +- `Machine.Specifications` - Meta NuGet package that references the default set of dependencies +- `Machine.Specifications.Analyzers` - Code hints and fixes for writing tests "the MSpec way" +- `Machine.Specifications.Core` - Core testing engine and framwork +- `Machine.Specifications.Core.SourceGenerator` - Source generators to aid in test discovery and speed up execution +- `Machine.Specifications.Fakes` - Interface mocking library used by MSpec +- `Machine.Specifications.Fakes.Analyzers` - Code warnings and fixes for writing mocks using MSpec +- `Machine.Specifications.Fakes.SourceGenerator` - Source generator that creates code for mocks in MSpec +- `Machine.Specifications.Should` - Assertion library for MSpec +- `Machine.Specifications.Templates` - Dotnet 'new' templates for creating test projects using MSpec + +All test projects end in `.Specs`, and match the libraries above. + +**Important:** Any projects named with the words `Fixtures` or `Runner` should be ignored as these are legacy and will be removed. +Only use the projects referenced by the `.slnx` file in the repo root. + +## Dev environment tips +- Use `dotnet build` to build the solution +- Use `dotnet test` to build and run all the tests in the solution + +## Making changes +- Make the smallest, most surgical change you can make for the feature you are writing +- Tests should be focused and not verbose +- Follow the naming and styling conventions of this repository +- All changes, in general, should have accompanying tests +- Any API surface changes should have documentation added to `docs` + +## PR instructions +- Title format: Use with a brief description +- Always run `dotnet test` before committing. diff --git a/Directory.Build.props b/Directory.Build.props index bb9a87f75..6cba54252 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,6 @@ <Project> <PropertyGroup> - <TargetFramework>netstandard2.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <LangVersion>latest</LangVersion> @@ -11,7 +10,7 @@ <Authors>Machine Specifications</Authors> <PackageTags>test;unit;testing;context;specification;bdd;tdd;mspec</PackageTags> <PackageReleaseNotes>https://github.com/machine/machine.specifications/releases</PackageReleaseNotes> - <PackageIcon>icon.png</PackageIcon> + <PackageIcon>mspec_logo.png</PackageIcon> <PackageProjectUrl>http://github.com/machine/machine.specifications</PackageProjectUrl> <RepositoryUrl>http://github.com/machine/machine.specifications</RepositoryUrl> <RepositoryType>git</RepositoryType> @@ -20,8 +19,8 @@ </PropertyGroup> <ItemGroup> - <None Include="../../images/icon.png" Pack="true" PackagePath="" Visible="false" /> - <None Include="../../README.md" Pack="true" PackagePath="/" /> + <None Include="$(MSBuildThisFileDirectory)assets/mspec_logo.png" Pack="true" PackagePath="/" Visible="false" /> + <None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="/" /> </ItemGroup> </Project> diff --git a/Machine.Specifications.slnx b/Machine.Specifications.slnx index 7e57ad360..870951541 100644 --- a/Machine.Specifications.slnx +++ b/Machine.Specifications.slnx @@ -1,15 +1,26 @@ <Solution> - <Project Path="src/Machine.Specifications.Analyzers.Tests/Machine.Specifications.Analyzers.Tests.csproj" /> - <Project Path="src/Machine.Specifications.Analyzers/Machine.Specifications.Analyzers.csproj" /> - <Project Path="src/Machine.Specifications.Core.Specs/Machine.Specifications.Core.Specs.csproj" /> - <Project Path="src/Machine.Specifications.Core/Machine.Specifications.Core.csproj" /> - <Project Path="src/Machine.Specifications.Fakes.Specs/Machine.Specifications.Fakes.Specs.csproj" /> - <Project Path="src/Machine.Specifications.Fakes/Machine.Specifications.Fakes.csproj" /> - <Project Path="src/Machine.Specifications.Fixtures/Machine.Specifications.Fixtures.csproj" /> - <Project Path="src/Machine.Specifications.Runner.Utility.Specs/Machine.Specifications.Runner.Utility.Specs.csproj" /> - <Project Path="src/Machine.Specifications.Runner.Utility/Machine.Specifications.Runner.Utility.csproj" /> - <Project Path="src/Machine.Specifications.Runner.VisualStudio/Machine.Specifications.Runner.VisualStudio.csproj" /> - <Project Path="src/Machine.Specifications.Should.Specs/Machine.Specifications.Should.Specs.csproj" /> - <Project Path="src/Machine.Specifications.Should/Machine.Specifications.Should.csproj" /> - <Project Path="src/Machine.Specifications/Machine.Specifications.csproj" /> + <Folder Name="/Analyzers/"> + <Project Path="src/Machine.Specifications.Analyzers/Machine.Specifications.Analyzers.csproj" /> + <Project Path="src/Machine.Specifications.Core.SourceGenerator/Machine.Specifications.Core.SourceGenerator.csproj" Id="be1e82ac-fadb-462e-b941-de93bf7a4a41" /> + <Project Path="src/Machine.Specifications.Fakes.Analyzers/Machine.Specifications.Fakes.Analyzers.csproj" Id="55618fdf-264c-426c-95d9-179826526efc" /> + <Project Path="src/Machine.Specifications.Fakes.SourceGenerator/Machine.Specifications.Fakes.SourceGenerator.csproj" Id="d39b087e-b815-4431-bf51-a786ab3a740e" /> + </Folder> + <Folder Name="/Core/"> + <Project Path="src/Machine.Specifications.Core/Machine.Specifications.Core.csproj" /> + <Project Path="src/Machine.Specifications.Fakes/Machine.Specifications.Fakes.csproj" /> + <Project Path="src/Machine.Specifications.Should/Machine.Specifications.Should.csproj" /> + <Project Path="src/Machine.Specifications/Machine.Specifications.csproj" /> + </Folder> + <Folder Name="/Templates/"> + <Project Path="src/Machine.Specifications.Templates/Machine.Specifications.Templates.csproj" Id="f8740762-8ccb-4b72-9ae2-2b84dcf04d0e" /> + </Folder> + <Folder Name="/Tests/"> + <Project Path="tests/Machine.Specifications.Analyzers.Specs/Machine.Specifications.Analyzers.Specs.csproj" /> + <Project Path="tests/Machine.Specifications.Core.SourceGenerator.Specs/Machine.Specifications.Core.SourceGenerator.Specs.csproj" /> + <Project Path="tests/Machine.Specifications.Core.Specs/Machine.Specifications.Core.Specs.csproj" /> + <Project Path="tests/Machine.Specifications.Fakes.Analzyers.Specs/Machine.Specifications.Fakes.Analzyers.Specs.csproj" /> + <Project Path="tests/Machine.Specifications.Fakes.SourceGenerator.Specs/Machine.Specifications.Fakes.SourceGenerator.Specs.csproj" /> + <Project Path="tests/Machine.Specifications.Fakes.Specs/Machine.Specifications.Fakes.Specs.csproj" /> + <Project Path="tests/Machine.Specifications.Should.Specs/Machine.Specifications.Should.Specs.csproj" /> + </Folder> </Solution> diff --git a/assets/mspec_logo.png b/assets/mspec_logo.png new file mode 100644 index 000000000..41082cd30 Binary files /dev/null and b/assets/mspec_logo.png differ diff --git a/assets/mspec_logo.svg b/assets/mspec_logo.svg new file mode 100644 index 000000000..993a93814 --- /dev/null +++ b/assets/mspec_logo.svg @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> + +<svg + width="512" + height="512" + viewBox="0 0 512 512" + version="1.1" + xml:space="preserve" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"> + <defs /> + <g> + <circle + style="fill:#9a9ea2;fill-opacity:1;stroke-width:0;stroke:none;stroke-dasharray:none" + cx="256" + cy="256" + r="247.52571" /> + <path + style="fill:#4f5153;fill-opacity:1;stroke-width:0;stroke-dasharray:none;stroke:none" + d="m 227.27462,67.69677 -8.80308,46.52843 a 149.39075,149.39075 0 0 0 -36.44584,14.81046 l -38.86429,-26.49812 -0.67335,0.67386 -39.27666,39.27666 -0.67386,0.67335 25.87594,37.95169 a 149.39075,149.39075 0 0 0 -16.36541,37.7703 l -44.351301,8.39122 v 0.95291 55.54545 0.95291 l 42.834081,8.1039 a 149.39075,149.39075 0 0 0 16.08997,40.68589 l -24.08328,35.32291 0.67386,0.67386 39.27666,39.27667 0.67335,0.67386 34.432,-23.47608 a 149.39075,149.39075 0 0 0 42.00157,17.72553 l 7.67964,40.5908 h 0.95291 55.54545 0.95291 l 7.67964,-40.5908 a 149.39075,149.39075 0 0 0 42.00105,-17.72553 l 34.43201,23.47608 0.67386,-0.67386 39.27667,-39.27667 0.67386,-0.67386 -24.0838,-35.32291 a 149.39075,149.39075 0 0 0 16.08997,-40.68589 l 42.83408,-8.1039 v -0.95291 -55.54545 -0.95291 l -44.35078,-8.3907 v -5.2e-4 a 149.39075,149.39075 0 0 0 -16.36541,-37.7703 l 25.87594,-37.95169 -0.67386,-0.67335 -39.27667,-39.27666 -0.67386,-0.67386 -38.8643,26.49812 A 149.39075,149.39075 0 0 0 293.52897,114.2252 l -8.80308,-46.52843 h -0.95291 -55.54545 z" /><circle + style="fill:#d7d9da;fill-opacity:1;stroke-width:0;stroke:none;stroke-dasharray:none" + id="path3" + cx="256" + cy="256" + r="84.321671" /> + </g> +</svg> diff --git a/build.ps1 b/build.ps1 index 603c8f435..53e55af94 100644 --- a/build.ps1 +++ b/build.ps1 @@ -10,7 +10,7 @@ if ($null -eq (Get-Command "dotnet" -ErrorAction Ignore)) { Push-Location (Split-Path $MyInvocation.MyCommand.Definition) try { - & dotnet run ./build/build.cs -- $args + & dotnet ./build/build.cs -- $args } finally { Pop-Location diff --git a/build.sh b/build.sh index 7e6904a8d..e1e918593 100755 --- a/build.sh +++ b/build.sh @@ -3,7 +3,7 @@ set -euo pipefail if which dotnet > /dev/null; then - dotnet run ./build/build.cs -- "$@" + dotnet ./build/build.cs -- "$@" else echo "error(1): Could not find 'dotnet', please install .NET SDK" exit 1 diff --git a/build/build.cs b/build/build.cs index 2c6b19f34..6e0d29a82 100644 --- a/build/build.cs +++ b/build/build.cs @@ -4,7 +4,7 @@ using static Bullseye.Targets; using static SimpleExec.Command; -var version = new GitVersion(); +var version = default(string); Target("clean", () => { @@ -16,20 +16,19 @@ } }); +Target("version", () => +{ + version = Environment.GetEnvironmentVariable("VERSION"); +}); + Target("restore", dependsOn: ["clean"], () => { Run("dotnet", "restore"); }); -Target("build", dependsOn: ["restore"], () => +Target("build", dependsOn: ["restore", "version"], () => { - Run("dotnet", "build " + - "--no-restore " + - "--configuration Release " + - $"--property Version={version.SemVer} " + - $"--property AssemblyVersion={version.AssemblySemVer} " + - $"--property FileVersion={version.AssemblySemFileVer} " + - $"--property InformationalVersion={version.InformationalVersion}"); + Run("dotnet", $"build --configuration Release --no-restore --property Version={version}"); }); Target("test", dependsOn: ["build"], () => @@ -37,29 +36,18 @@ Run("dotnet", "test --configuration Release --no-restore --no-build"); }); -Target("package", dependsOn: ["build", "test"], () => +Target("package", dependsOn: ["build", "test", "version"], () => { - Run("dotnet", $"pack --configuration Release --no-restore --no-build --output artifacts --property Version={version.SemVer}"); + Run("dotnet", $"pack --configuration Release --no-restore --no-build --output artifacts --property Version={version}"); }); Target("publish", dependsOn: ["package"], () => { var apiKey = Environment.GetEnvironmentVariable("NUGET_API_KEY"); - Run("dotnet", $"nuget push {Path.Combine("artifacts", "*.nupkg")} --api-key {apiKey} --source https://api.nuget.org/v3/index.json"); + Run("dotnet", $"nuget push artifacts/*.nupkg --api-key {apiKey} --source https://api.nuget.org/v3/index.json"); }); Target("default", dependsOn: ["package"]); await RunTargetsAndExitAsync(args); - -public class GitVersion -{ - public string SemVer { get; } = Environment.GetEnvironmentVariable("GitVersion_SemVer") ?? "0.1.0"; - - public string AssemblySemVer { get; } = Environment.GetEnvironmentVariable("GitVersion_AssemblySemVer") ?? "0.1.0"; - - public string AssemblySemFileVer { get; } = Environment.GetEnvironmentVariable("GitVersion_AssemblySemFileVer") ?? "0.1.0"; - - public string InformationalVersion { get; } = Environment.GetEnvironmentVariable("GitVersion_InformationalVersion") ?? "0.1.0"; -} diff --git a/docs/.gitkeep b/docs/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/global.json b/global.json new file mode 100644 index 000000000..3140116df --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "test": { + "runner": "Microsoft.Testing.Platform" + } +} diff --git a/src/Directory.Build.props b/src/Directory.Build.props new file mode 100644 index 000000000..c6ef25973 --- /dev/null +++ b/src/Directory.Build.props @@ -0,0 +1,9 @@ +<Project> + + <Import Project="../Directory.Build.props" /> + + <PropertyGroup> + <TargetFramework>netstandard2.0</TargetFramework> + </PropertyGroup> + +</Project> diff --git a/src/Machine.Specifications.Analyzers.Tests/Machine.Specifications.Analyzers.Tests.csproj b/src/Machine.Specifications.Analyzers.Tests/Machine.Specifications.Analyzers.Tests.csproj deleted file mode 100644 index 7047e919d..000000000 --- a/src/Machine.Specifications.Analyzers.Tests/Machine.Specifications.Analyzers.Tests.csproj +++ /dev/null @@ -1,25 +0,0 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <TargetFramework>net10.0</TargetFramework> - <OutputType>Exe</OutputType> - <TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport> - <IsPackable>false</IsPackable> - </PropertyGroup> - - <ItemGroup> - <Using Include="Xunit" /> - </ItemGroup> - - <ItemGroup> - <PackageReference Include="Microsoft.CodeAnalysis" Version="4.12.0" /> - <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" /> - <PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.2" /> - <PackageReference Include="xunit.v3" Version="1.0.0" /> - </ItemGroup> - - <ItemGroup> - <ProjectReference Include="..\Machine.Specifications.Analyzers\Machine.Specifications.Analyzers.csproj" /> - </ItemGroup> - -</Project> diff --git a/src/Machine.Specifications.Analyzers/Machine.Specifications.Analyzers.csproj b/src/Machine.Specifications.Analyzers/Machine.Specifications.Analyzers.csproj index ecefb21de..9a511ee01 100644 --- a/src/Machine.Specifications.Analyzers/Machine.Specifications.Analyzers.csproj +++ b/src/Machine.Specifications.Analyzers/Machine.Specifications.Analyzers.csproj @@ -4,7 +4,6 @@ <IncludeBuildOutput>false</IncludeBuildOutput> <DevelopmentDependency>true</DevelopmentDependency> <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> - <TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);PackageItems</TargetsForTfmSpecificContentInPackage> </PropertyGroup> <PropertyGroup> @@ -12,17 +11,11 @@ </PropertyGroup> <ItemGroup> - <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" PrivateAssets="all" /> + <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.0.0" PrivateAssets="all" /> </ItemGroup> <ItemGroup> - <None Update="*.ps1" CopyToOutputDirectory="Always" Pack="true" PackagePath="tools" Visible="false" /> + <TfmSpecificPackageFile Include="$(TargetPath)" Pack="true" PackagePath="analyzers/dotnet/cs" /> </ItemGroup> - <Target Name="PackageItems"> - <ItemGroup> - <TfmSpecificPackageFile Include="$(OutputPath)\$(AssemblyName).dll" PackagePath="analyzers/dotnet/cs" /> - </ItemGroup> - </Target> - </Project> diff --git a/src/Machine.Specifications.Analyzers/MachineSpecStubs.cs b/src/Machine.Specifications.Analyzers/MachineSpecStubs.cs index 1affc07dc..8b7093163 100644 --- a/src/Machine.Specifications.Analyzers/MachineSpecStubs.cs +++ b/src/Machine.Specifications.Analyzers/MachineSpecStubs.cs @@ -1,4 +1,4 @@ -namespace Machine.Specifications; +namespace Machine.Specifications; public class SetupDelegateAttribute : Attribute { diff --git a/src/Machine.Specifications.Analyzers/install.ps1 b/src/Machine.Specifications.Analyzers/install.ps1 deleted file mode 100644 index ff051759d..000000000 --- a/src/Machine.Specifications.Analyzers/install.ps1 +++ /dev/null @@ -1,58 +0,0 @@ -param($installPath, $toolsPath, $package, $project) - -if($project.Object.SupportsPackageDependencyResolution) -{ - if($project.Object.SupportsPackageDependencyResolution()) - { - # Do not install analyzers via install.ps1, instead let the project system handle it. - return - } -} - -$analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers") * -Resolve - -foreach($analyzersPath in $analyzersPaths) -{ - if (Test-Path $analyzersPath) - { - # Install the language agnostic analyzers. - foreach ($analyzerFilePath in Get-ChildItem -Path "$analyzersPath\*.dll" -Exclude *.resources.dll) - { - if($project.Object.AnalyzerReferences) - { - $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName) - } - } - } -} - -# $project.Type gives the language name like (C# or VB.NET) -$languageFolder = "" -if($project.Type -eq "C#") -{ - $languageFolder = "cs" -} -if($project.Type -eq "VB.NET") -{ - $languageFolder = "vb" -} -if($languageFolder -eq "") -{ - return -} - -foreach($analyzersPath in $analyzersPaths) -{ - # Install language specific analyzers. - $languageAnalyzersPath = join-path $analyzersPath $languageFolder - if (Test-Path $languageAnalyzersPath) - { - foreach ($analyzerFilePath in Get-ChildItem -Path "$languageAnalyzersPath\*.dll" -Exclude *.resources.dll) - { - if($project.Object.AnalyzerReferences) - { - $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName) - } - } - } -} diff --git a/src/Machine.Specifications.Analyzers/uninstall.ps1 b/src/Machine.Specifications.Analyzers/uninstall.ps1 deleted file mode 100644 index 4bed33374..000000000 --- a/src/Machine.Specifications.Analyzers/uninstall.ps1 +++ /dev/null @@ -1,65 +0,0 @@ -param($installPath, $toolsPath, $package, $project) - -if($project.Object.SupportsPackageDependencyResolution) -{ - if($project.Object.SupportsPackageDependencyResolution()) - { - # Do not uninstall analyzers via uninstall.ps1, instead let the project system handle it. - return - } -} - -$analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers") * -Resolve - -foreach($analyzersPath in $analyzersPaths) -{ - # Uninstall the language agnostic analyzers. - if (Test-Path $analyzersPath) - { - foreach ($analyzerFilePath in Get-ChildItem -Path "$analyzersPath\*.dll" -Exclude *.resources.dll) - { - if($project.Object.AnalyzerReferences) - { - $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName) - } - } - } -} - -# $project.Type gives the language name like (C# or VB.NET) -$languageFolder = "" -if($project.Type -eq "C#") -{ - $languageFolder = "cs" -} -if($project.Type -eq "VB.NET") -{ - $languageFolder = "vb" -} -if($languageFolder -eq "") -{ - return -} - -foreach($analyzersPath in $analyzersPaths) -{ - # Uninstall language specific analyzers. - $languageAnalyzersPath = join-path $analyzersPath $languageFolder - if (Test-Path $languageAnalyzersPath) - { - foreach ($analyzerFilePath in Get-ChildItem -Path "$languageAnalyzersPath\*.dll" -Exclude *.resources.dll) - { - if($project.Object.AnalyzerReferences) - { - try - { - $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName) - } - catch - { - - } - } - } - } -} diff --git a/src/Machine.Specifications.Core.SourceGenerator/Machine.Specifications.Core.SourceGenerator.csproj b/src/Machine.Specifications.Core.SourceGenerator/Machine.Specifications.Core.SourceGenerator.csproj new file mode 100644 index 000000000..3a421494b --- /dev/null +++ b/src/Machine.Specifications.Core.SourceGenerator/Machine.Specifications.Core.SourceGenerator.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> + <IsPackable>false</IsPackable> + <IsRoslynComponent>true</IsRoslynComponent> + </PropertyGroup> + +</Project> diff --git a/src/Machine.Specifications.Core.Specs/Machine.Specifications.Core.Specs.csproj b/src/Machine.Specifications.Core.Specs/Machine.Specifications.Core.Specs.csproj deleted file mode 100644 index 80c9588be..000000000 --- a/src/Machine.Specifications.Core.Specs/Machine.Specifications.Core.Specs.csproj +++ /dev/null @@ -1,19 +0,0 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <TargetFramework>net10.0</TargetFramework> - <IsPackable>false</IsPackable> - </PropertyGroup> - - <ItemGroup> - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> - </ItemGroup> - - <ItemGroup> - <ProjectReference Include="..\Machine.Specifications.Core\Machine.Specifications.Core.csproj" /> - <ProjectReference Include="..\Machine.Specifications.Fixtures\Machine.Specifications.Fixtures.csproj" /> - <ProjectReference Include="..\Machine.Specifications.Runner.VisualStudio\Machine.Specifications.Runner.VisualStudio.csproj" /> - <ProjectReference Include="..\Machine.Specifications.Should\Machine.Specifications.Should.csproj" /> - </ItemGroup> - -</Project> diff --git a/src/Machine.Specifications.Core/Framework.cs b/src/Machine.Specifications.Core/Framework.cs index 60ea270f3..f8338ad61 100644 --- a/src/Machine.Specifications.Core/Framework.cs +++ b/src/Machine.Specifications.Core/Framework.cs @@ -1,3 +1,5 @@ +using System.Linq.Expressions; + namespace Machine.Specifications { [SetupDelegate] diff --git a/src/Machine.Specifications.Core/Machine.Specifications.Core.csproj b/src/Machine.Specifications.Core/Machine.Specifications.Core.csproj index e06333496..483bc167c 100644 --- a/src/Machine.Specifications.Core/Machine.Specifications.Core.csproj +++ b/src/Machine.Specifications.Core/Machine.Specifications.Core.csproj @@ -9,7 +9,15 @@ </PropertyGroup> <ItemGroup> - <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.6.0" /> + <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.6.3" /> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\Machine.Specifications.Core.SourceGenerator\Machine.Specifications.Core.SourceGenerator.csproj" /> + </ItemGroup> + + <ItemGroup> + <TfmSpecificPackageFile Include="$(TargetDir)$(AssemblyName).SourceGenerator.dll" Pack="true" PackagePath="analyzers/dotnet/cs" /> </ItemGroup> </Project> diff --git a/src/Machine.Specifications.Core/Runner/Impl/DefaultRunner.cs b/src/Machine.Specifications.Core/Runner/Impl/DefaultRunner.cs index a2a283701..7de7d5da9 100644 --- a/src/Machine.Specifications.Core/Runner/Impl/DefaultRunner.cs +++ b/src/Machine.Specifications.Core/Runner/Impl/DefaultRunner.cs @@ -3,7 +3,7 @@ using System.IO; using System.Linq; using System.Reflection; -#if !NET6_0_OR_GREATER +#if !NETSTANDARD using System.Runtime.Remoting; using System.Runtime.Remoting.Messaging; #endif @@ -16,11 +16,11 @@ namespace Machine.Specifications.Runner.Impl { -#if !NET6_0_OR_GREATER +#if !NETSTANDARD [Serializable] #endif public class DefaultRunner : -#if !NET6_0_OR_GREATER +#if !NETSTANDARD MarshalByRefObject, IMessageSink, #endif ISpecificationRunner @@ -40,7 +40,7 @@ public class DefaultRunner : private bool explicitStartAndEnd; -#if !NET6_0_OR_GREATER +#if !NETSTANDARD public DefaultRunner(object listener, string runOptionsXml, bool signalRunStartAndEnd) : this(new RemoteRunListenerDecorator(listener), RunOptions.Parse(runOptionsXml), signalRunStartAndEnd) { @@ -173,7 +173,7 @@ public void EndRun(Assembly assembly) runEnd.Invoke(); } -#if !NET6_0_OR_GREATER +#if !NETSTANDARD [SecurityCritical] public override object InitializeLifetimeService() { diff --git a/src/Machine.Specifications.Core/Runner/Impl/RemoteRunListenerDecorator.cs b/src/Machine.Specifications.Core/Runner/Impl/RemoteRunListenerDecorator.cs index 7cd8b8d01..f7ac685b9 100644 --- a/src/Machine.Specifications.Core/Runner/Impl/RemoteRunListenerDecorator.cs +++ b/src/Machine.Specifications.Core/Runner/Impl/RemoteRunListenerDecorator.cs @@ -1,4 +1,4 @@ -#if !NET6_0_OR_GREATER +#if !NETSTANDARD using System; using System.Collections; using System.Collections.Generic; diff --git a/src/Machine.Specifications.Core/Sdk/RemoteRunListenerDecorator.cs b/src/Machine.Specifications.Core/Sdk/RemoteRunListenerDecorator.cs index b8c84f915..93eb8ca36 100644 --- a/src/Machine.Specifications.Core/Sdk/RemoteRunListenerDecorator.cs +++ b/src/Machine.Specifications.Core/Sdk/RemoteRunListenerDecorator.cs @@ -1,4 +1,4 @@ -#if !NET6_0_OR_GREATER +#if !NETSTANDARD using System; using System.Collections; diff --git a/src/Machine.Specifications.Core/Sdk/RunSpecs.cs b/src/Machine.Specifications.Core/Sdk/RunSpecs.cs index 21c300993..e5ca4c9d6 100644 --- a/src/Machine.Specifications.Core/Sdk/RunSpecs.cs +++ b/src/Machine.Specifications.Core/Sdk/RunSpecs.cs @@ -1,4 +1,4 @@ -#if !NET6_0_OR_GREATER +#if !NETSTANDARD using System.Collections.Generic; using System.Linq; diff --git a/src/Machine.Specifications.Fakes.Analyzers/Machine.Specifications.Fakes.Analyzers.csproj b/src/Machine.Specifications.Fakes.Analyzers/Machine.Specifications.Fakes.Analyzers.csproj new file mode 100644 index 000000000..bef03830d --- /dev/null +++ b/src/Machine.Specifications.Fakes.Analyzers/Machine.Specifications.Fakes.Analyzers.csproj @@ -0,0 +1,2 @@ +<Project Sdk="Microsoft.NET.Sdk"> +</Project> diff --git a/src/Machine.Specifications.Fakes.SourceGenerator/Machine.Specifications.Fakes.SourceGenerator.csproj b/src/Machine.Specifications.Fakes.SourceGenerator/Machine.Specifications.Fakes.SourceGenerator.csproj new file mode 100644 index 000000000..bef03830d --- /dev/null +++ b/src/Machine.Specifications.Fakes.SourceGenerator/Machine.Specifications.Fakes.SourceGenerator.csproj @@ -0,0 +1,2 @@ +<Project Sdk="Microsoft.NET.Sdk"> +</Project> diff --git a/src/Machine.Specifications.Fakes.Specs/Machine.Specifications.Fakes.Specs.csproj b/src/Machine.Specifications.Fakes.Specs/Machine.Specifications.Fakes.Specs.csproj deleted file mode 100644 index ba4c133d1..000000000 --- a/src/Machine.Specifications.Fakes.Specs/Machine.Specifications.Fakes.Specs.csproj +++ /dev/null @@ -1,19 +0,0 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <TargetFramework>net10.0</TargetFramework> - <IsPackable>false</IsPackable> - </PropertyGroup> - - <ItemGroup> - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> - </ItemGroup> - - <ItemGroup> - <ProjectReference Include="..\Machine.Specifications.Core\Machine.Specifications.Core.csproj" /> - <ProjectReference Include="..\Machine.Specifications.Fakes\Machine.Specifications.Fakes.csproj" /> - <ProjectReference Include="..\Machine.Specifications.Runner.VisualStudio\Machine.Specifications.Runner.VisualStudio.csproj" /> - <ProjectReference Include="..\Machine.Specifications.Should\Machine.Specifications.Should.csproj" /> - </ItemGroup> - -</Project> diff --git a/src/Machine.Specifications.Fakes/Machine.Specifications.Fakes.csproj b/src/Machine.Specifications.Fakes/Machine.Specifications.Fakes.csproj index cc67fc1c0..b33e0d1b2 100644 --- a/src/Machine.Specifications.Fakes/Machine.Specifications.Fakes.csproj +++ b/src/Machine.Specifications.Fakes/Machine.Specifications.Fakes.csproj @@ -1,9 +1,5 @@ <Project Sdk="Microsoft.NET.Sdk"> - <PropertyGroup> - <IsPackable>false</IsPackable> - </PropertyGroup> - <ItemGroup> <PackageReference Include="System.Reflection.Emit" Version="4.7.0" /> </ItemGroup> diff --git a/src/Machine.Specifications.Interfaces/Machine.Specifications.Interfaces.csproj b/src/Machine.Specifications.Interfaces/Machine.Specifications.Interfaces.csproj deleted file mode 100644 index f63243811..000000000 --- a/src/Machine.Specifications.Interfaces/Machine.Specifications.Interfaces.csproj +++ /dev/null @@ -1,20 +0,0 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <TargetFramework>netstandard2.0</TargetFramework> - <RootNamespace>Machine.Specifications</RootNamespace> - - <Description>SDK and common runner interfaces used by Machine.Specifications</Description> - <Authors>Machine Specifications</Authors> - <PackageTags>test;unit;testing;context;specification;bdd;tdd;mspec</PackageTags> - <PackageReleaseNotes>https://github.com/machine/machine.specifications/releases</PackageReleaseNotes> - <PackageIcon>icon.png</PackageIcon> - <PackageProjectUrl>http://github.com/machine/machine.specifications</PackageProjectUrl> - <PackageLicenseExpression>MIT</PackageLicenseExpression> - </PropertyGroup> - - <ItemGroup> - <None Include="../../images/icon.png" Pack="true" PackagePath="" Visible="false" /> - </ItemGroup> - -</Project> diff --git a/src/Machine.Specifications.Runner.Utility.Specs/Machine.Specifications.Runner.Utility.Specs.csproj b/src/Machine.Specifications.Runner.Utility.Specs/Machine.Specifications.Runner.Utility.Specs.csproj deleted file mode 100644 index 73c3fc6d9..000000000 --- a/src/Machine.Specifications.Runner.Utility.Specs/Machine.Specifications.Runner.Utility.Specs.csproj +++ /dev/null @@ -1,20 +0,0 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <TargetFrameworks>net10.0</TargetFrameworks> - <IsPackable>false</IsPackable> - </PropertyGroup> - - <ItemGroup> - <PackageReference Include="Microsoft.CodeAnalysis.Compilers" Version="4.12.0" /> - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> - </ItemGroup> - - <ItemGroup> - <ProjectReference Include="..\Machine.Specifications.Core\Machine.Specifications.Core.csproj" /> - <ProjectReference Include="..\Machine.Specifications.Runner.Utility\Machine.Specifications.Runner.Utility.csproj" /> - <ProjectReference Include="..\Machine.Specifications.Runner.VisualStudio\Machine.Specifications.Runner.VisualStudio.csproj" /> - <ProjectReference Include="..\Machine.Specifications.Should\Machine.Specifications.Should.csproj" /> - </ItemGroup> - -</Project> diff --git a/src/Machine.Specifications.Should/Machine.Specifications.Should.csproj b/src/Machine.Specifications.Should/Machine.Specifications.Should.csproj index 9b9b8ea5e..5e7f57426 100644 --- a/src/Machine.Specifications.Should/Machine.Specifications.Should.csproj +++ b/src/Machine.Specifications.Should/Machine.Specifications.Should.csproj @@ -1,5 +1,9 @@ <Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <RootNamespace>Machine.Specifications</RootNamespace> + </PropertyGroup> + <PropertyGroup> <Description>Assertion library for Machine.Specifications</Description> </PropertyGroup> diff --git a/src/Machine.Specifications.Templates/Machine.Specifications.Templates.csproj b/src/Machine.Specifications.Templates/Machine.Specifications.Templates.csproj new file mode 100644 index 000000000..bef03830d --- /dev/null +++ b/src/Machine.Specifications.Templates/Machine.Specifications.Templates.csproj @@ -0,0 +1,2 @@ +<Project Sdk="Microsoft.NET.Sdk"> +</Project> diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props new file mode 100644 index 000000000..839a65f1b --- /dev/null +++ b/tests/Directory.Build.props @@ -0,0 +1,10 @@ +<Project> + + <Import Project="../Directory.Build.props" /> + + <PropertyGroup> + <TargetFramework>net10.0</TargetFramework> + <IsPackable>false</IsPackable> + </PropertyGroup> + +</Project> diff --git a/src/Machine.Specifications.Analyzers.Tests/AnalyzerVerifier.cs b/tests/Machine.Specifications.Analyzers.Specs/AnalyzerVerifier.cs similarity index 100% rename from src/Machine.Specifications.Analyzers.Tests/AnalyzerVerifier.cs rename to tests/Machine.Specifications.Analyzers.Specs/AnalyzerVerifier.cs diff --git a/src/Machine.Specifications.Analyzers.Tests/CodeFixVerifier.cs b/tests/Machine.Specifications.Analyzers.Specs/CodeFixVerifier.cs similarity index 100% rename from src/Machine.Specifications.Analyzers.Tests/CodeFixVerifier.cs rename to tests/Machine.Specifications.Analyzers.Specs/CodeFixVerifier.cs diff --git a/tests/Machine.Specifications.Analyzers.Specs/Machine.Specifications.Analyzers.Specs.csproj b/tests/Machine.Specifications.Analyzers.Specs/Machine.Specifications.Analyzers.Specs.csproj new file mode 100644 index 000000000..b43d47fba --- /dev/null +++ b/tests/Machine.Specifications.Analyzers.Specs/Machine.Specifications.Analyzers.Specs.csproj @@ -0,0 +1,15 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <ItemGroup> + <PackageReference Include="Microsoft.CodeAnalysis" Version="5.0.0" /> + <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.4" /> + <PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.4" /> + <PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing" Version="1.1.4" /> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\..\src\Machine.Specifications.Analyzers\Machine.Specifications.Analyzers.csproj" /> + <ProjectReference Include="..\..\src\Machine.Specifications.Core\Machine.Specifications.Core.csproj" /> + </ItemGroup> + +</Project> diff --git a/src/Machine.Specifications.Analyzers.Tests/Maintainability/AccessModifierShouldNotBeUsedTests.cs b/tests/Machine.Specifications.Analyzers.Specs/Maintainability/AccessModifierShouldNotBeUsedTests.cs similarity index 72% rename from src/Machine.Specifications.Analyzers.Tests/Maintainability/AccessModifierShouldNotBeUsedTests.cs rename to tests/Machine.Specifications.Analyzers.Specs/Maintainability/AccessModifierShouldNotBeUsedTests.cs index 275b80c2c..8fc49bf73 100644 --- a/src/Machine.Specifications.Analyzers.Tests/Maintainability/AccessModifierShouldNotBeUsedTests.cs +++ b/tests/Machine.Specifications.Analyzers.Specs/Maintainability/AccessModifierShouldNotBeUsedTests.cs @@ -1,5 +1,6 @@ -using System.Threading.Tasks; -using Xunit; +using System.Threading.Tasks; +using Machine.Specifications.Analyzers.Naming; +using Microsoft.CodeAnalysis.Testing; using Verify = Machine.Specifications.Analyzers.Tests.CodeFixVerifier< Machine.Specifications.Analyzers.Maintainability.AccessModifierShouldNotBeUsedAnalyzer, Machine.Specifications.Analyzers.Maintainability.AccessModifierShouldNotBeUsedCodeFixProvider>; @@ -8,8 +9,7 @@ namespace Machine.Specifications.Analyzers.Tests.Maintainability; public class AccessModifierShouldNotBeUsedTests { - [Fact] - public async Task NoErrorsInValidSource() + public class NoErrorsInValidSource { const string source = @" using System; @@ -31,12 +31,11 @@ class inner_specs } } }"; - - await Verify.VerifyAnalyzerAsync(source); + It should_verify = async () => + await Verify.VerifyAnalyzerAsync(source); } - [Fact] - public async Task RemovesClassAccessModifier() + public class RemovesClassAccessModifier() { const string source = @" using System; @@ -64,15 +63,18 @@ class SpecsClass } }"; - var expected = Verify.Diagnostic(DiagnosticIds.Maintainability.AccessModifierShouldNotBeUsed) - .WithLocation(0) - .WithArguments("SpecsClass"); + static DiagnosticResult expected; + + Because of = () => + expected = Verify.Diagnostic(DiagnosticIds.Maintainability.AccessModifierShouldNotBeUsed) + .WithLocation(0) + .WithArguments("SpecsClass"); - await Verify.VerifyCodeFixAsync(source, expected, fixedSource); + It should_verify = async () => + await Verify.VerifyCodeFixAsync(source, expected, fixedSource); } - [Fact] - public async Task RemovesFieldAccessModifier() + public class RemovesFieldAccessModifier { const string source = @" using System; @@ -100,15 +102,18 @@ class SpecsClass } }"; - var expected = Verify.Diagnostic(DiagnosticIds.Maintainability.AccessModifierShouldNotBeUsed) - .WithLocation(0) - .WithArguments("should_do_something"); + static DiagnosticResult expected; + + Because of = () => + expected = Verify.Diagnostic(DiagnosticIds.Maintainability.AccessModifierShouldNotBeUsed) + .WithLocation(0) + .WithArguments("should_do_something"); - await Verify.VerifyCodeFixAsync(source, expected, fixedSource); + It should_verify = async () => + await Verify.VerifyCodeFixAsync(source, expected, fixedSource); } - [Fact] - public async Task RemovesFieldAndClassAccessModifiers() + public class RemovesFieldAndClassAccessModifiers { const string source = @" using System; @@ -136,8 +141,10 @@ class SpecsClass } }"; - var expected = new[] - { + static DiagnosticResult[] expected; + + Because of = () => expected = + [ Verify.Diagnostic(DiagnosticIds.Maintainability.AccessModifierShouldNotBeUsed) .WithLocation(0) .WithArguments("SpecsClass"), @@ -145,13 +152,13 @@ class SpecsClass Verify.Diagnostic(DiagnosticIds.Maintainability.AccessModifierShouldNotBeUsed) .WithLocation(1) .WithArguments("should_do_something") - }; + ]; - await Verify.VerifyCodeFixAsync(source, expected, fixedSource); + It should_verify = async () => + await Verify.VerifyCodeFixAsync(source, expected, fixedSource); } - [Fact] - public async Task RemovesInnerFieldAndClassAccessModifiers() + public class RemovesInnerFieldAndClassAccessModifiers { const string source = @" using System; @@ -195,8 +202,10 @@ class InnerClass } }"; - var expected = new[] - { + static DiagnosticResult[] expected; + + Because of = () => expected = + [ Verify.Diagnostic(DiagnosticIds.Maintainability.AccessModifierShouldNotBeUsed) .WithLocation(0) .WithArguments("value"), @@ -208,13 +217,13 @@ class InnerClass Verify.Diagnostic(DiagnosticIds.Maintainability.AccessModifierShouldNotBeUsed) .WithLocation(2) .WithArguments("context") - }; + ]; - await Verify.VerifyCodeFixAsync(source, expected, fixedSource); + It should_verify = async () => + await Verify.VerifyCodeFixAsync(source, expected, fixedSource); } - [Fact] - public async Task RemovesFieldAccessModifierWithLeadingTrivia() + public class RemovesFieldAccessModifierWithLeadingTrivia { const string source = @" using System; @@ -246,11 +255,11 @@ class SpecsClass } }"; - await Verify.VerifyCodeFixAsync(source, fixedSource); + It should_verify = async () => + await Verify.VerifyCodeFixAsync(source, fixedSource); } - [Fact] - public async Task RemovesMultipleAccessModifiers() + public class RemovesMultipleAccessModifiers { const string source = @" using System; @@ -282,6 +291,7 @@ class SpecsClass } }"; - await Verify.VerifyCodeFixAsync(source, fixedSource); + It should_verify = async () => + await Verify.VerifyCodeFixAsync(source, fixedSource); } } diff --git a/src/Machine.Specifications.Analyzers.Tests/VerifierHelper.cs b/tests/Machine.Specifications.Analyzers.Specs/VerifierHelper.cs similarity index 100% rename from src/Machine.Specifications.Analyzers.Tests/VerifierHelper.cs rename to tests/Machine.Specifications.Analyzers.Specs/VerifierHelper.cs diff --git a/tests/Machine.Specifications.Core.SourceGenerator.Specs/Machine.Specifications.Core.SourceGenerator.Specs.csproj b/tests/Machine.Specifications.Core.SourceGenerator.Specs/Machine.Specifications.Core.SourceGenerator.Specs.csproj new file mode 100644 index 000000000..bef03830d --- /dev/null +++ b/tests/Machine.Specifications.Core.SourceGenerator.Specs/Machine.Specifications.Core.SourceGenerator.Specs.csproj @@ -0,0 +1,2 @@ +<Project Sdk="Microsoft.NET.Sdk"> +</Project> diff --git a/src/Machine.Specifications.Core.Specs/.editorconfig b/tests/Machine.Specifications.Core.Specs/.editorconfig similarity index 100% rename from src/Machine.Specifications.Core.Specs/.editorconfig rename to tests/Machine.Specifications.Core.Specs/.editorconfig diff --git a/src/Machine.Specifications.Core.Specs/CatchSpecs.cs b/tests/Machine.Specifications.Core.Specs/CatchSpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/CatchSpecs.cs rename to tests/Machine.Specifications.Core.Specs/CatchSpecs.cs diff --git a/src/Machine.Specifications.Core.Specs/Controller/ControllerSpecs.cs b/tests/Machine.Specifications.Core.Specs/Controller/ControllerSpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Controller/ControllerSpecs.cs rename to tests/Machine.Specifications.Core.Specs/Controller/ControllerSpecs.cs diff --git a/src/Machine.Specifications.Core.Specs/ExceptionResultSpecs.cs b/tests/Machine.Specifications.Core.Specs/ExceptionResultSpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/ExceptionResultSpecs.cs rename to tests/Machine.Specifications.Core.Specs/ExceptionResultSpecs.cs diff --git a/src/Machine.Specifications.Core.Specs/Explorers/AssemblyExplorerSpecs.cs b/tests/Machine.Specifications.Core.Specs/Explorers/AssemblyExplorerSpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Explorers/AssemblyExplorerSpecs.cs rename to tests/Machine.Specifications.Core.Specs/Explorers/AssemblyExplorerSpecs.cs diff --git a/src/Machine.Specifications.Core.Specs/Factories/ContextFactorySpecs.cs b/tests/Machine.Specifications.Core.Specs/Factories/ContextFactorySpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Factories/ContextFactorySpecs.cs rename to tests/Machine.Specifications.Core.Specs/Factories/ContextFactorySpecs.cs diff --git a/src/Machine.Specifications.Core.Specs/Factories/SpecificationFactorySpecs.cs b/tests/Machine.Specifications.Core.Specs/Factories/SpecificationFactorySpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Factories/SpecificationFactorySpecs.cs rename to tests/Machine.Specifications.Core.Specs/Factories/SpecificationFactorySpecs.cs diff --git a/src/Machine.Specifications.Fixtures/ExampleFixture.cs b/tests/Machine.Specifications.Core.Specs/Fixtures/ExampleFixture.cs similarity index 100% rename from src/Machine.Specifications.Fixtures/ExampleFixture.cs rename to tests/Machine.Specifications.Core.Specs/Fixtures/ExampleFixture.cs diff --git a/src/Machine.Specifications.Fixtures/FailingFixture.cs b/tests/Machine.Specifications.Core.Specs/Fixtures/FailingFixture.cs similarity index 100% rename from src/Machine.Specifications.Fixtures/FailingFixture.cs rename to tests/Machine.Specifications.Core.Specs/Fixtures/FailingFixture.cs diff --git a/src/Machine.Specifications.Fixtures/LargeFixture.cs b/tests/Machine.Specifications.Core.Specs/Fixtures/LargeFixture.cs similarity index 100% rename from src/Machine.Specifications.Fixtures/LargeFixture.cs rename to tests/Machine.Specifications.Core.Specs/Fixtures/LargeFixture.cs diff --git a/src/Machine.Specifications.Fixtures/RandomFixture.cs b/tests/Machine.Specifications.Core.Specs/Fixtures/RandomFixture.cs similarity index 100% rename from src/Machine.Specifications.Fixtures/RandomFixture.cs rename to tests/Machine.Specifications.Core.Specs/Fixtures/RandomFixture.cs diff --git a/tests/Machine.Specifications.Core.Specs/Machine.Specifications.Core.Specs.csproj b/tests/Machine.Specifications.Core.Specs/Machine.Specifications.Core.Specs.csproj new file mode 100644 index 000000000..da11eb34c --- /dev/null +++ b/tests/Machine.Specifications.Core.Specs/Machine.Specifications.Core.Specs.csproj @@ -0,0 +1,8 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <ItemGroup> + <ProjectReference Include="..\..\src\Machine.Specifications.Core\Machine.Specifications.Core.csproj" /> + <ProjectReference Include="..\..\src\Machine.Specifications.Should\Machine.Specifications.Should.csproj" /> + </ItemGroup> + +</Project> diff --git a/src/Machine.Specifications.Core.Specs/Model/ContextSpecs.cs b/tests/Machine.Specifications.Core.Specs/Model/ContextSpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Model/ContextSpecs.cs rename to tests/Machine.Specifications.Core.Specs/Model/ContextSpecs.cs diff --git a/src/Machine.Specifications.Core.Specs/Model/SpecificationSpecs.cs b/tests/Machine.Specifications.Core.Specs/Model/SpecificationSpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Model/SpecificationSpecs.cs rename to tests/Machine.Specifications.Core.Specs/Model/SpecificationSpecs.cs diff --git a/src/Machine.Specifications.Core.Specs/Runner/AsyncDelegateRunnerSpecs.cs b/tests/Machine.Specifications.Core.Specs/Runner/AsyncDelegateRunnerSpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Runner/AsyncDelegateRunnerSpecs.cs rename to tests/Machine.Specifications.Core.Specs/Runner/AsyncDelegateRunnerSpecs.cs diff --git a/src/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerSpecs.cs b/tests/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerSpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerSpecs.cs rename to tests/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerSpecs.cs diff --git a/src/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerWithBehaviorSpecs.cs b/tests/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerWithBehaviorSpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerWithBehaviorSpecs.cs rename to tests/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerWithBehaviorSpecs.cs diff --git a/src/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerWithInheritanceSpecs.cs b/tests/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerWithInheritanceSpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerWithInheritanceSpecs.cs rename to tests/Machine.Specifications.Core.Specs/Runner/SpecificationRunnerWithInheritanceSpecs.cs diff --git a/src/Machine.Specifications.Core.Specs/Tags.cs b/tests/Machine.Specifications.Core.Specs/Tags.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Tags.cs rename to tests/Machine.Specifications.Core.Specs/Tags.cs diff --git a/src/Machine.Specifications.Core.Specs/Utility/Internal/NamingSpecs.cs b/tests/Machine.Specifications.Core.Specs/Utility/Internal/NamingSpecs.cs similarity index 100% rename from src/Machine.Specifications.Core.Specs/Utility/Internal/NamingSpecs.cs rename to tests/Machine.Specifications.Core.Specs/Utility/Internal/NamingSpecs.cs diff --git a/tests/Machine.Specifications.Fakes.Analzyers.Specs/Machine.Specifications.Fakes.Analzyers.Specs.csproj b/tests/Machine.Specifications.Fakes.Analzyers.Specs/Machine.Specifications.Fakes.Analzyers.Specs.csproj new file mode 100644 index 000000000..bef03830d --- /dev/null +++ b/tests/Machine.Specifications.Fakes.Analzyers.Specs/Machine.Specifications.Fakes.Analzyers.Specs.csproj @@ -0,0 +1,2 @@ +<Project Sdk="Microsoft.NET.Sdk"> +</Project> diff --git a/tests/Machine.Specifications.Fakes.SourceGenerator.Specs/Machine.Specifications.Fakes.SourceGenerator.Specs.csproj b/tests/Machine.Specifications.Fakes.SourceGenerator.Specs/Machine.Specifications.Fakes.SourceGenerator.Specs.csproj new file mode 100644 index 000000000..bef03830d --- /dev/null +++ b/tests/Machine.Specifications.Fakes.SourceGenerator.Specs/Machine.Specifications.Fakes.SourceGenerator.Specs.csproj @@ -0,0 +1,2 @@ +<Project Sdk="Microsoft.NET.Sdk"> +</Project> diff --git a/src/Machine.Specifications.Fakes.Specs/DeepFake.cs b/tests/Machine.Specifications.Fakes.Specs/DeepFake.cs similarity index 100% rename from src/Machine.Specifications.Fakes.Specs/DeepFake.cs rename to tests/Machine.Specifications.Fakes.Specs/DeepFake.cs diff --git a/tests/Machine.Specifications.Fakes.Specs/Machine.Specifications.Fakes.Specs.csproj b/tests/Machine.Specifications.Fakes.Specs/Machine.Specifications.Fakes.Specs.csproj new file mode 100644 index 000000000..f25d703ea --- /dev/null +++ b/tests/Machine.Specifications.Fakes.Specs/Machine.Specifications.Fakes.Specs.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + +<ItemGroup> + <ProjectReference Include="..\..\src\Machine.Specifications.Core\Machine.Specifications.Core.csproj" /> + <ProjectReference Include="..\..\src\Machine.Specifications.Fakes\Machine.Specifications.Fakes.csproj" /> + <ProjectReference Include="..\..\src\Machine.Specifications.Should\Machine.Specifications.Should.csproj" /> + </ItemGroup> + +</Project> diff --git a/src/Machine.Specifications.Fakes.Specs/TestSpec.cs b/tests/Machine.Specifications.Fakes.Specs/TestSpec.cs similarity index 100% rename from src/Machine.Specifications.Fakes.Specs/TestSpec.cs rename to tests/Machine.Specifications.Fakes.Specs/TestSpec.cs diff --git a/tests/Machine.Specifications.Fixtures/ExampleFixture.cs b/tests/Machine.Specifications.Fixtures/ExampleFixture.cs new file mode 100644 index 000000000..a12f8a30a --- /dev/null +++ b/tests/Machine.Specifications.Fixtures/ExampleFixture.cs @@ -0,0 +1,91 @@ +using System; +using Machine.Specifications; + +namespace Example +{ + public class Account + { + public decimal Balance { get; set; } + + public void Transfer(decimal amount, Account toAccount) + { + if (amount > Balance) + throw new Exception(String.Format("Cannot transfer ${ 0 }.The available balance is ${ 1}.", amount, Balance)); + + Balance -= amount; + toAccount.Balance += amount; + } + } + + public class TestAssemblyContext : IAssemblyContext + { + public static bool OnAssemblyStartRun; + + public static bool OnAssemblyCompleteRun; + + public void OnAssemblyStart() + { + OnAssemblyStartRun = true; + } + + public void OnAssemblyComplete() + { + OnAssemblyCompleteRun = true; + } + } + + [Subject(typeof(Account), "Funds transfer")] + public class when_transferring_between_two_accounts : AccountSpecs + { + Establish context = () => + { + fromAccount = new Account { Balance = 1m }; + toAccount = new Account { Balance = 1m }; + }; + + Because of = () => + fromAccount.Transfer(1m, toAccount); + + It should_debit_the_from_account_by_the_amount_transferred = () => + fromAccount.Balance.ShouldEqual(0m); + + It should_credit_the_to_account_by_the_amount_transferred = () => + toAccount.Balance.ShouldEqual(2m); + } + + [Subject(typeof(Account), "Funds transfer")] + [Tags("failure")] + public class when_transferring_an_amount_larger_than_the_balance_of_the_from_account : AccountSpecs + { + static Exception exception; + + Establish context = () => + { + fromAccount = new Account { Balance = 1m }; + toAccount = new Account { Balance = 1m }; + }; + + Because of = () => + exception = Catch.Exception(() => fromAccount.Transfer(2m, toAccount)); + + It should_not_allow_the_transfer = () => + exception.ShouldBeOfExactType<Exception>(); + } + + public abstract class AccountSpecs + { + protected static Account fromAccount; + + protected static Account toAccount; + } + + [Subject("Recent Account Activity Summary page")] + public class when_a_customer_first_views_the_account_summary_page + { + It should_display_all_account_transactions_for_the_past_thirty_days; + + It should_display_debit_amounts_in_red_text; + + It should_display_deposit_amounts_in_black_text; + } +} diff --git a/tests/Machine.Specifications.Fixtures/FailingFixture.cs b/tests/Machine.Specifications.Fixtures/FailingFixture.cs new file mode 100644 index 000000000..92b7a74d7 --- /dev/null +++ b/tests/Machine.Specifications.Fixtures/FailingFixture.cs @@ -0,0 +1,35 @@ +using System; +using Machine.Specifications; + +namespace Example.Failing +{ + [Subject("Scott Bellware")] + public class at_any_given_moment + { + It will_fail = () => + throw new Exception("hi scott, love you, miss you."); + } + + [Tags("example")] + public class context_with_multiple_establish_clauses + { + Establish foo = () => { }; + + Establish bar = () => { }; + + It should = () => { }; + } + + [SetupDelegate] + public delegate void Given(); + + [Tags("example")] + public class context_with_multiple_given_clauses + { + Given foo = () => { }; + + Given bar = () => { }; + + It should = () => { }; + } +} diff --git a/tests/Machine.Specifications.Fixtures/LargeFixture.cs b/tests/Machine.Specifications.Fixtures/LargeFixture.cs new file mode 100644 index 000000000..1d2bf0ef2 --- /dev/null +++ b/tests/Machine.Specifications.Fixtures/LargeFixture.cs @@ -0,0 +1,1025 @@ +using System; +using System.Diagnostics; +using System.Reflection; +using System.Threading.Tasks; +using Machine.Specifications; + +namespace Example.Large +{ + public class when_there_are_many_contexts + { + public static bool Created = false; + + public when_there_are_many_contexts() + { + Created = true; + } + + It spec = () => { }; + } + + public static class OtherTests + { + public static bool Created = false; + } + + class when_there_are_many_contexts_1 + { + when_there_are_many_contexts_1() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_2 + { + when_there_are_many_contexts_2() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_3 + { + when_there_are_many_contexts_3() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_4 + { + when_there_are_many_contexts_4() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_5 + { + when_there_are_many_contexts_5() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_6 + { + when_there_are_many_contexts_6() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_7 + { + when_there_are_many_contexts_7() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_8 + { + when_there_are_many_contexts_8() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_9 + { + when_there_are_many_contexts_9() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_10 + { + when_there_are_many_contexts_10() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_11 + { + when_there_are_many_contexts_11() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_12 + { + when_there_are_many_contexts_12() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_13 + { + when_there_are_many_contexts_13() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_14 + { + when_there_are_many_contexts_14() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_15 + { + when_there_are_many_contexts_15() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_16 + { + when_there_are_many_contexts_16() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_17 + { + when_there_are_many_contexts_17() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_18 + { + when_there_are_many_contexts_18() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_19 + { + when_there_are_many_contexts_19() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_20 + { + when_there_are_many_contexts_20() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_21 + { + when_there_are_many_contexts_21() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_22 + { + when_there_are_many_contexts_22() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_23 + { + when_there_are_many_contexts_23() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_24 + { + when_there_are_many_contexts_24() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_25 + { + when_there_are_many_contexts_25() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_26 + { + when_there_are_many_contexts_26() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_27 + { + when_there_are_many_contexts_27() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_28 + { + when_there_are_many_contexts_28() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_29 + { + when_there_are_many_contexts_29() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_30 + { + when_there_are_many_contexts_30() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_31 + { + when_there_are_many_contexts_31() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_32 + { + when_there_are_many_contexts_32() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_33 + { + when_there_are_many_contexts_33() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_34 + { + when_there_are_many_contexts_34() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_35 + { + when_there_are_many_contexts_35() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_36 + { + when_there_are_many_contexts_36() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_37 + { + when_there_are_many_contexts_37() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_38 + { + when_there_are_many_contexts_38() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_39 + { + when_there_are_many_contexts_39() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_40 + { + when_there_are_many_contexts_40() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_41 + { + when_there_are_many_contexts_41() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_42 + { + when_there_are_many_contexts_42() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_43 + { + when_there_are_many_contexts_43() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_44 + { + when_there_are_many_contexts_44() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_45 + { + when_there_are_many_contexts_45() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_46 + { + when_there_are_many_contexts_46() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_47 + { + when_there_are_many_contexts_47() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_48 + { + when_there_are_many_contexts_48() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_49 + { + when_there_are_many_contexts_49() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_50 + { + when_there_are_many_contexts_50() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_51 + { + when_there_are_many_contexts_51() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_52 + { + when_there_are_many_contexts_52() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_53 + { + when_there_are_many_contexts_53() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_54 + { + when_there_are_many_contexts_54() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_55 + { + when_there_are_many_contexts_55() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_56 + { + when_there_are_many_contexts_56() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_57 + { + when_there_are_many_contexts_57() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_58 + { + when_there_are_many_contexts_58() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_59 + { + when_there_are_many_contexts_59() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_60 + { + when_there_are_many_contexts_60() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_61 + { + when_there_are_many_contexts_61() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_62 + { + when_there_are_many_contexts_62() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_63 + { + when_there_are_many_contexts_63() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_64 + { + when_there_are_many_contexts_64() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_65 + { + when_there_are_many_contexts_65() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_66 + { + when_there_are_many_contexts_66() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_67 + { + when_there_are_many_contexts_67() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_68 + { + when_there_are_many_contexts_68() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_69 + { + when_there_are_many_contexts_69() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_70 + { + when_there_are_many_contexts_70() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_71 + { + when_there_are_many_contexts_71() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_72 + { + when_there_are_many_contexts_72() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_73 + { + when_there_are_many_contexts_73() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_74 + { + when_there_are_many_contexts_74() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_75 + { + when_there_are_many_contexts_75() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_76 + { + when_there_are_many_contexts_76() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_77 + { + when_there_are_many_contexts_77() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_78 + { + when_there_are_many_contexts_78() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_79 + { + when_there_are_many_contexts_79() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_80 + { + when_there_are_many_contexts_80() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_81 + { + when_there_are_many_contexts_81() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_82 + { + when_there_are_many_contexts_82() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_83 + { + when_there_are_many_contexts_83() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_84 + { + when_there_are_many_contexts_84() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_85 + { + when_there_are_many_contexts_85() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_86 + { + when_there_are_many_contexts_86() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_87 + { + when_there_are_many_contexts_87() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_88 + { + when_there_are_many_contexts_88() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_89 + { + when_there_are_many_contexts_89() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_90 + { + when_there_are_many_contexts_90() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_91 + { + when_there_are_many_contexts_91() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_92 + { + when_there_are_many_contexts_92() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_93 + { + when_there_are_many_contexts_93() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_94 + { + when_there_are_many_contexts_94() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_95 + { + when_there_are_many_contexts_95() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_96 + { + when_there_are_many_contexts_96() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_97 + { + when_there_are_many_contexts_97() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_98 + { + when_there_are_many_contexts_98() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_99 + { + when_there_are_many_contexts_99() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } + + class when_there_are_many_contexts_100 + { + when_there_are_many_contexts_100() + { + OtherTests.Created = true; + } + + It spec = () => { }; + } +} diff --git a/src/Machine.Specifications.Fixtures/Machine.Specifications.Fixtures.csproj b/tests/Machine.Specifications.Fixtures/Machine.Specifications.Fixtures.csproj similarity index 79% rename from src/Machine.Specifications.Fixtures/Machine.Specifications.Fixtures.csproj rename to tests/Machine.Specifications.Fixtures/Machine.Specifications.Fixtures.csproj index a2e918693..42475085b 100644 --- a/src/Machine.Specifications.Fixtures/Machine.Specifications.Fixtures.csproj +++ b/tests/Machine.Specifications.Fixtures/Machine.Specifications.Fixtures.csproj @@ -1,9 +1,5 @@ <Project Sdk="Microsoft.NET.Sdk"> - <PropertyGroup> - <IsPackable>false</IsPackable> - </PropertyGroup> - <ItemGroup> <ProjectReference Include="..\Machine.Specifications.Core\Machine.Specifications.Core.csproj" /> <ProjectReference Include="..\Machine.Specifications.Should\Machine.Specifications.Should.csproj" /> diff --git a/tests/Machine.Specifications.Fixtures/RandomFixture.cs b/tests/Machine.Specifications.Fixtures/RandomFixture.cs new file mode 100644 index 000000000..1545c2aac --- /dev/null +++ b/tests/Machine.Specifications.Fixtures/RandomFixture.cs @@ -0,0 +1,1158 @@ +using System; +using System.Reflection; +using System.Threading.Tasks; +using Machine.Specifications; + +namespace Example.Random +{ + public class TestAssemblyContext : IAssemblyContext + { + public static bool OnAssemblyStartRun; + + public static bool OnAssemblyCompleteRun; + + public void OnAssemblyStart() + { + OnAssemblyStartRun = true; + } + + public void OnAssemblyComplete() + { + OnAssemblyCompleteRun = true; + } + } + + public static class StaticContainer + { + static readonly bool Foo; + + static StaticContainer() + { + Foo = true; + } + + public class when_a_context_is_nested_inside_a_static_class + { + It should_be_run = () => + Foo.ShouldBeTrue(); + } + } + + public class NonStaticContainer + { + static readonly bool Bar; + + static NonStaticContainer() + { + Bar = true; + } + + public static class StaticContainer + { + static readonly bool Foo; + + static StaticContainer() + { + Foo = true; + } + + public class when_a_context_is_nested_inside_a_static_class_that_is_nested_inside_a_class + { + It should_be_run = () => + { + Foo.ShouldBeTrue(); + Bar.ShouldBeTrue(); + }; + } + } + } + + public static class tag + { + public const string example = "example"; + + public const string some_other_tag = "some other tag"; + + public const string one_more_tag = "one more tag"; + } + + [SetupForEachSpecification, Tags(tag.example)] + public class context_with_multiple_specifications_and_setup_for_each + { + public static int establish_run_count; + + public static int because_clause_run_count; + + Establish context = () => + establish_run_count++; + + Because of = () => + because_clause_run_count++; + + It spec1 = () => { }; + + It spec2 = () => { }; + } + + [Tags(tag.example, "foobar")] + public class context_with_multiple_specifications + { + public static int establish_run_count; + + public static int because_clause_run_count; + + Establish context = () => + establish_run_count++; + + Because of = () => + because_clause_run_count++; + + It spec1 = () => { }; + + It spec2 = () => { }; + } + + [Tags(tag.example, tag.example)] + [Tags(tag.example)] + public class context_with_duplicate_tags + { + It bla_bla = () => { }; + } + + [Tags(tag.example, tag.some_other_tag, tag.one_more_tag)] + public class context_with_tags + { + It bla_bla = () => { }; + } + + public class context_with_unimplemented_specs + { + It should_be_unimplemented; + } + + [Ignore("example reason")] + public class context_with_ignore : context_with_no_specs + { + public static bool ignored_spec_ran; + + It should_be_ignored = () => + ignored_spec_ran = true; + } + + public class context_with_ignore_on_one_spec : context_with_no_specs + { + public static bool ignored_spec_ran; + + [Ignore("example reason")] + It should_be_ignored = () => + ignored_spec_ran = true; + } + + [Ignore("example reason")] + public class context_with_ignore_and_reason : context_with_no_specs + { + public static bool ignored_spec_ran; + + It should_be_ignored = () => + ignored_spec_ran = true; + } + + public class context_with_ignore_and_reason_on_one_spec : context_with_no_specs + { + public static bool ignored_spec_ran; + + [Ignore("example reason")] + It should_be_ignored = () => + ignored_spec_ran = true; + } + + [Tags(tag.example)] + public class context_with_no_specs + { + public static bool context_established; + + public static bool cleanup_occurred; + + Establish context = () => + context_established = true; + + Cleanup after_each = () => + cleanup_occurred = true; + } + + [Subject(typeof(int), "Some description")] + [Tags(tag.example)] + public class context_with_subject + { + } + + public class context_with_parent_with_subject : context_with_subject + { + } + + [Subject(typeof(int), "Parent description")] + public class parent_context + { + It should_be_able_to_assert_something = () => + true.ShouldBeTrue(); + + public class nested_context + { + It should_be_able_to_assert_something_else = () => + false.ShouldBeFalse(); + } + + public class nested_context_inheriting_another_concern : context_with_subject + { + It should_be_able_to_assert_something_else = () => + false.ShouldBeFalse(); + } + + [Subject(typeof(int), "Nested description")] + public class nested_context_inheriting_and_owning_a_concern : context_with_subject + { + It should_be_able_to_assert_something_else = () => + false.ShouldBeFalse(); + } + } + + public class parent_context_without_concern + { + It should_be_able_to_assert_something = () => + true.ShouldBeTrue(); + + public class nested_context + { + It should_be_able_to_assert_something_else = () => + false.ShouldBeFalse(); + } + } + + public class parent_context_that_has_its_own_because_block + { + Because of = () => { }; + + public class nested_context_that_has_a_because_block_which + { + Because of = () => { }; + } + } + + [Tags(tag.example)] + public class context_with_failing_specs + { + It should = () => + throw new InvalidOperationException("something went wrong"); + } + + [Tags(tag.example)] + public class context_with_failing_establish + { + Establish context = () => + throw new InvalidOperationException("something went wrong"); + + It should = () => { }; + } + + [Tags(tag.example)] + public class context_with_failing_because + { + Because of = () => + throw new InvalidOperationException("something went wrong"); + + It should = () => { }; + } + + [Tags(tag.example)] + public class context_with_failing_cleanup + { + public static readonly Exception ExceptionThrownByCleanup = new InvalidOperationException("something went wrong"); + + It should = () => { }; + + Cleanup after = () => + { + throw ExceptionThrownByCleanup; + }; + } + + [Tags(tag.example)] + public class context_with_console_output + { + Establish context = () => + Console.Out.WriteLine("Console.Out message in establish"); + + Because of = () => + Console.Out.WriteLine("Console.Out message in because"); + + Cleanup after = () => + Console.Out.WriteLine("Console.Out message in cleanup"); + + It should_log_messages = () => + Console.Out.WriteLine("Console.Out message in spec"); + + It should_log_messages_also_for_the_nth_spec = () => + Console.Out.WriteLine("Console.Out message in nth spec"); + } + + [Tags(tag.example)] + public class context_with_console_error_output + { + Establish context = () => + Console.Error.WriteLine("Console.Error message in establish"); + + Because of = () => + Console.Error.WriteLine("Console.Error message in because"); + + Cleanup after = () => + Console.Error.WriteLine("Console.Error message in cleanup"); + + It should_log_messages = () => + Console.Error.WriteLine("Console.Error message in spec"); + + It should_log_messages_also_for_the_nth_spec = () => + Console.Error.WriteLine("Console.Error message in nth spec"); + } + + [Tags(tag.example)] + public class context_with_debug_output + { + Establish context = () => + Console.WriteLine("Debug.WriteLine message in establish"); + + Because of = () => + Console.WriteLine("Debug.WriteLine message in because"); + + Cleanup after = () => + Console.WriteLine("Debug.WriteLine message in cleanup"); + + It should_log_messages = () => + Console.WriteLine("Debug.WriteLine message in spec"); + + It should_log_messages_also_for_the_nth_spec = () => + Console.WriteLine("Debug.WriteLine message in nth spec"); + } + + [SetupForEachSpecification, Tags(tag.example)] + public class context_with_console_output_and_setup_for_each + { + Establish context = () => + Console.Out.WriteLine("Console.Out message in establish"); + + Because of = () => + Console.Out.WriteLine("Console.Out message in because"); + + Cleanup after = () => + Console.Out.WriteLine("Console.Out message in cleanup"); + + It should_log_messages = () => + Console.Out.WriteLine("Console.Out message in spec"); + + It should_log_messages_also_for_the_nth_spec = () => + Console.Out.WriteLine("Console.Out message in nth spec"); + } + + [Tags(tag.example)] + public class context_with_inner_exception + { + It should_throw = () => + { + try + { + throw new Exception("INNER123"); + } + catch (Exception err) + { + throw new TargetInvocationException(err); + } + }; + } + + public class Container + { + [Tags(tag.example)] + public class nested_context + { + It should_be_run = () => { }; + } + } + + [Tags(tag.example)] + public class context_with_public_It_field + { + public It should; + } + + [Tags(tag.example)] + public class context_with_protected_It_field + { + protected It should; + } + + [Tags(tag.example)] + public class context_with_internal_It_field + { + internal It should; + } + + [Tags(tag.example)] + public class context_with_public_Behaves_like_field + { + public Behaves_like<Behaviors> behavior; + } + + [Tags(tag.example)] + public class context_with_nonprivate_framework_fields + { + public Establish establish; + + public Because because; + + public Cleanup cleanup; + + internal Behaves_like<Behaviors> behavior; + + protected It specification; + + It private_specification; + } + + [Tags(tag.example)] + public class generic_container<Type1> + { + public class nested_context + { + } + + public class nested_generic_context<Type2> + { + public class nested_nested_non_generic + { + } + + public class nested_nested_generic<Type3> + { + } + } + } + + [Tags(tag.example, "behavior usage")] + public class context_with_behaviors + { + public static bool local_spec_ran; + + It should_run = () => local_spec_ran = true; + + Behaves_like<Behaviors> behavior; + } + + [Tags(tag.example, "behavior usage")] + public class second_context_with_behaviors + { + Behaves_like<Behaviors> behavior; + } + + [Tags(tag.example)] + public class context_with_behaviors_where_the_behavior_field_is_ignored + { + public static bool local_spec_ran; + + It should_run = () => + local_spec_ran = true; + + [Ignore("example reason")] + Behaves_like<Behaviors> behavior; + } + + [Tags(tag.example)] + public class context_with_behaviors_where_the_behavior_is_ignored + { + public static bool local_spec_ran; + + It should_run = () => + local_spec_ran = true; + + Behaves_like<IgnoredBehaviors> behavior; + } + + [Tags(tag.example)] + public class context_with_behaviors_where_the_behavior_specs_are_ignored + { + public static bool local_spec_ran; + + It should_run = () => + local_spec_ran = true; + + Behaves_like<BehaviorsWithIgnoredSpec> behavior; + } + + [Tags(tag.example)] + public class context_with_nested_behaviors + { + public static bool local_spec_ran; + + It should_run = () => + local_spec_ran = true; + + Behaves_like<BehaviorsWithNestedBehavior> behavior_with_nested_behavior; + } + + [Tags(tag.example)] + public class context_with_behaviors_without_behaviors_attribute + { + public static bool local_spec_ran; + + It should_run = () => + local_spec_ran = true; + + Behaves_like<BehaviorsWithoutBehaviorsAttribute> behavior_without_behavior_attribute; + } + + [Tags(tag.example)] + public class context_with_behaviors_with_establish + { + public static bool local_spec_ran; + + It should_run = () => + local_spec_ran = true; + + Behaves_like<BehaviorsWithEstablish> behavior_with_establish; + } + + [Tags(tag.example)] + public class context_with_behaviors_with_because + { + public static bool local_spec_ran; + + It should_run = () => + local_spec_ran = true; + + Behaves_like<BehaviorsWithBecause> behavior_with_because; + } + + [Tags(tag.example)] + public class context_missing_protected_fields_that_are_in_behaviors + { + public static bool local_spec_ran; + + It should_not_run = () => + local_spec_ran = true; + + Behaves_like<BehaviorsWithProtectedFields> behavior_with_protected_fields; + } + + [Tags(tag.example)] + public class context_with_protected_fields_having_different_types_than_in_behaviors + { + public static bool local_spec_ran; + + protected static bool field_that_should_be_copied_over_from_context; + + It should_not_run = () => + local_spec_ran = true; + + Behaves_like<BehaviorsWithProtectedFields> behavior_with_protected_fields; + } + + [Behaviors] + public class Behaviors + { + public static bool behavior_spec_ran; + + It should_run_if_behavior_is_not_ignored = () => + behavior_spec_ran = true; + } + + [Ignore("example reason")] + [Behaviors] + public class IgnoredBehaviors + { + public static bool behavior_spec_ran; + + It should_not_run = () => + behavior_spec_ran = true; + } + + [Behaviors] + public class BehaviorsWithIgnoredSpec + { + public static bool behavior_spec_ran; + + [Ignore("example reason")] + It should_not_run = () => + behavior_spec_ran = true; + } + + [Behaviors] + public class BehaviorsWithNestedBehavior + { + Behaves_like<object> disallowed_nested_behavior; + } + + public class BehaviorsWithoutBehaviorsAttribute + { + public static bool behavior_spec_ran; + + It should_not_run = () => + behavior_spec_ran = true; + } + + [Behaviors] + public class BehaviorsWithEstablish + { + Establish context; + } + + [Behaviors] + public class BehaviorsWithBecause + { + Because of; + } + + [Behaviors] + public class BehaviorsWithProtectedFields + { + public static bool behavior_spec_ran; + + protected static int field_that_should_be_copied_over_from_context; + + It should_not_run = () => + behavior_spec_ran = true; + } + + [Subject("Context that inherits")] + [Tags(tag.example)] + public abstract class context_that_inherits + { + public static int base_establish_run_count; + + Establish context = () => + base_establish_run_count++; + + protected It should_be_inherited_but_not_executed = () => { }; + + It should_not_be_executed = () => { }; + } + + public class context_with_inherited_specifications : context_that_inherits + { + public static int because_clause_run_count; + + public static int establish_run_count; + + Establish context = () => + establish_run_count++; + + Because of = () => + because_clause_run_count++; + + It spec1 = () => { }; + + It spec2 = () => { }; + } + + [SetupForEachSpecification] + public class context_with_inherited_specifications_and_setup_for_each : context_that_inherits + { + public static int because_clause_run_count; + + public static int establish_run_count; + + Establish context = () => + establish_run_count++; + + Because of = () => + because_clause_run_count++; + + It spec1 = () => { }; + + It spec2 = () => { }; + } + + [Behaviors] + public class SampleBehaviors + { + It behavior1 = () => { }; + } + + public class context_with_specs_and_behaviors + { + Establish context = () => { }; + + Because of = () => { }; + + Behaves_like<SampleBehaviors> behaviors; + + It spec1 = () => { }; + + It spec2 = () => { }; + } + + public class TestCleanupAfterEveryContext : ICleanupAfterEveryContextInAssembly + { + public static bool AfterContextCleanupRun; + + public static int AfterContextCleanupRunCount; + + public void AfterContextCleanup() + { + ++AfterContextCleanupRunCount; + AfterContextCleanupRun = true; + } + + public static void Reset() + { + AfterContextCleanupRun = false; + AfterContextCleanupRunCount = 0; + } + } + + [Tags("foobar")] + public class TaggedCleanup : ICleanupAfterEveryContextInAssembly + { + public static bool AfterContextCleanupRun; + + public static int AfterContextCleanupRunCount; + + public void AfterContextCleanup() + { + ++AfterContextCleanupRunCount; + AfterContextCleanupRun = true; + } + + public static void Reset() + { + AfterContextCleanupRun = false; + AfterContextCleanupRunCount = 0; + } + } + + public class UntaggedCleanup : ICleanupAfterEveryContextInAssembly + { + public static bool AfterContextCleanupRun; + + public static int AfterContextCleanupRunCount; + + public void AfterContextCleanup() + { + ++AfterContextCleanupRunCount; + AfterContextCleanupRun = true; + } + + public static void Reset() + { + AfterContextCleanupRun = false; + AfterContextCleanupRunCount = 0; + } + } + + [Tags("foobar")] + public class TaggedAssemblyContext : IAssemblyContext + { + public static bool OnAssemblyStartRun; + + public static bool OnAssemblyCompleteRun; + + public static void Reset() + { + OnAssemblyStartRun = false; + OnAssemblyCompleteRun = false; + } + + public void OnAssemblyStart() + { + OnAssemblyStartRun = true; + } + + public void OnAssemblyComplete() + { + OnAssemblyCompleteRun = true; + } + } + + public class UntaggedAssemblyContext : IAssemblyContext + { + public static bool OnAssemblyStartRun; + + public static bool OnAssemblyCompleteRun; + + public static void Reset() + { + OnAssemblyStartRun = false; + OnAssemblyCompleteRun = false; + } + + public void OnAssemblyStart() + { + OnAssemblyStartRun = true; + } + + public void OnAssemblyComplete() + { + OnAssemblyCompleteRun = true; + } + } + + [Tags("foobar")] + public class TaggedResultSupplementer : ISupplementSpecificationResults + { + public static bool SupplementResultRun; + + public Result SupplementResult(Result result) + { + SupplementResultRun = true; + return result; + } + + public static void Reset() + { + SupplementResultRun = false; + } + } + + public class UntaggedResultSupplementer : ISupplementSpecificationResults + { + public static bool SupplementResultRun; + + public Result SupplementResult(Result result) + { + SupplementResultRun = true; + return result; + } + + public static void Reset() + { + SupplementResultRun = false; + } + } +} + +namespace Example.Random.Internal +{ + [Subject("Internal types")] + [Tags(tag.example)] + class when_a_context_is_internal + { + It should_work = () => + true.ShouldBeTrue(); + } + + [Subject("Internal types")] + [Tags(tag.example)] + class when_a_context_is_internal_and_uses_internal_behaviors + { + protected static bool MSpecRocks = true; + + Because of = () => + MSpecRocks = true; + + Behaves_like<WorkingSpecs> a_working_spec; + } + + [Behaviors] + class WorkingSpecs + { + protected static bool MSpecRocks; + + It should_work = () => + MSpecRocks.ShouldBeTrue(); + } +} + +namespace Example.Random.SingleContextInThisNamespace +{ + public class context_without_any_other_in_the_same_namespace + { + Establish context = () => { }; + + Because of = () => { }; + + It spec1 = () => { }; + + It spec2 = () => { }; + } +} + +namespace Machine.Specifications +{ + namespace ExampleA + { + namespace ExampleB + { + public class InExampleB_1 + { + It is_spec_1 = () => { }; + } + + public class InExampleB_2 + { + It is_spec_1 = () => { }; + } + } + + public class InExampleA_1 + { + It is_spec_1 = () => { }; + } + + public class InExampleA_2 + { + It is_spec_1 = () => { }; + } + } + + namespace ExampleC + { + public class InExampleC_1 + { + It is_spec_1 = () => { }; + + It is_spec_2 = () => { }; + } + + public class InExampleC_2 + { + } + } + + public class ContextWithSpecificationExpectingThrowThatDoesnt + { + public static bool it_invoked; + + static Exception exception; + + Because of = () => + exception = null; + + It should_throw_but_it_wont = () => + exception.ShouldNotBeNull(); + + public static void Reset() + { + it_invoked = false; + } + } + + public class ContextWithThrowingWhenAndPassingSpecification + { + public static bool it_invoked; + + Because of = () => + throw new Exception(); + + It should_fail = () => + it_invoked = true; + + public static void Reset() + { + it_invoked = false; + } + } + + public class ContextWithEmptyWhen + { + public static bool it_invoked; + + Because of; + + It should_do_stuff = () => + it_invoked = true; + + public static void Reset() + { + it_invoked = false; + } + } + + public class ContextWithTwoWhens + { + public static bool when_1_invoked; + + public static bool when_2_invoked; + + public static bool it_for_when_1_invoked; + + public static bool it_for_when_2_invoked; + + Because _1 = () => + when_1_invoked = true; + + It for_when_1 = () => + it_for_when_1_invoked = true; + + Because _2 = () => + when_2_invoked = true; + + It for_when_2 = () => + it_for_when_2_invoked = true; + + public static void Reset() + { + when_1_invoked = false; + when_2_invoked = false; + it_for_when_1_invoked = false; + it_for_when_2_invoked = false; + } + } + + public class ContextWithEmptySpecification + { + public static bool when_invoked; + + Because of = () => + when_invoked = true; + + It should_do_stuff; + + public static void Reset() + { + when_invoked = false; + } + } + + public class ContextWithThrowingSpecification + { + public static bool when_invoked; + public static bool it_invoked; + public static Exception exception; + + Because it_happens = () => + { + when_invoked = true; + exception = Catch.Exception(() => { throw new Exception(); }); + }; + + It should_throw_an_exception = () => + it_invoked = true; + + public static void Reset() + { + when_invoked = false; + it_invoked = false; + } + } + + public class ContextWithSingleSpecification + { + public static bool because_invoked; + + public static bool it_invoked; + + public static bool context_invoked; + + public static bool cleanup_invoked; + + Establish context = () => + context_invoked = true; + + Because of = () => + because_invoked = true; + + It is_a_specification = () => + it_invoked = true; + + Cleanup after = () => + cleanup_invoked = true; + + public static void Reset() + { + because_invoked = false; + it_invoked = false; + context_invoked = false; + cleanup_invoked = false; + } + } + + public class AsyncSpecifications + { + public static bool establish_invoked; + + public static bool because_invoked; + + public static bool async_it_invoked; + + public static bool sync_it_invoked; + + public static bool cleanup_invoked; + + Establish context = async () => + { + establish_invoked = true; + + await Task.Delay(10); + }; + + Because of = async () => + { + because_invoked = true; + + await Task.Delay(10); + }; + + It should_invoke_sync = () => + sync_it_invoked = true; + + It should_invoke_async = async () => + { + async_it_invoked = true; + + await Task.Delay(10); + }; + + Cleanup after = async () => + { + cleanup_invoked = true; + + await Task.Delay(10); + }; + } + + public class AsyncSpecificationsValueTask + { + public static int establish_value; + + public static int because_value; + + public static int async_it_value; + + public static int sync_it_value; + + public static int cleanup_value; + + public static ValueTask<int> Test() + { + return new ValueTask<int>(10); + } + + Establish context = async () => + establish_value = await Test(); + + Because of = async () => + because_value = await Test(); + + It should_invoke_sync = () => + sync_it_value = Test().Result; + + It should_invoke_async = async () => + async_it_value = await Test(); + + Cleanup after = async () => + cleanup_value = await Test(); + } +} + +namespace Example.Exceptions +{ + + public class AsyncSpecificationsWithExceptions + { + Because of = async () => + throw new InvalidOperationException("something went wrong"); + + It should_invoke_sync = () => + throw new InvalidOperationException("something went wrong"); + + It should_invoke_async = async () => + throw new InvalidOperationException("something went wrong"); + } +} diff --git a/src/Machine.Specifications.Runner.Utility.Specs/.editorconfig b/tests/Machine.Specifications.Runner.Utility.Specs/.editorconfig similarity index 100% rename from src/Machine.Specifications.Runner.Utility.Specs/.editorconfig rename to tests/Machine.Specifications.Runner.Utility.Specs/.editorconfig diff --git a/src/Machine.Specifications.Runner.Utility.Specs/AppDomainRunnerSpecs.cs b/tests/Machine.Specifications.Runner.Utility.Specs/AppDomainRunnerSpecs.cs similarity index 100% rename from src/Machine.Specifications.Runner.Utility.Specs/AppDomainRunnerSpecs.cs rename to tests/Machine.Specifications.Runner.Utility.Specs/AppDomainRunnerSpecs.cs diff --git a/src/Machine.Specifications.Runner.Utility.Specs/CompileContext.cs b/tests/Machine.Specifications.Runner.Utility.Specs/CompileContext.cs similarity index 100% rename from src/Machine.Specifications.Runner.Utility.Specs/CompileContext.cs rename to tests/Machine.Specifications.Runner.Utility.Specs/CompileContext.cs diff --git a/src/Machine.Specifications.Runner.Utility.Specs/CustomDelegateSpecs.cs b/tests/Machine.Specifications.Runner.Utility.Specs/CustomDelegateSpecs.cs similarity index 100% rename from src/Machine.Specifications.Runner.Utility.Specs/CustomDelegateSpecs.cs rename to tests/Machine.Specifications.Runner.Utility.Specs/CustomDelegateSpecs.cs diff --git a/src/Machine.Specifications.Should.Specs/Machine.Specifications.Should.Specs.csproj b/tests/Machine.Specifications.Runner.Utility.Specs/Machine.Specifications.Runner.Utility.Specs.csproj similarity index 70% rename from src/Machine.Specifications.Should.Specs/Machine.Specifications.Should.Specs.csproj rename to tests/Machine.Specifications.Runner.Utility.Specs/Machine.Specifications.Runner.Utility.Specs.csproj index bee92a93c..025df8c9f 100644 --- a/src/Machine.Specifications.Should.Specs/Machine.Specifications.Should.Specs.csproj +++ b/tests/Machine.Specifications.Runner.Utility.Specs/Machine.Specifications.Runner.Utility.Specs.csproj @@ -1,17 +1,13 @@ <Project Sdk="Microsoft.NET.Sdk"> - <PropertyGroup> - <TargetFramework>net10.0</TargetFramework> - <IsPackable>false</IsPackable> - </PropertyGroup> - <ItemGroup> + <PackageReference Include="Microsoft.CodeAnalysis.Compilers" Version="4.12.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\Machine.Specifications.Core\Machine.Specifications.Core.csproj" /> - <ProjectReference Include="..\Machine.Specifications.Runner.VisualStudio\Machine.Specifications.Runner.VisualStudio.csproj" /> + <ProjectReference Include="..\Machine.Specifications.Runner.Utility\Machine.Specifications.Runner.Utility.csproj" /> <ProjectReference Include="..\Machine.Specifications.Should\Machine.Specifications.Should.csproj" /> </ItemGroup> diff --git a/src/Machine.Specifications.Runner.Utility.Specs/RemoteRunListenerSpecs.cs b/tests/Machine.Specifications.Runner.Utility.Specs/RemoteRunListenerSpecs.cs similarity index 100% rename from src/Machine.Specifications.Runner.Utility.Specs/RemoteRunListenerSpecs.cs rename to tests/Machine.Specifications.Runner.Utility.Specs/RemoteRunListenerSpecs.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Fixtures/FixtureCode.cs b/tests/Machine.Specifications.Runner.VisualStudio.Fixtures/FixtureCode.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Fixtures/FixtureCode.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Fixtures/FixtureCode.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Fixtures/Machine.Specifications.Runner.VisualStudio.Fixtures.csproj b/tests/Machine.Specifications.Runner.VisualStudio.Fixtures/Machine.Specifications.Runner.VisualStudio.Fixtures.csproj similarity index 82% rename from src/Machine.Specifications.Runner.VisualStudio.Fixtures/Machine.Specifications.Runner.VisualStudio.Fixtures.csproj rename to tests/Machine.Specifications.Runner.VisualStudio.Fixtures/Machine.Specifications.Runner.VisualStudio.Fixtures.csproj index 98b564ca3..1079634a8 100644 --- a/src/Machine.Specifications.Runner.VisualStudio.Fixtures/Machine.Specifications.Runner.VisualStudio.Fixtures.csproj +++ b/tests/Machine.Specifications.Runner.VisualStudio.Fixtures/Machine.Specifications.Runner.VisualStudio.Fixtures.csproj @@ -1,10 +1,5 @@ <Project Sdk="Microsoft.NET.Sdk"> - <PropertyGroup> - <TargetFramework>netstandard2.0</TargetFramework> - <IsPackable>false</IsPackable> - </PropertyGroup> - <ItemGroup> <PackageReference Include="InternalsVisibleTo.MSBuild" Version="1.1.0"> <PrivateAssets>all</PrivateAssets> diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/.editorconfig b/tests/Machine.Specifications.Runner.VisualStudio.Specs/.editorconfig similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/.editorconfig rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/.editorconfig diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/BehaviorsSpecs.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/BehaviorsSpecs.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/BehaviorsSpecs.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/BehaviorsSpecs.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/CustomActAssertSpecs.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/CustomActAssertSpecs.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/CustomActAssertSpecs.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/CustomActAssertSpecs.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/DisabledTestNameOffSpecs.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/DisabledTestNameOffSpecs.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/DisabledTestNameOffSpecs.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/DisabledTestNameOffSpecs.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/DiscoverySpecs.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/DiscoverySpecs.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/DiscoverySpecs.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/DiscoverySpecs.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/NestedTypesDiscoverySpecs.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/NestedTypesDiscoverySpecs.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/NestedTypesDiscoverySpecs.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/NestedTypesDiscoverySpecs.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/WithDiscoverySetup.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/WithDiscoverySetup.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/WithDiscoverySetup.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/WithDiscoverySetup.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/DiscoveryUnhandledErrorSpecs.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/DiscoveryUnhandledErrorSpecs.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/DiscoveryUnhandledErrorSpecs.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/DiscoveryUnhandledErrorSpecs.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationEndsWithAFail.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationEndsWithAFail.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationEndsWithAFail.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationEndsWithAFail.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationEndsWithAPass.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationEndsWithAPass.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationEndsWithAPass.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationEndsWithAPass.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationStarts.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationStarts.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationStarts.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenSpecificationStarts.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenThereIsAnErrorReported.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenThereIsAnErrorReported.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenThereIsAnErrorReported.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/RunListener/WhenThereIsAnErrorReported.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenCleaningUpAContext.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenCleaningUpAContext.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenCleaningUpAContext.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenCleaningUpAContext.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningANestedSpecPasses.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningANestedSpecPasses.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningANestedSpecPasses.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningANestedSpecPasses.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASingleBehaviorPasses.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASingleBehaviorPasses.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASingleBehaviorPasses.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASingleBehaviorPasses.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatFails.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatFails.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatFails.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatFails.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatIsIgnored.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatIsIgnored.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatIsIgnored.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatIsIgnored.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatIsNotImplemented.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatIsNotImplemented.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatIsNotImplemented.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatIsNotImplemented.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatPasses.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatPasses.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatPasses.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatPasses.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatThrows.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatThrows.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatThrows.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecThatThrows.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecWithCustomActAssertDelegatesPasses.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecWithCustomActAssertDelegatesPasses.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecWithCustomActAssertDelegatesPasses.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningASpecWithCustomActAssertDelegatesPasses.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningAnAssemblyWithBehaviors.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningAnAssemblyWithBehaviors.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningAnAssemblyWithBehaviors.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WhenRunningAnAssemblyWithBehaviors.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithAssemblyExecutionSetup.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithAssemblyExecutionSetup.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithAssemblyExecutionSetup.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithAssemblyExecutionSetup.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithMultipleSpecExecutionSetup.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithMultipleSpecExecutionSetup.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithMultipleSpecExecutionSetup.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithMultipleSpecExecutionSetup.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithSingleSpecExecutionSetup.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithSingleSpecExecutionSetup.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithSingleSpecExecutionSetup.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Execution/WithSingleSpecExecutionSetup.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/ExecutionUnhandledErrorSpecs.cs b/tests/Machine.Specifications.Runner.VisualStudio.Specs/ExecutionUnhandledErrorSpecs.cs similarity index 100% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/ExecutionUnhandledErrorSpecs.cs rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/ExecutionUnhandledErrorSpecs.cs diff --git a/src/Machine.Specifications.Runner.VisualStudio.Specs/Machine.Specifications.Runner.VisualStudio.Specs.csproj b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Machine.Specifications.Runner.VisualStudio.Specs.csproj similarity index 83% rename from src/Machine.Specifications.Runner.VisualStudio.Specs/Machine.Specifications.Runner.VisualStudio.Specs.csproj rename to tests/Machine.Specifications.Runner.VisualStudio.Specs/Machine.Specifications.Runner.VisualStudio.Specs.csproj index 1e1cda414..8f839e8bf 100644 --- a/src/Machine.Specifications.Runner.VisualStudio.Specs/Machine.Specifications.Runner.VisualStudio.Specs.csproj +++ b/tests/Machine.Specifications.Runner.VisualStudio.Specs/Machine.Specifications.Runner.VisualStudio.Specs.csproj @@ -1,10 +1,5 @@ <Project Sdk="Microsoft.NET.Sdk"> - <PropertyGroup> - <TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks> - <IsPackable>false</IsPackable> - </PropertyGroup> - <ItemGroup> <PackageReference Include="Machine.Fakes.Moq" Version="2.11.0" /> <PackageReference Include="Machine.Specifications.Should" Version="1.0.0" /> diff --git a/src/Machine.Specifications.Should.Specs/.editorconfig b/tests/Machine.Specifications.Should.Specs/.editorconfig similarity index 100% rename from src/Machine.Specifications.Should.Specs/.editorconfig rename to tests/Machine.Specifications.Should.Specs/.editorconfig diff --git a/src/Machine.Specifications.Should.Specs/AssertionSpecs.cs b/tests/Machine.Specifications.Should.Specs/AssertionSpecs.cs similarity index 100% rename from src/Machine.Specifications.Should.Specs/AssertionSpecs.cs rename to tests/Machine.Specifications.Should.Specs/AssertionSpecs.cs diff --git a/tests/Machine.Specifications.Should.Specs/Machine.Specifications.Should.Specs.csproj b/tests/Machine.Specifications.Should.Specs/Machine.Specifications.Should.Specs.csproj new file mode 100644 index 000000000..da11eb34c --- /dev/null +++ b/tests/Machine.Specifications.Should.Specs/Machine.Specifications.Should.Specs.csproj @@ -0,0 +1,8 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <ItemGroup> + <ProjectReference Include="..\..\src\Machine.Specifications.Core\Machine.Specifications.Core.csproj" /> + <ProjectReference Include="..\..\src\Machine.Specifications.Should\Machine.Specifications.Should.csproj" /> + </ItemGroup> + +</Project> diff --git a/src/Machine.Specifications.Should.Specs/ShouldBeCloseToSpecs.cs b/tests/Machine.Specifications.Should.Specs/ShouldBeCloseToSpecs.cs similarity index 100% rename from src/Machine.Specifications.Should.Specs/ShouldBeCloseToSpecs.cs rename to tests/Machine.Specifications.Should.Specs/ShouldBeCloseToSpecs.cs diff --git a/src/Machine.Specifications.Should.Specs/ShouldBeLikeSpecs.cs b/tests/Machine.Specifications.Should.Specs/ShouldBeLikeSpecs.cs similarity index 100% rename from src/Machine.Specifications.Should.Specs/ShouldBeLikeSpecs.cs rename to tests/Machine.Specifications.Should.Specs/ShouldBeLikeSpecs.cs diff --git a/src/Machine.Specifications.Should.Specs/Utility/Internal/ErrorMessageSpecs.cs b/tests/Machine.Specifications.Should.Specs/Utility/Internal/ErrorMessageSpecs.cs similarity index 100% rename from src/Machine.Specifications.Should.Specs/Utility/Internal/ErrorMessageSpecs.cs rename to tests/Machine.Specifications.Should.Specs/Utility/Internal/ErrorMessageSpecs.cs diff --git a/src/Machine.Specifications.Should.Specs/Utility/ObjectGraphHelperSpecs.cs b/tests/Machine.Specifications.Should.Specs/Utility/ObjectGraphHelperSpecs.cs similarity index 100% rename from src/Machine.Specifications.Should.Specs/Utility/ObjectGraphHelperSpecs.cs rename to tests/Machine.Specifications.Should.Specs/Utility/ObjectGraphHelperSpecs.cs