-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Property Method Attribute Generators #16
Merged
dharmaturtle
merged 35 commits into
hedgehogqa:main
from
JohnEffo:nethod-parameter-generator
Jul 5, 2023
+1,193
−54
Merged
Changes from 7 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
81c1d40
First stab as attribute parameters
JohnEffo 865f9e1
Add demo range test
JohnEffo 4667514
Fix attributes on ParameterGeneraterBaseType
JohnEffo 71dfc6e
Add examples showcasing attributes in CSharp
JohnEffo 1284400
Make file names match the examples
JohnEffo 08eea0d
test
dharmaturtle 9d851f6
added a docstring, some tests, and some polish
dharmaturtle 3deb955
part way through docs
JohnEffo 235e321
Merge wip with upstream.
JohnEffo 609985d
Documenation completed
JohnEffo ce4c504
C# properties which are Task or Task<bool> now run.
JohnEffo c81034d
Cater for useful AsyncResult types.
JohnEffo c12e7e4
C# properties which are Task or Task<bool> now run.
JohnEffo 48b88d0
Cater for useful AsyncResult types.
JohnEffo 97cfb1e
Finish documentation
JohnEffo 496e428
Fix single = mistake in documentation property.
JohnEffo 9c9296a
Merge branch 'main' into nethod-parameter-generator
dharmaturtle c9b0eb8
polish
dharmaturtle 5aa8682
ParameterGenerator => GenAttribute
dharmaturtle 2d05195
Merge main int nethod-parameter-generator branch
JohnEffo ca4baad
Merge branch 'main' into nethod-parameter-generator
JohnEffo 20f15df
Merge branch 'main' into nethod-parameter-generator
dharmaturtle d222d68
polish 1
dharmaturtle c45ba46
rename
dharmaturtle c10a87f
lol
dharmaturtle 1567e36
oops
dharmaturtle 5697937
polish
dharmaturtle c93e7d2
?
dharmaturtle 25094f5
Task.CompletedTask => Task.Delay
dharmaturtle 3cb81fb
Revert "?"
dharmaturtle b04d42f
polish
dharmaturtle 9915cfd
more or less done with Readme
dharmaturtle aecd795
readmeCSharp more or less done
dharmaturtle 19a8b7b
polish
dharmaturtle 96907d9
changelog
dharmaturtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
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,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; | ||
} |
28 changes: 28 additions & 0 deletions
28
...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,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; | ||
} |
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> |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this name be more general? Might be useful for other C# examples. Or heck, could even turn it into a real test suite. I should probably add it to CICD anyway - doesn't really make sense to have broken examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have updated this, I realised this when I came to do the documentation and wanted to put add the documentation examples.