Skip to content

Commit d5a503d

Browse files
committed
Wrote some simple tests for the new Randomize method.
1 parent f3f7412 commit d5a503d

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
namespace TryAtSoftware.Randomizer.Core.Tests;
2+
3+
using System;
4+
using TryAtSoftware.Randomizer.Core.Primitives;
5+
using TryAtSoftware.Randomizer.Core.Tests.Models;
6+
using Xunit;
7+
8+
public class ComplexRandomizerTests
9+
{
10+
[Fact]
11+
public void RandomizeShouldThrowExceptionWhenInvalidParametersAreProvided()
12+
{
13+
var randomizer = new ComplexRandomizer<Person>();
14+
Assert.Throws<ArgumentNullException>(() => randomizer.Randomize(null!));
15+
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(null!, _ => new StringRandomizer()));
18+
Assert.Throws<ArgumentNullException>(() => randomizer.Randomize<string>(x => x.Name, getRandomizer: null!));
19+
}
20+
21+
[Fact]
22+
public void RandomizationRulesShouldBeAddedSuccessfully()
23+
{
24+
var randomizer = new ComplexRandomizer<Person>();
25+
randomizer.Randomize(x => x.Id, new GuidRandomizer());
26+
randomizer.Randomize(x => x.Name, _ => new StringRandomizer());
27+
randomizer.Randomize(new RandomizationRule<Person, int>(x => x.Age, new NumberRandomizer(min: 10, max: 50)));
28+
29+
var person = randomizer.PrepareRandomValue();
30+
Assert.NotEqual(Guid.Empty, person.Id);
31+
Assert.False(string.IsNullOrWhiteSpace(person.Name));
32+
Assert.NotEqual(0, person.Age);
33+
}
34+
35+
[Fact]
36+
public void RandomizationRulesShouldBeOverriddenSuccessfully()
37+
{
38+
var randomizer = new ComplexRandomizer<Person>();
39+
randomizer.Randomize(x => x.Age, new NumberRandomizer(min: 10, max: 20));
40+
randomizer.Randomize(x => x.Age, new NumberRandomizer(min: 100, max: 200));
41+
42+
var person = randomizer.PrepareRandomValue();
43+
Assert.True(100 <= person.Age && person.Age < 200);
44+
}
45+
}

0 commit comments

Comments
 (0)