Skip to content

Commit 73b6dac

Browse files
committed
Added a bulk create for Randomizer with which the randomizer can create a set of random items.
1 parent 318414c commit 73b6dac

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ObjectFiller.Test/RandomizerTest.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace ObjectFiller.Test
22
{
33
using System;
4+
using System.Collections.Generic;
45
using System.Linq;
56

67
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -45,7 +46,16 @@ public void TryingToCreateAnObjectWithAnInterfaceShallFailAndHaveAnInnerexceptio
4546
Assert.IsNotNull(ex.InnerException);
4647
throw;
4748
}
48-
49+
}
50+
51+
[TestMethod]
52+
public void RandomizerCreatesAListOfRandomItemsIfNeeded()
53+
{
54+
int amount = 5;
55+
56+
IEnumerable<int> result = Randomizer<int>.Create(amount);
57+
58+
Assert.AreEqual(amount, result.Count());
4959
}
5060

5161
}

ObjectFiller/Randomizer.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
namespace Tynamix.ObjectFiller
1111
{
1212
using System;
13+
using System.Collections.Generic;
1314
using System.Linq;
15+
using System.Runtime.CompilerServices;
1416

1517
/// <summary>
1618
/// This class is a easy way to get random values.
@@ -65,6 +67,22 @@ public static T Create()
6567
return (T)Setup.TypeToRandomFunc[typeof(T)]();
6668
}
6769

70+
/// <summary>
71+
/// Creates a set of random items of the given type. It will use a <see cref="IRandomizerPlugin{T}"/> for that.
72+
/// </summary>
73+
/// <param name="amount">Amount of items created.</param>
74+
/// <returns>Set of random items of the given type.</returns>
75+
public static IEnumerable<T> Create(int amount)
76+
{
77+
var resultSet = new List<T>();
78+
for (int i = 0; i < amount; i++)
79+
{
80+
resultSet.Add(Create());
81+
}
82+
83+
return resultSet;
84+
}
85+
6886
/// <summary>
6987
/// Creates a random value of the target type. It will use a <see cref="IRandomizerPlugin{T}"/> for that
7088
/// </summary>

0 commit comments

Comments
 (0)