Skip to content

Commit a9fac48

Browse files
committed
C# ToPropertyWith
1 parent 5a6f144 commit a9fac48

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/Hedgehog.Stateful/Hedgehog.Stateful.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6-
<Version>0.7.0-beta2</Version>
6+
<Version>0.7.0-beta3</Version>
77
<Description>Stateful testing for Hedgehog</Description>
88
<Authors>Alexey Raga</Authors>
99
<Copyright>Copyright © 2025</Copyright>
@@ -38,6 +38,7 @@
3838
<Compile Include="SequentialSpecification.fs" />
3939
<Compile Include="ParallelSpecification.fs" />
4040
<Compile Include="Linq\VarExtensions.fs" />
41+
<Compile Include="Linq\SpecificationExtensions.fs" />
4142
<Compile Include="Linq\NoValue.fs" />
4243
</ItemGroup>
4344

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace Hedgehog.Stateful.Linq
2+
3+
open System
4+
open System.Runtime.CompilerServices
5+
open Hedgehog
6+
open Hedgehog.Stateful
7+
8+
9+
/// <summary>
10+
/// Extension methods for working with specifications in C#.
11+
/// </summary>
12+
[<AbstractClass; Sealed>]
13+
type SpecificationExtensions private () =
14+
15+
/// <summary>
16+
/// Convert a sequential specification to a property using a SUT factory.
17+
/// The factory is called once per property test run to create a fresh SUT.
18+
/// This is the recommended approach to ensure test isolation.
19+
/// </summary>
20+
/// <param name="spec">The sequential specification.</param>
21+
/// <param name="createSut">A Func delegate that creates a new SUT instance for each test run.</param>
22+
/// <returns>A property representing the sequential specification test.</returns>
23+
[<Extension>]
24+
static member ToPropertyWith(spec: SequentialSpecification<'TSystem, 'TState>, createSut: Func<'TSystem>) : Property<unit> =
25+
spec.ToPropertyWith(fun () -> createSut.Invoke())
26+
27+
/// <summary>
28+
/// Convert a parallel specification to a property using a SUT factory.
29+
/// The factory is called once per property test run to create a fresh SUT.
30+
/// This is the recommended approach to ensure test isolation.
31+
/// </summary>
32+
/// <param name="spec">The parallel specification.</param>
33+
/// <param name="createSut">A Func delegate that creates a new SUT instance for each test run.</param>
34+
/// <returns>A property representing the parallel specification test.</returns>
35+
[<Extension>]
36+
static member ToPropertyWith(spec: ParallelSpecification<'TSystem, 'TState>, createSut: Func<'TSystem>) : Property<unit> =
37+
spec.ToPropertyWith(fun () -> createSut.Invoke())

0 commit comments

Comments
 (0)