Skip to content

Commit 9516799

Browse files
gokTyBalDgokTyBalD
authored andcommitted
Added feature IgnoreAllOfType
1 parent 7feedf9 commit 9516799

File tree

6 files changed

+88
-8
lines changed

6 files changed

+88
-8
lines changed

ObjectFiller.Test/PersonFillingTest.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void TestFillPerson()
2121

2222
Assert.IsNotNull(filledPerson.Address);
2323
Assert.IsNotNull(filledPerson.Addresses);
24-
Assert.IsNotNull(filledPerson.BlaToBla);
24+
Assert.IsNotNull(filledPerson.StringToIAddress);
2525
Assert.IsNotNull(filledPerson.SureNames);
2626

2727
}
@@ -106,6 +106,7 @@ public void TestSetupForTypeOverrideSettings()
106106
Assert.AreEqual(1, p.Age);
107107
Assert.AreNotEqual(1, p.Address.HouseNumber);
108108
}
109+
109110
[TestMethod]
110111
public void TestSetupForTypeWithoutOverrideSettings()
111112
{
@@ -119,5 +120,53 @@ public void TestSetupForTypeWithoutOverrideSettings()
119120
Assert.AreEqual(1, p.Age);
120121
Assert.AreEqual(1, p.Address.HouseNumber);
121122
}
123+
124+
[TestMethod]
125+
public void TestIgnoreAllOfType()
126+
{
127+
ObjectFiller<Person> pFiller = new ObjectFiller<Person>();
128+
pFiller.Setup()
129+
.RegisterInterface<IAddress, Address>()
130+
.IgnoreAllOfType<string>()
131+
;
132+
133+
Person p = pFiller.Fill();
134+
135+
Assert.IsNotNull(p);
136+
Assert.IsNull(p.FirstName);
137+
Assert.IsNotNull(p.Address);
138+
Assert.IsNull(p.Address.City);
139+
}
140+
141+
[TestMethod]
142+
public void TestIgnoreAllOfComplexType()
143+
{
144+
ObjectFiller<Person> pFiller = new ObjectFiller<Person>();
145+
pFiller.Setup()
146+
.RegisterInterface<IAddress, Address>()
147+
.IgnoreAllOfType<Address>()
148+
.IgnoreAllOfType<IAddress>()
149+
;
150+
Person p = pFiller.Fill();
151+
152+
Assert.IsNotNull(p);
153+
Assert.IsNull(p.Address);
154+
}
155+
156+
[TestMethod]
157+
public void TestIgnoreAllOfTypeDictionary()
158+
{
159+
ObjectFiller<Person> pFiller = new ObjectFiller<Person>();
160+
pFiller.Setup()
161+
.RegisterInterface<IAddress, Address>()
162+
.IgnoreAllOfType<Address>()
163+
.IgnoreAllOfType<IAddress>()
164+
.IgnoreAllOfType<Dictionary<string, IAddress>>();
165+
Person p = pFiller.Fill();
166+
167+
Assert.IsNotNull(p);
168+
Assert.IsNull(p.Address);
169+
Assert.IsNull(p.StringToIAddress);
170+
}
122171
}
123172
}

ObjectFiller.Test/TestPoco/Person/Person.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public class Person
1919

2020
public string Title { get; set; }
2121

22-
public Dictionary<string, IAddress> BlaToBla { get; set; }
22+
public Dictionary<string, IAddress> StringToIAddress { get; set; }
2323

2424
public IList<IAddress> Addresses { get; set; }
2525

2626
public ICollection<IAddress> AddressCollection { get; set; }
2727

28-
public Dictionary<string, List<Address>> SenselessDictionary { get; set; }
28+
public Dictionary<string, List<Address>> StringToListOfAddress { get; set; }
2929
}
3030
}

