Skip to content

Commit de77adc

Browse files
authored
Merge pull request #9
Enhanced randomization rules
2 parents 486eed8 + b3e4cab commit de77adc

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

src/TryAtSoftware.Randomizer.Core/RandomizationRule.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,36 @@
99
public class RandomizationRule<TEntity, TValue> : IRandomizationRule<TEntity>
1010
where TEntity : class
1111
{
12-
public RandomizationRule([NotNull] Expression<Func<TEntity, TValue>> propertySelector, [NotNull] IRandomizer<TValue> randomizer)
12+
private readonly IRandomValueSetter<TEntity> _valueSetter;
13+
14+
private RandomizationRule(Expression<Func<TEntity, TValue>> propertySelector)
1315
{
16+
if (propertySelector is null)
17+
throw new ArgumentNullException(nameof(propertySelector));
18+
1419
var property = propertySelector.GetPropertyInfo();
1520
this.PropertyName = property.Name;
16-
this.Randomizer = randomizer;
1721
}
1822

19-
/// <inheritdoc />
20-
public string PropertyName { get; }
23+
public RandomizationRule([NotNull] Expression<Func<TEntity, TValue>> propertySelector, [NotNull] IRandomizer<TValue> randomizer)
24+
: this(propertySelector)
25+
{
26+
if (randomizer is null)
27+
throw new ArgumentNullException(nameof(randomizer));
28+
29+
this._valueSetter = new RandomValueSetter<TEntity, TValue>(this.PropertyName, randomizer, MembersBinderCache<TEntity>.Binder);
30+
}
31+
32+
public RandomizationRule([NotNull] Expression<Func<TEntity, TValue>> propertySelector, [NotNull] IRandomValueSetter<TEntity> valueSetter)
33+
: this(propertySelector)
34+
{
35+
this._valueSetter = valueSetter ?? throw new ArgumentNullException(nameof(valueSetter));
36+
}
2137

2238
/// <inheritdoc />
23-
public IRandomizer<TValue> Randomizer { get; }
39+
public string PropertyName { get; }
2440

2541
/// <inheritdoc />
26-
public IRandomValueSetter<TEntity> GetValueSetter()
27-
=> new RandomValueSetter<TEntity,TValue>(this.PropertyName, this.Randomizer, MembersBinderCache<TEntity>.Binder);
42+
public IRandomValueSetter<TEntity> GetValueSetter() => this._valueSetter;
2843
}
2944
}

src/TryAtSoftware.Randomizer.Core/TryAtSoftware.Randomizer.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<PackageId>TryAtSoftware.Randomizer</PackageId>
6-
<Version>1.0.1</Version>
6+
<Version>1.0.2</Version>
77
<Authors>Tony Troeff</Authors>
88
<RepositoryUrl>https://github.com/TryAtSoftware/Randomizer</RepositoryUrl>
99
<PackageLicenseExpression>MIT</PackageLicenseExpression>

0 commit comments

Comments
 (0)