Skip to content

Commit 004ca56

Browse files
authored
Merge pull request #46
Removed the surplus `IConfigurableComplexRandomizer` interface.
2 parents 70836af + a39b241 commit 004ca56

File tree

4 files changed

+28
-32
lines changed

4 files changed

+28
-32
lines changed

src/TryAtSoftware.Randomizer.Core/ComplexRandomizer.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
using System;
44
using System.Collections.Generic;
5-
using System.Linq.Expressions;
65
using TryAtSoftware.Randomizer.Core.Interfaces;
76

8-
public class ComplexRandomizer<TEntity> : IConfigurableComplexRandomizer<TEntity>
7+
public class ComplexRandomizer<TEntity> : IComplexRandomizer<TEntity>
98
{
109
private readonly List<string> _orderedMembers = new ();
1110
private readonly HashSet<string> _randomizedMembers = new ();
@@ -49,24 +48,6 @@ public void Randomize(IRandomizationRule<TEntity> rule)
4948
this.SetRuleInternally(rule);
5049
}
5150

52-
/// <inheritdoc />
53-
public void Randomize<TValue>(Expression<Func<TEntity, TValue>> propertySelector, IRandomizer<TValue> randomizer)
54-
{
55-
if (propertySelector is null) throw new ArgumentNullException(nameof(propertySelector));
56-
if (randomizer is null) throw new ArgumentNullException(nameof(randomizer));
57-
58-
this.SetRuleInternally(new RandomizationRule<TEntity,TValue>(propertySelector, randomizer));
59-
}
60-
61-
/// <inheritdoc />
62-
public void Randomize<TValue>(Expression<Func<TEntity, TValue>> propertySelector, Func<TEntity, IRandomizer<TValue>?> getRandomizer)
63-
{
64-
if (propertySelector is null) throw new ArgumentNullException(nameof(propertySelector));
65-
if (getRandomizer is null) throw new ArgumentNullException(nameof(getRandomizer));
66-
67-
this.SetRuleInternally(new RandomizationRule<TEntity,TValue>(propertySelector, getRandomizer));
68-
}
69-
7051
private void SetRuleInternally(IRandomizationRule<TEntity> rule)
7152
{
7253
if (string.IsNullOrWhiteSpace(rule.PropertyName)) return;
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
namespace TryAtSoftware.Randomizer.Core.Interfaces;
22

3-
using System;
4-
using System.Linq.Expressions;
5-
63
public interface IComplexRandomizer<out TEntity> : IRandomizer<TEntity>
74
{
85
IInstanceBuilder<TEntity> InstanceBuilder { get; }
9-
}
10-
11-
public interface IConfigurableComplexRandomizer<TEntity> : IComplexRandomizer<TEntity>
12-
{
6+
137
void Randomize(IRandomizationRule<TEntity> rule);
14-
void Randomize<TValue>(Expression<Func<TEntity, TValue>> propertySelector, IRandomizer<TValue> randomizer);
15-
void Randomize<TValue>(Expression<Func<TEntity, TValue>> propertySelector, Func<TEntity, IRandomizer<TValue>?> getRandomizer);
16-
}
8+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
namespace TryAtSoftware.Randomizer.Core;
22

3+
using System;
4+
using System.Linq.Expressions;
35
using TryAtSoftware.Randomizer.Core.Interfaces;
46
using TryAtSoftware.Randomizer.Core.Primitives;
57

68
public static class RandomizationExtensions
79
{
810
public static IRandomizer<TValue> AsConstantRandomizer<TValue>(this TValue value) => new ConstantValueRandomizer<TValue>(value);
11+
12+
public static void Randomize<TEntity, TValue>(this IComplexRandomizer<TEntity> complexRandomizer, Expression<Func<TEntity, TValue>> propertySelector, IRandomizer<TValue> randomizer)
13+
{
14+
if (complexRandomizer is null) throw new ArgumentNullException(nameof(complexRandomizer));
15+
if (propertySelector is null) throw new ArgumentNullException(nameof(propertySelector));
16+
if (randomizer is null) throw new ArgumentNullException(nameof(randomizer));
17+
18+
complexRandomizer.Randomize(new RandomizationRule<TEntity,TValue>(propertySelector, randomizer));
19+
}
20+
21+
public static void Randomize<TEntity, TValue>(this IComplexRandomizer<TEntity> complexRandomizer, Expression<Func<TEntity, TValue>> propertySelector, Func<TEntity, IRandomizer<TValue>?> getRandomizer)
22+
{
23+
if (complexRandomizer is null) throw new ArgumentNullException(nameof(complexRandomizer));
24+
if (propertySelector is null) throw new ArgumentNullException(nameof(propertySelector));
25+
if (getRandomizer is null) throw new ArgumentNullException(nameof(getRandomizer));
26+
27+
complexRandomizer.Randomize(new RandomizationRule<TEntity,TValue>(propertySelector, getRandomizer));
28+
}
929
}

tests/TryAtSoftware.Randomizer.Core.Tests/ComplexRandomizerTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace TryAtSoftware.Randomizer.Core.Tests;
22

33
using System;
4+
using TryAtSoftware.Randomizer.Core.Interfaces;
45
using TryAtSoftware.Randomizer.Core.Primitives;
56
using TryAtSoftware.Randomizer.Core.Tests.Models;
67
using Xunit;
@@ -13,9 +14,11 @@ public void RandomizeShouldThrowExceptionWhenInvalidParametersAreProvided()
1314
var randomizer = new ComplexRandomizer<Person>();
1415
Assert.Throws<ArgumentNullException>(() => randomizer.Randomize(null!));
1516
Assert.Throws<ArgumentNullException>(() => randomizer.Randomize(null!, new StringRandomizer()));
16-
Assert.Throws<ArgumentNullException>(() => randomizer.Randomize<string>(x => x.Name, randomizer: null!));
17+
Assert.Throws<ArgumentNullException>(() => randomizer.Randomize<Person, string>(x => x.Name, randomizer: null!));
18+
Assert.Throws<ArgumentNullException>(() => ((IComplexRandomizer<Person>)null!).Randomize(x => x.Name, new StringRandomizer()));
1719
Assert.Throws<ArgumentNullException>(() => randomizer.Randomize(null!, _ => new StringRandomizer()));
18-
Assert.Throws<ArgumentNullException>(() => randomizer.Randomize<string>(x => x.Name, getRandomizer: null!));
20+
Assert.Throws<ArgumentNullException>(() => randomizer.Randomize<Person, string>(x => x.Name, getRandomizer: null!));
21+
Assert.Throws<ArgumentNullException>(() => ((IComplexRandomizer<Person>)null!).Randomize(x => x.Name, _ => new StringRandomizer()));
1922
}
2023

2124
[Fact]

0 commit comments

Comments
 (0)