-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples showcasing attributes in CSharp
- Loading branch information
Showing
6 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...harp-attribute-based-parameters-comparision/PositiveAndNegativeGeneratorContainerTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Hedgehog; | ||
using Hedgehog.Linq; | ||
using Hedgehog.Xunit; | ||
using Gen = Hedgehog.Linq.Gen; | ||
using Range = Hedgehog.Linq.Range; | ||
|
||
|
||
namespace csharp_attribute_based_parameters_comparision; | ||
|
||
public record PositiveInt(int Value); | ||
public record NegativeInt( int Value ); | ||
|
||
public class Generators | ||
{ | ||
public static Gen<PositiveInt> GenPositiveInt => | ||
from x in Gen.Int32(Range.Constant(1, Int32.MaxValue)) | ||
select new PositiveInt(x); | ||
|
||
public static Gen<NegativeInt> GenNegativeInt => | ||
from x in Gen.Int32(Range.Constant(Int32.MinValue, -1)) | ||
select new NegativeInt(x); | ||
|
||
public static AutoGenConfig _ => GenX.defaults | ||
.WithGenerator(GenPositiveInt) | ||
.WithGenerator(GenNegativeInt); | ||
} | ||
|
||
public class PositiveAndNegativeGeneratorContainerTypes | ||
{ | ||
[Property(typeof(Generators))] | ||
public bool ResultOfAddingPositiveAndNegativeLessThanPositive( | ||
PositiveInt positive, | ||
NegativeInt negative) | ||
=> positive.Value + negative.Value < positive.Value; | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
examples/csharp-attribute-based-parameters-comparision/PositiveAndNegativeSimpleAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Hedgehog; | ||
using Hedgehog.Xunit; | ||
using Gen = Hedgehog.Linq.Gen; | ||
using Range = Hedgehog.Linq.Range; | ||
|
||
namespace csharp_attribute_based_parameters_comparision; | ||
|
||
public class Int32Range : ParameterGeneraterBaseType<int> | ||
{ | ||
private readonly int _min; | ||
private readonly int _max; | ||
|
||
public Int32Range(int min, int max) | ||
{ | ||
_min = min; | ||
_max = max; | ||
} | ||
public override Gen<int> Generator => Gen.Int32(Range.Constant(_min, _max)); | ||
} | ||
|
||
public class PositiveAndNegativeWithAttributes | ||
{ | ||
[Property] | ||
public bool ResultOfAddingPositiveAndNegativeLessThanPositive( | ||
[Int32Range(1, Int32.MaxValue)] int positive, | ||
[Int32Range(Int32.MinValue, -1 )] int negative) | ||
=> positive + negative < positive; | ||
} |
24 changes: 24 additions & 0 deletions
24
...tribute-based-parameters-comparision/PositiveAndNegativeUtilizingIntegerRangeAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Hedgehog; | ||
using Hedgehog.Xunit; | ||
using Gen = Hedgehog.Linq.Gen; | ||
using Range = Hedgehog.Linq.Range; | ||
|
||
namespace csharp_attribute_based_parameters_comparision; | ||
|
||
public class Negative : ParameterGeneraterBaseType<int> | ||
{ | ||
public override Gen<int> Generator => Gen.Int32(Range.Constant(Int32.MinValue, -1)); | ||
} | ||
public class Positive : ParameterGeneraterBaseType<int> | ||
{ | ||
public override Gen<int> Generator => Gen.Int32(Range.Constant(1, Int32.MaxValue)); | ||
} | ||
|
||
public class PositiveAndNegativeUtilizingIntegerRangeAttribute | ||
{ | ||
[Property] | ||
public bool ResultOfAddingPositiveAndNegativeLessThanPositive( | ||
[Positive] int positive, | ||
[Negative] int negative) | ||
=> positive + negative < positive; | ||
} |
1 change: 1 addition & 0 deletions
1
examples/csharp-attribute-based-parameters-comparision/Usings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
29 changes: 29 additions & 0 deletions
29
...tribute-based-parameters-comparision/csharp-attribute-based-parameters-comparision.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<RootNamespace>csharp_attribute_based_parameters_comparision</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Hedgehog.Xunit\Hedgehog.Xunit.fsproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |