Skip to content

Commit c7d9341

Browse files
committed
Merge pull request #39 from Tynamix/BUGFIX_RandomList_NullableBool
Bugfix random list nullable bool
2 parents 0fe0c35 + 116afdb commit c7d9341

File tree

5 files changed

+95
-66
lines changed

5 files changed

+95
-66
lines changed

ObjectFiller.Test/AddressFillingTest.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace ObjectFiller.Test
66
{
7+
using System.Linq;
8+
79
[TestClass]
810
public class AddressFillingTest
911
{
@@ -97,6 +99,27 @@ public void SetupTheAdressWithStaticValues()
9799
Assert.AreEqual(10, address.HouseNumber);
98100
}
99101

102+
[TestMethod]
103+
public void RandomListPluginShallReturnDifferentValues()
104+
{
105+
Filler<Address> addressFiller = new Filler<Address>();
106+
107+
addressFiller.Setup().OnProperty(x => x.City).Use(new RandomListItem<string>("Test1", "Test2"));
108+
109+
var addresses = addressFiller.Create(1000);
110+
111+
Assert.IsTrue(addresses.Any(x => x.City == "Test2"));
112+
113+
addressFiller = new Filler<Address>();
114+
115+
addressFiller.Setup().OnProperty(x => x.City).Use(new RandomListItem<string>("Test1"));
116+
117+
addresses = addressFiller.Create(1000);
118+
119+
Assert.IsTrue(addresses.All(x => x.City == "Test1"));
120+
121+
}
122+
100123

101124
}
102125
}

ObjectFiller.Test/DefaultDatatypeMappingsTest.cs

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,57 @@
66

77
namespace ObjectFiller.Test
88
{
9-
[TestClass]
10-
public class DefaultDatatypeMappingsTest
11-
{
12-
[TestMethod]
13-
public void Ensure_that_each_primitive_datatype_is_mapped_by_default()
14-
{
15-
var filler = new Filler<MyClass>();
16-
var myClasses = filler.Create(100).ToArray();
17-
foreach (var myClass in myClasses)
18-
{
19-
Assert.AreNotEqual(default(Guid), myClass._Guid);
20-
Assert.AreNotEqual(default(decimal), myClass._Decimal);
21-
}
22-
}
9+
[TestClass]
10+
public class DefaultDatatypeMappingsTest
11+
{
12+
[TestMethod]
13+
public void Ensure_that_each_primitive_datatype_is_mapped_by_default()
14+
{
15+
var filler = new Filler<MyClass>();
16+
var myClasses = filler.Create(100).ToArray();
17+
foreach (var myClass in myClasses)
18+
{
19+
Assert.AreNotEqual(default(Guid), myClass._Guid);
20+
Assert.AreNotEqual(default(decimal), myClass._Decimal);
21+
}
22+
}
2323

24-
public class MyClass
25-
{
26-
public byte _byte { get; set; }
27-
public char _char { get; set; }
28-
public Int16 _i16 { get; set; }
29-
public Int32 _i32 { get; set; }
30-
public Int64 _i64 { get; set; }
31-
public UInt16 _u16 { get; set; }
32-
public UInt32 _u32 { get; set; }
33-
public UInt64 _u64 { get; set; }
34-
public float _float { get; set; }
35-
public double _double { get; set; }
36-
public decimal _Decimal { get; set; }
37-
public IntPtr _IntPtr { get; set; }
38-
public DateTime _DateTime { get; set; }
39-
public TimeSpan _TimeSpan { get; set; }
40-
public Guid _Guid { get; set; }
41-
public string _String { get; set; }
24+
public class MyClass
25+
{
26+
public bool _bool { get; set; }
27+
public byte _byte { get; set; }
28+
public char _char { get; set; }
29+
public Int16 _i16 { get; set; }
30+
public Int32 _i32 { get; set; }
31+
public Int64 _i64 { get; set; }
32+
public UInt16 _u16 { get; set; }
33+
public UInt32 _u32 { get; set; }
34+
public UInt64 _u64 { get; set; }
35+
public float _float { get; set; }
36+
public double _double { get; set; }
37+
public decimal _Decimal { get; set; }
38+
public IntPtr _IntPtr { get; set; }
39+
public DateTime _DateTime { get; set; }
40+
public TimeSpan _TimeSpan { get; set; }
41+
public Guid _Guid { get; set; }
42+
public string _String { get; set; }
4243

43-
public byte? _n_byte { get; set; }
44-
public char? _n_char { get; set; }
45-
public Int16? _n_i16 { get; set; }
46-
public Int32? _n_i32 { get; set; }
47-
public Int64? _n_i64 { get; set; }
48-
public UInt16? _n_u16 { get; set; }
49-
public UInt32? _n_u32 { get; set; }
50-
public UInt64? _n_u64 { get; set; }
51-
public float? _n_float { get; set; }
52-
public double? _n_double { get; set; }
53-
public decimal? _n_Decimal { get; set; }
54-
public IntPtr? _n_IntPtr { get; set; }
55-
public DateTime? _n_DateTime { get; set; }
56-
public TimeSpan? _n_TimeSpan { get; set; }
57-
public Guid? _n_Guid { get; set; }
58-
}
59-
}
44+
public bool? _n_bool { get; set; }
45+
public byte? _n_byte { get; set; }
46+
public char? _n_char { get; set; }
47+
public Int16? _n_i16 { get; set; }
48+
public Int32? _n_i32 { get; set; }
49+
public Int64? _n_i64 { get; set; }
50+
public UInt16? _n_u16 { get; set; }
51+
public UInt32? _n_u32 { get; set; }
52+
public UInt64? _n_u64 { get; set; }
53+
public float? _n_float { get; set; }
54+
public double? _n_double { get; set; }
55+
public decimal? _n_Decimal { get; set; }
56+
public IntPtr? _n_IntPtr { get; set; }
57+
public DateTime? _n_DateTime { get; set; }
58+
public TimeSpan? _n_TimeSpan { get; set; }
59+
public Guid? _n_Guid { get; set; }
60+
}
61+
}
6062
}

