Skip to content

Commit 5caddf1

Browse files
unknownunknown
authored andcommitted
Cleanup code style for several plugins
1 parent 1b804f5 commit 5caddf1

22 files changed

+1679
-3863
lines changed

ObjectFiller.Test/EmailAddressesPluginTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void GivenDomainRootIsAttachedToGeneratedEmailAddress()
113113
[TestMethod]
114114
public void EmailAddressesWorksInCombinationWithRealNamesPlugin()
115115
{
116-
var realNames = new RealNames(RealNameStyle.FirstNameLastName);
116+
var realNames = new RealNames(NameStyle.FirstNameLastName);
117117

118118
var sut = new EmailAddresses(realNames);
119119
var result = sut.GetValue();

ObjectFiller.Test/GermanStreetNamesPluginTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace ObjectFiller.Test
55
{
6+
using Tynamix.ObjectFiller;
7+
68
[TestClass]
79
public class GermanStreetNamesPluginTest
810
{

ObjectFiller.Test/PatternGeneratorTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Must_be_able_to_handle_private_setters()
1414
{
1515
var filler = new Filler<ClassWithPrivateStuffSealed>();
1616
filler.Setup()
17-
.OnProperty(x => x.RealNameStyle).DoIt(At.TheEnd).Use(() => RealNameStyle.FirstNameLastName)
17+
.OnProperty(x => x.NameStyle).DoIt(At.TheEnd).Use(() => NameStyle.FirstNameLastName)
1818
.OnProperty(x=>x.WithPrivateSetter);
1919

2020

@@ -23,7 +23,7 @@ public void Must_be_able_to_handle_private_setters()
2323
Assert.AreNotEqual(0, obj.WithPrivateSetter, "Must be able to set even a private setter");
2424
Assert.AreEqual(123, obj.WithoutSetter, "Cannot set that... must get default value");
2525

26-
Assert.AreEqual(obj.RealNameStyle, RealNameStyle.FirstNameLastName);
26+
Assert.AreEqual(obj.NameStyle, NameStyle.FirstNameLastName);
2727
}
2828

2929
[TestMethod]
@@ -244,7 +244,7 @@ public class ClassWithPrivateStuffAbstract
244244
public int WithPrivateSetter { get; private set; }
245245
public int WithoutSetter { get { return 123; } }
246246

247-
public RealNameStyle RealNameStyle { get; private set; }
247+
public NameStyle NameStyle { get; private set; }
248248
}
249249

250250
public class ClassWithPrivateStuff : ClassWithPrivateStuffAbstract

ObjectFiller.Test/PersonFillingTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public void TestNameListStringRandomizer()
5353
Filler<Person> pFiller = new Filler<Person>();
5454

5555
pFiller.Setup().OnType<IAddress>().CreateInstanceOf<Address>()
56-
.OnProperty(p => p.FirstName).Use(new RealNames(RealNameStyle.FirstNameOnly))
57-
.OnProperty(p => p.LastName).Use(new RealNames(RealNameStyle.LastNameOnly));
56+
.OnProperty(p => p.FirstName).Use(new RealNames(NameStyle.FirstName))
57+
.OnProperty(p => p.LastName).Use(new RealNames(NameStyle.LastName));
5858

5959
Person filledPerson = pFiller.Create();
6060

@@ -71,7 +71,7 @@ public void TestFirstNameAsConstantLastNameAsRealName()
7171
pFiller.Setup()
7272
.OnType<IAddress>().CreateInstanceOf<Address>()
7373
.OnProperty(p => p.FirstName).Use(() => "John")
74-
.OnProperty(p => p.LastName).Use(new RealNames(RealNameStyle.LastNameOnly));
74+
.OnProperty(p => p.LastName).Use(new RealNames(NameStyle.LastName));
7575

7676
Person filledPerson = pFiller.Create();
7777

@@ -106,7 +106,7 @@ public void BigComplicated()
106106
Filler<Person> pFiller = new Filler<Person>();
107107
pFiller.Setup()
108108
.OnType<IAddress>().CreateInstanceOf<Address>()
109-
.OnProperty(p => p.LastName, p => p.FirstName).DoIt(At.TheEnd).Use(new RealNames(RealNameStyle.FirstNameOnly))
109+
.OnProperty(p => p.LastName, p => p.FirstName).DoIt(At.TheEnd).Use(new RealNames(NameStyle.FirstName))
110110
.OnProperty(p => p.Age).Use(() => Random.Next(10, 32))
111111
.SetupFor<Address>()
112112
.OnProperty(a => a.City).Use(new MnemonicString(1))

ObjectFiller.Test/RealNamePluginTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public void TestRealNameFirstNameOnly()
1111
{
1212
Filler<LibraryFillingTest.Person> filler = new Filler<LibraryFillingTest.Person>();
1313
filler.Setup()
14-
.OnProperty(x => x.Name).Use(new RealNames(RealNameStyle.FirstNameOnly));
14+
.OnProperty(x => x.Name).Use(new RealNames(NameStyle.FirstName));
1515

1616
LibraryFillingTest.Person p = filler.Create();
1717

@@ -25,7 +25,7 @@ public void TestRealNameLastNameOnly()
2525
{
2626
Filler<LibraryFillingTest.Person> filler = new Filler<LibraryFillingTest.Person>();
2727
filler.Setup()
28-
.OnProperty(x => x.Name).Use(new RealNames(RealNameStyle.LastNameOnly));
28+
.OnProperty(x => x.Name).Use(new RealNames(NameStyle.LastName));
2929

3030
LibraryFillingTest.Person p = filler.Create();
3131

@@ -39,7 +39,7 @@ public void TestRealNameFirstNameLastName()
3939
{
4040
Filler<LibraryFillingTest.Person> filler = new Filler<LibraryFillingTest.Person>();
4141
filler.Setup()
42-
.OnProperty(x => x.Name).Use(new RealNames(RealNameStyle.FirstNameLastName));
42+
.OnProperty(x => x.Name).Use(new RealNames(NameStyle.FirstNameLastName));
4343

4444
LibraryFillingTest.Person p = filler.Create();
4545

@@ -54,7 +54,7 @@ public void TestRealNameLastNameFirstName()
5454
{
5555
Filler<LibraryFillingTest.Person> filler = new Filler<LibraryFillingTest.Person>();
5656
filler.Setup()
57-
.OnProperty(x => x.Name).Use(new RealNames(RealNameStyle.LastNameFirstName));
57+
.OnProperty(x => x.Name).Use(new RealNames(NameStyle.LastNameFirstName));
5858

5959
LibraryFillingTest.Person p = filler.Create();
6060

ObjectFiller.Test/SaveFillerSetupTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public void GetFillerSetup()
1818
_fillerSetup = filler.Setup()
1919
.OnType<IAddress>().CreateInstanceOf<Address>()
2020
.OnProperty(x => x.Age).Use(new IntRange(18, 35))
21-
.OnProperty(x => x.FirstName).Use(new RealNames(RealNameStyle.FirstNameOnly))
22-
.OnProperty(x => x.LastName).Use(new RealNames(RealNameStyle.LastNameOnly))
21+
.OnProperty(x => x.FirstName).Use(new RealNames(NameStyle.FirstName))
22+
.OnProperty(x => x.LastName).Use(new RealNames(NameStyle.LastName))
2323
.SetupFor<Address>()
2424
.OnProperty(x => x.HouseNumber).Use(new IntRange(1, 100))
2525
.Result;

ObjectFiller/HashStack.cs

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,56 @@
1-
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
4-
using System.Linq;
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="HashStack.cs" company="Tynamix">
3+
// © by GothicX
4+
// </copyright>
5+
// <summary>
6+
// A stack-like collection that uses a HashSet under the covers, so elements also need to be unique.
7+
// </summary>
8+
// --------------------------------------------------------------------------------------------------------------------
59

610
namespace Tynamix.ObjectFiller
711
{
12+
using System.Collections;
13+
using System.Collections.Generic;
14+
815
/// <summary>
916
/// A stack-like collection that uses a HashSet under the covers, so elements also need to be unique.
1017
/// </summary>
18+
/// <typeparam name="T">
19+
/// Type of the Hashstack
20+
/// </typeparam>
1121
/// <remarks>
1222
/// I decided to follow the HashSet more closely than the stack,
1323
/// which is why Push returns a boolean. I still think throwing an exception makes more
1424
/// sense, but if HashSet does it people should be already familiar with the paradigm.
15-
///
1625
/// Pop however follows the standard stack implementation, of course.
1726
/// </remarks>
1827
internal class HashStack<T> : IEnumerable<T>
1928
{
20-
private readonly HashSet<T> _set;
21-
private readonly Stack<T> _stack;
29+
/// <summary>
30+
/// The _set.
31+
/// </summary>
32+
private readonly HashSet<T> set;
2233

23-
internal HashStack() : this(EqualityComparer<T>.Default)
34+
private readonly Stack<T> stack;
35+
36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="HashStack{T}"/> class.
38+
/// </summary>
39+
internal HashStack()
40+
: this(EqualityComparer<T>.Default)
2441
{
2542
}
2643

44+
/// <summary>
45+
/// Initializes a new instance of the <see cref="HashStack{T}"/> class.
46+
/// </summary>
47+
/// <param name="comparer">
48+
/// The comparer.
49+
/// </param>
2750
internal HashStack(IEqualityComparer<T> comparer)
2851
{
29-
_set = new HashSet<T>(comparer);
30-
_stack = new Stack<T>();
52+
this.set = new HashSet<T>(comparer);
53+
this.stack = new Stack<T>();
3154
}
3255

3356
/// <summary>
@@ -36,40 +59,73 @@ internal HashStack(IEqualityComparer<T> comparer)
3659
/// <returns>True if the element is added; false if the element is already present.</returns>
3760
internal bool Push(T item)
3861
{
39-
var added = _set.Add(item);
40-
if (added) _stack.Push(item);
62+
var added = this.set.Add(item);
63+
if (added)
64+
{
65+
this.stack.Push(item);
66+
}
67+
4168
return added;
4269
}
4370

4471
/// <summary>
4572
/// Removes and returns the last added element.
4673
/// </summary>
74+
/// <returns>
75+
/// The item of type <see cref="T"/>
76+
/// </returns>
4777
internal T Pop()
4878
{
49-
var last = _stack.Pop();
50-
_set.Remove(last);
79+
var last = this.stack.Pop();
80+
this.set.Remove(last);
5181
return last;
5282
}
5383

84+
/// <summary>
85+
/// Clears the hash stack
86+
/// </summary>
5487
internal void Clear()
5588
{
56-
_set.Clear();
57-
_stack.Clear();
89+
this.set.Clear();
90+
this.stack.Clear();
5891
}
5992

93+
/// <summary>
94+
/// Checks if the <see cref="HashStack{T}"/> contains the <see cref="item"/>
95+
/// </summary>
96+
/// <param name="item">
97+
/// The item.
98+
/// </param>
99+
/// <returns>
100+
/// True if the <see cref="HashStack{T}"/> contains the item
101+
/// </returns>
60102
internal bool Contains(T item)
61103
{
62-
return _set.Contains(item);
104+
return this.set.Contains(item);
63105
}
64106

107+
/// <summary>
108+
/// Returns an enumerator that iterates through the collection.
109+
/// </summary>
110+
/// <returns>
111+
/// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
112+
/// </returns>
113+
/// <filterpriority>1</filterpriority>
65114
public IEnumerator<T> GetEnumerator()
66115
{
67-
return _stack.GetEnumerator();
116+
return this.stack.GetEnumerator();
68117
}
69118

119+
/// <summary>
120+
/// Returns an enumerator that iterates through a collection.
121+
/// </summary>
122+
/// <returns>
123+
/// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
124+
/// </returns>
125+
/// <filterpriority>2</filterpriority>
70126
IEnumerator IEnumerable.GetEnumerator()
71127
{
72-
return GetEnumerator();
128+
return this.GetEnumerator();
73129
}
74130
}
75131
}

ObjectFiller/IInterfaceMocker.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="IInterfaceMocker.cs" company="Tynamix">
3+
// ©2015 by Roman Köhler
4+
// </copyright>
5+
// <summary>
6+
// Implement this interface to use a mocking framework for instantiate your interfaces.
7+
// Register this <see cref="IInterfaceMocker" /> in the setup of the ObjectFiller
8+
// </summary>
9+
// --------------------------------------------------------------------------------------------------------------------
10+
111
namespace Tynamix.ObjectFiller
212
{
313
/// <summary>
4-
/// Implement this interface to use a mockingframework for instantiate your interfaces.
14+
/// Implement this interface to use a mocking framework for instantiate your interfaces.
515
/// Register this <see cref="IInterfaceMocker"/> in the setup of the ObjectFiller
616
/// </summary>
717
public interface IInterfaceMocker
Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,71 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="EnumeratorPlugin.cs" company="Tynamix">
3+
// © by Roman Köhler
4+
// </copyright>
5+
// <summary>
6+
// Enumerator plugin is used to always select the next value of an IEnumerable.
7+
// </summary>
8+
// --------------------------------------------------------------------------------------------------------------------
49

510
namespace Tynamix.ObjectFiller
611
{
12+
using System;
13+
using System.Collections.Generic;
14+
15+
/// <summary>
16+
/// Enumerator plugin is used to always select the next value of an IEnumerable.
17+
/// </summary>
18+
/// <typeparam name="T">Type for which the randomizer will generate data</typeparam>
719
internal class EnumeratorPlugin<T> : IRandomizerPlugin<T>
820
{
9-
private readonly IEnumerable<T> _enumerable;
10-
private IEnumerator<T> _enumerator;
21+
/// <summary>
22+
/// The enumerable.
23+
/// </summary>
24+
private readonly IEnumerable<T> enumerable;
1125

26+
/// <summary>
27+
/// The enumerator to move thru the the <see cref="enumerable"/>
28+
/// </summary>
29+
private IEnumerator<T> enumerator;
1230

31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="EnumeratorPlugin{T}"/> class.
33+
/// </summary>
34+
/// <param name="enumerable">
35+
/// The enumerable to select one value after another.
36+
/// </param>
1337
public EnumeratorPlugin(IEnumerable<T> enumerable)
1438
{
15-
_enumerable = enumerable;
39+
this.enumerable = enumerable;
1640
}
1741

42+
/// <summary>
43+
/// Gets random data for type <see cref="T"/>
44+
/// </summary>
45+
/// <returns>Random data for type <see cref="T"/></returns>
1846
public T GetValue()
1947
{
2048
// First time?
21-
if (_enumerator == null)
49+
if (this.enumerator == null)
2250
{
23-
_enumerator = _enumerable.GetEnumerator();
51+
this.enumerator = this.enumerable.GetEnumerator();
2452
}
2553

2654
// Advance, try to recover if we hit end-of-enumeration
27-
var hasNext = _enumerator.MoveNext();
55+
var hasNext = this.enumerator.MoveNext();
2856
if (!hasNext)
2957
{
30-
_enumerator = _enumerable.GetEnumerator();
31-
hasNext = _enumerator.MoveNext();
58+
this.enumerator = this.enumerable.GetEnumerator();
59+
hasNext = this.enumerator.MoveNext();
3260

3361
if (!hasNext)
3462
{
35-
string message = "Unable to get next value from enumeration " + _enumerable;
36-
Debug.WriteLine("ObjectFiller: " + message);
37-
throw new Exception(message);
63+
string message = string.Format("Unable to get next value from enumeration {0}", this.enumerable);
64+
throw new Exception(message);
3865
}
3966
}
4067

41-
return _enumerator.Current;
68+
return this.enumerator.Current;
4269
}
4370
}
4471
}

ObjectFiller/Plugins/IRandomizerPlugin.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
namespace Tynamix.ObjectFiller
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="IRandomizerPlugin.cs" company="Tynamix">
3+
// © 2015 by Roman Köhler
4+
// </copyright>
5+
// <summary>
6+
// Implement this interface to create a custom randomizer of type <see cref="T" />
7+
// </summary>
8+
// --------------------------------------------------------------------------------------------------------------------
9+
10+
namespace Tynamix.ObjectFiller
211
{
312
/// <summary>
413
/// Implement this interface to create a custom randomizer of type <see cref="T"/>

0 commit comments

Comments
 (0)