ObjectFiller/IFluentFillerApi.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public interface IFluentFillerApi<TTargetObject>
4949
/// <param name="property">The target property which will be filled by the customm <see cref="randomizerPlugin"/>.</param>
5050
/// <param name="additionalProperties">Some more properties which should be also filled by the custom <see cref="randomizerPlugin"/></param>
5151
/// <example>
52-
/// objectFiller.Setup()..RandomizerForProperty<Person, string>(new MnemonicStringPlugin(1), person => person.FirstName, person => person.LastName)
52+
/// objectFiller.Setup().RandomizerForProperty<Person, string>(new MnemonicStringPlugin(1), person => person.FirstName, person => person.LastName)
5353
/// </example>
5454
IFluentFillerApi<TTargetObject> RandomizerForProperty<TTargetType>(IRandomizerPlugin<TTargetType> randomizerPlugin, Expression<Func<TTargetObject, TTargetType>> property, params Expression<Func<TTargetObject, TTargetType>>[] additionalProperties);
5555

@@ -60,11 +60,17 @@ public interface IFluentFillerApi<TTargetObject>
6060
/// <typeparam name="TTargetObject">The type of object where the target properties to ignore are located</typeparam>
6161
/// <param name="propertyToIgnore">Targetproperty to ignore</param>
6262
/// <param name="additionalProperties">OPTIONAL: Additional Properties which will be also ignored</param>
63-
IFluentFillerApi<TTargetObject> IgnoreProperties(
64-
Expression<Func<TTargetObject, object>> propertyToIgnore,
65-
params Expression<Func<TTargetObject, object>>[] additionalProperties);
66-
// where TTargetObject : class;
63+
IFluentFillerApi<TTargetObject> IgnoreProperties(Expression<Func<TTargetObject, object>> propertyToIgnore, params Expression<Func<TTargetObject, object>>[] additionalProperties);
6764

65+
/// <summary>
66+
/// Ignore all properties of type <see cref="TTargetType"/> when generating Testdata.
67+
/// </summary>
68+
/// <typeparam name="TTargetType">Type which will be ignored</typeparam>
69+
/// <example>
70+
/// objectFiller.IgnoreAllOfType<string>();
71+
/// </example>
72+
IFluentFillerApi<TTargetObject> IgnoreAllOfType<TTargetType>();
73+
6874
/// <summary>
6975
/// Setup the maximum item count for lists. The ObjectFiller will not generate more listitems then this.
7076
/// The default value is 25.

ObjectFiller/ObjectFiller.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ private void FillInternal(object objectToFill)
111111

112112
foreach (PropertyInfo property in properties)
113113
{
114+
if (currentSetup.TypesToIgnore.Contains(property.PropertyType))
115+
{
116+
continue;
117+
}
118+
114119
if (IgnoreProperty(property, currentSetup))
115120
{
116121
continue;

ObjectFiller/ObjectFillerApi.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ public IFluentFillerApi<TTargetObject> IgnoreProperties(Expression<Func<TTargetO
126126
return this;
127127
}
128128

129+
/// <summary>
130+
/// Ignore all properties of type <see cref="TTargetType"/> when generating Testdata
131+
/// </summary>
132+
/// <typeparam name="TTargetType">Type which will be ignored</typeparam>
133+
/// <example>
134+
/// objectFiller.IgnoreAllOfType<string>();
135+
/// </example>
136+
public IFluentFillerApi<TTargetObject> IgnoreAllOfType<TTargetType>()
137+
{
138+
SetupManager.GetFor<TTargetObject>().TypesToIgnore.Add(typeof (TTargetType));
139+
140+
return this;
141+
}
142+
129143

130144
/// <summary>
131145
/// Setup the maximum item count for lists. The ObjectFiller will not generate more listitems then this.

ObjectFiller/ObjectFillerSetup.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public ObjectFillerSetup()
1919
TypeToRandomFunc = new Dictionary<Type, Func<object>>();
2020
PropertyToRandomFunc = new Dictionary<PropertyInfo, Func<object>>();
2121
ProperiesToIgnore = new List<PropertyInfo>();
22+
TypesToIgnore = new List<Type>();
2223

2324
InterfaceToImplementation = new Dictionary<Type, Type>();
2425

@@ -71,6 +72,11 @@ private void SetDefaultRandomizer()
7172
/// </summary>
7273
public List<PropertyInfo> ProperiesToIgnore { get; private set; }
7374

75+
/// <summary>
76+
/// All types which will be ignored completly
77+
/// </summary>
78+
public List<Type> TypesToIgnore { get; private set; }
79+
7480
/// <summary>
7581
/// Minimum count of list items which will be generated
7682
/// </summary>

0 commit comments

Comments
 (0)