ObjectFiller.Test/ObjectFillerTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public void TestFillPerson()
3030
Assert.IsTrue(new List<string>() { "Maik", "Tom", "Anton" }.Contains(pFilled.LastName));
3131
}
3232

33+
34+
35+
3336
[TestMethod]
3437
public void CreateMultipleInstances()
3538
{

ObjectFiller/Plugins/RandomListItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public RandomListItem(IEnumerable<T> allAvailableValues)
2929

3030
public T GetValue()
3131
{
32-
int rndmListIndex = Random.Next(0, _allAvailableValues.Length - 1);
32+
int rndmListIndex = Random.Next(0, _allAvailableValues.Length);
3333
return _allAvailableValues[rndmListIndex];
3434
}
3535
}

ObjectFiller/Setup/FillerSetupItem.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ private void SetDefaultRandomizer()
3030
var dateTimeRandomizer = new DateTimeRange(new System.DateTime(1970, 1, 1));
3131
TypeToRandomFunc[typeof(string)] = mnemonic.GetValue;
3232
TypeToRandomFunc[typeof(bool)] = () => Random.Next(0, 2) == 1;
33+
TypeToRandomFunc[typeof(bool?)] = () => new RandomListItem<bool?>(true, false, null).GetValue();
3334
TypeToRandomFunc[typeof(short)] = () => (short)Random.Next(-32767, 32767);
3435
TypeToRandomFunc[typeof(short?)] = () => (short)Random.Next(-32767, 32767);
3536
TypeToRandomFunc[typeof(int)] = () => Random.Next();
@@ -40,26 +41,26 @@ private void SetDefaultRandomizer()
4041
TypeToRandomFunc[typeof(float?)] = () => (float?)doublePlugin.GetValue();
4142
TypeToRandomFunc[typeof(double)] = () => doublePlugin.GetValue();
4243
TypeToRandomFunc[typeof(double?)] = () => doublePlugin.GetValue();
43-
TypeToRandomFunc[typeof(decimal)] = () => (decimal)Random.Next();
44-
TypeToRandomFunc[typeof(decimal?)] = () => (decimal)Random.Next();
44+
TypeToRandomFunc[typeof(decimal)] = () => (decimal)Random.Next();
45+
TypeToRandomFunc[typeof(decimal?)] = () => (decimal)Random.Next();
4546
TypeToRandomFunc[typeof(Guid)] = () => Guid.NewGuid();
4647
TypeToRandomFunc[typeof(Guid?)] = () => Guid.NewGuid();
4748
TypeToRandomFunc[typeof(System.DateTime)] = () => dateTimeRandomizer.GetValue();
4849
TypeToRandomFunc[typeof(System.DateTime?)] = () => dateTimeRandomizer.GetValue();
49-
TypeToRandomFunc[typeof(byte)] = () => (byte)Random.Next();
50-
TypeToRandomFunc[typeof(byte?)] = () => (byte?)Random.Next();
51-
TypeToRandomFunc[typeof(char)] = () => (char)Random.Next();
52-
TypeToRandomFunc[typeof(char?)] = () => (char)Random.Next();
53-
TypeToRandomFunc[typeof(ushort)] = () => (ushort)Random.Next();
54-
TypeToRandomFunc[typeof(ushort?)] = () => (ushort)Random.Next();
55-
TypeToRandomFunc[typeof(uint)] = () => (uint)Random.Next();
56-
TypeToRandomFunc[typeof(uint?)] = () => (uint)Random.Next();
57-
TypeToRandomFunc[typeof(ulong)] = () => (ulong)Random.Next();
58-
TypeToRandomFunc[typeof(ulong?)] = () => (ulong)Random.Next();
59-
TypeToRandomFunc[typeof(IntPtr)] = () => default(IntPtr);
60-
TypeToRandomFunc[typeof(IntPtr?)] = () => default(IntPtr);
61-
TypeToRandomFunc[typeof(TimeSpan)] = () => new TimeSpan(Random.Next());
62-
TypeToRandomFunc[typeof(TimeSpan?)] = () => new TimeSpan(Random.Next());
50+
TypeToRandomFunc[typeof(byte)] = () => (byte)Random.Next();
51+
TypeToRandomFunc[typeof(byte?)] = () => (byte?)Random.Next();
52+
TypeToRandomFunc[typeof(char)] = () => (char)Random.Next();
53+
TypeToRandomFunc[typeof(char?)] = () => (char)Random.Next();
54+
TypeToRandomFunc[typeof(ushort)] = () => (ushort)Random.Next();
55+
TypeToRandomFunc[typeof(ushort?)] = () => (ushort)Random.Next();
56+
TypeToRandomFunc[typeof(uint)] = () => (uint)Random.Next();
57+
TypeToRandomFunc[typeof(uint?)] = () => (uint)Random.Next();
58+
TypeToRandomFunc[typeof(ulong)] = () => (ulong)Random.Next();
59+
TypeToRandomFunc[typeof(ulong?)] = () => (ulong)Random.Next();
60+
TypeToRandomFunc[typeof(IntPtr)] = () => default(IntPtr);
61+
TypeToRandomFunc[typeof(IntPtr?)] = () => default(IntPtr);
62+
TypeToRandomFunc[typeof(TimeSpan)] = () => new TimeSpan(Random.Next());
63+
TypeToRandomFunc[typeof(TimeSpan?)] = () => new TimeSpan(Random.Next());
6364
}
6465

6566
/// <summary>

0 commit comments

Comments
 (0)