Skip to content

Commit 54abe2e

Browse files
gokTyBalDgokTyBalD
authored andcommitted
Fantastic PatternPlugin by charlass, namespace adjusting
1 parent e704aac commit 54abe2e

23 files changed

+690
-47
lines changed

ObjectFiller.Test/AddressFillingTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using ObjectFiller.Test.TestPoco.Person;
3+
using Tynamix.ObjectFiller;
34

45
namespace ObjectFiller.Test
56
{

ObjectFiller.Test/LibraryFillingTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using ObjectFiller.Test.TestPoco.Library;
3+
using Tynamix.ObjectFiller;
34

45
namespace ObjectFiller.Test
56
{

ObjectFiller.Test/ListFillingTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using ObjectFiller.Test.TestPoco.ListTest;
4+
using Tynamix.ObjectFiller;
45

56
namespace ObjectFiller.Test
67
{

ObjectFiller.Test/ObjectFiller.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,17 @@
6363
<Compile Include="TestPoco\Person\Address.cs" />
6464
<Compile Include="TestPoco\Person\IAddress.cs" />
6565
<Compile Include="TestPoco\Person\Person.cs" />
66+
<Compile Include="PatternGeneratorTest.cs" />
6667
</ItemGroup>
6768
<ItemGroup>
6869
<ProjectReference Include="..\ObjectFiller\ObjectFiller.csproj">
6970
<Project>{5D35C338-2162-4D16-A27C-3A0E5E72635D}</Project>
7071
<Name>ObjectFiller</Name>
7172
</ProjectReference>
7273
</ItemGroup>
74+
<ItemGroup>
75+
<Content Include="Chris_readme.txt" />
76+
</ItemGroup>
7377
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
7478
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7579
Other similar extension points exist, see Microsoft.Common.targets.

ObjectFiller.Test/ObjectFillerTest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using System;
2-
using System.Text;
32
using System.Collections.Generic;
4-
using System.Linq;
53
using Microsoft.VisualStudio.TestTools.UnitTesting;
6-
using ObjectFiller.FillerPlugins;
7-
using ObjectFiller.FillerPlugins.String;
84
using ObjectFiller.Test.TestPoco.Person;
5+
using Tynamix.ObjectFiller;
6+
using Tynamix.ObjectFiller.Plugins;
97

108
namespace ObjectFiller.Test
119
{
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using ObjectFiller;
4+
using System.Text.RegularExpressions;
5+
using System.Collections.Generic;
6+
using Tynamix.ObjectFiller;
7+
using Tynamix.ObjectFiller.Plugins;
8+
9+
namespace ObjectFiller.Test
10+
{
11+
[TestClass]
12+
public class PatternGeneratorTest
13+
{
14+
[TestMethod]
15+
public void Must_be_able_to_handle_private_setters()
16+
{
17+
var filler = new ObjectFiller<ClassWithPrivateStuff>();
18+
var obj = filler.Fill();
19+
20+
Assert.AreNotEqual(0, obj.WithPrivateSetter, "Must be able to set even a private setter");
21+
Assert.AreEqual(123, obj.WithoutSetter, "Cannot set that... must get default value");
22+
}
23+
24+
[TestMethod]
25+
public void Must_be_able_to_handle_inheritance_and_sealed()
26+
{
27+
var filler = new ObjectFiller<InheritedClass>();
28+
var obj = filler.Fill();
29+
30+
Assert.AreNotEqual(0, obj.NormalNumber);
31+
Assert.AreNotEqual(0, obj.OverrideNormalNumber);
32+
Assert.AreNotEqual(0, obj.SealedOverrideNormalNumber);
33+
}
34+
35+
[TestMethod, Ignore]
36+
public void Must_be_able_to_handle_arrays()
37+
{
38+
var filler = new ObjectFiller<WithArrays>();
39+
filler.Setup()
40+
.RegisterInterface<int[],int[]>();
41+
//.SetupFor<int[]>();
42+
var obj = filler.Fill();
43+
44+
Assert.IsNotNull(obj.Ints);
45+
Assert.IsNotNull(obj.Strings);
46+
Assert.IsNotNull(obj.Interfaces);
47+
}
48+
49+
[TestMethod]
50+
public void StringPatternGenerator_A()
51+
{
52+
HashSet<char> chars = new HashSet<char>();
53+
54+
var sut = new PatternGenerator("{A}");
55+
for (int n = 0; n < 10000; n++)
56+
{
57+
var s = sut.GetValue();
58+
Assert.IsTrue(Regex.IsMatch(s, "^[A-Z]$"));
59+
chars.Add(s[0]);
60+
}
61+
62+
Assert.AreEqual(26, chars.Count, "Should have all a..z");
63+
}
64+
65+
[TestMethod]
66+
public void StringPatternGenerator_A_fixed_len()
67+
{
68+
var sut = new PatternGenerator("x{A:3}x");
69+
for (int n = 0; n < 10000; n++)
70+
{
71+
var s = sut.GetValue();
72+
Assert.IsTrue(Regex.IsMatch(s, "^x[A-Z]{3}x$"));
73+
}
74+
}
75+
76+
[TestMethod]
77+
public void StringPatternGenerator_A_random_len()
78+
{
79+
var sut = new PatternGenerator("x{A:3-6}x");
80+
for (int n = 0; n < 10000; n++)
81+
{
82+
var s = sut.GetValue();
83+
Assert.IsTrue(Regex.IsMatch(s, "^x[A-Z]{3,6}x$"));
84+
}
85+
}
86+
87+
[TestMethod]
88+
public void StringPatternGenerator_a()
89+
{
90+
HashSet<char> chars = new HashSet<char>();
91+
92+
var sut = new PatternGenerator("{a}");
93+
for (int n = 0; n < 10000; n++)
94+
{
95+
var s = sut.GetValue();
96+
Assert.IsTrue(s.Length == 1);
97+
Assert.IsTrue(Regex.IsMatch(s, "^[a-z]$"));
98+
chars.Add(s[0]);
99+
}
100+
101+
Assert.AreEqual(26, chars.Count, "Should have all a..z");
102+
}
103+
104+
[TestMethod]
105+
public void StringPatternGenerator_aaa()
106+
{
107+
var sut = new PatternGenerator("xcccx");
108+
for (int n = 0; n < 10000; n++)
109+
{
110+
var s = sut.GetValue();
111+
Assert.IsTrue(s.Length == 5);
112+
Assert.IsTrue(Regex.IsMatch(s, "^x[a-z]{3}x$"));
113+
}
114+
}
115+
116+
[TestMethod]
117+
public void StringPatternGenerator_N()
118+
{
119+
HashSet<char> chars = new HashSet<char>();
120+
121+
var sut = new PatternGenerator("{N}");
122+
for (int n = 0; n < 10000; n++)
123+
{
124+
var s = sut.GetValue();
125+
Assert.IsTrue(s.Length == 1);
126+
Assert.IsTrue(Regex.IsMatch(s, "^[0-9]$"));
127+
chars.Add(s[0]);
128+
}
129+
130+
Assert.AreEqual(10, chars.Count, "Should have all 0-9");
131+
}
132+
133+
[TestMethod]
134+
public void StringPatternGenerator_X()
135+
{
136+
HashSet<char> chars = new HashSet<char>();
137+
138+
var sut = new PatternGenerator("{X}");
139+
for (int n = 0; n < 10000; n++)
140+
{
141+
var s = sut.GetValue();
142+
Assert.IsTrue(s.Length == 1);
143+
Assert.IsTrue(Regex.IsMatch(s, "^[0-9A-F]$"));
144+
chars.Add(s[0]);
145+
}
146+
147+
Assert.AreEqual(16, chars.Count, "Should have all 0-9 A-F");
148+
}
149+
150+
[TestMethod]
151+
public void StringPatternGenerator_C_simple()
152+
{
153+
var sut = new PatternGenerator("{C}");
154+
Assert.AreEqual("1", sut.GetValue());
155+
Assert.AreEqual("2", sut.GetValue());
156+
Assert.AreEqual("3", sut.GetValue());
157+
}
158+
159+
[TestMethod]
160+
public void StringPatternGenerator_C_with_StartValue()
161+
{
162+
var sut = new PatternGenerator("{C:33}");
163+
Assert.AreEqual("33", sut.GetValue());
164+
Assert.AreEqual("34", sut.GetValue());
165+
Assert.AreEqual("35", sut.GetValue());
166+
}
167+
168+
[TestMethod]
169+
public void StringPatternGenerator_C_with_StartValue_with_Increment()
170+
{
171+
var sut = new PatternGenerator("{C:33,3}");
172+
Assert.AreEqual("33", sut.GetValue());
173+
Assert.AreEqual("36", sut.GetValue());
174+
Assert.AreEqual("39", sut.GetValue());
175+
}
176+
177+
[TestMethod]
178+
public void StringPatternGenerator_C_combination()
179+
{
180+
var sut = new PatternGenerator("_{C}_{C:+11}_{C:110,10}_");
181+
Assert.AreEqual("_1_11_110_", sut.GetValue());
182+
Assert.AreEqual("_2_12_120_", sut.GetValue());
183+
Assert.AreEqual("_3_13_130_", sut.GetValue());
184+
Assert.AreEqual("_4_14_140_", sut.GetValue());
185+
}
186+
187+
[TestMethod]
188+
public void StringPatternGenerator_C_startvalue_negative_value()
189+
{
190+
var sut = new PatternGenerator("{C:-3}");
191+
Assert.AreEqual("-3", sut.GetValue());
192+
Assert.AreEqual("-2", sut.GetValue());
193+
Assert.AreEqual("-1", sut.GetValue());
194+
Assert.AreEqual("0", sut.GetValue());
195+
Assert.AreEqual("1", sut.GetValue());
196+
Assert.AreEqual("2", sut.GetValue());
197+
Assert.AreEqual("3", sut.GetValue());
198+
}
199+
200+
[TestMethod]
201+
public void StringPatternGenerator_C__startvalue_negative__positive_increment()
202+
{
203+
var sut = new PatternGenerator("{C:-3,+2}");
204+
Assert.AreEqual("-3", sut.GetValue());
205+
Assert.AreEqual("-1", sut.GetValue());
206+
Assert.AreEqual("1", sut.GetValue());
207+
Assert.AreEqual("3", sut.GetValue());
208+
}
209+
210+
[TestMethod]
211+
public void StringPatternGenerator_C__startvalue_negative__negative_increment()
212+
{
213+
var sut = new PatternGenerator("{C:-3,-2}");
214+
Assert.AreEqual("-3", sut.GetValue());
215+
Assert.AreEqual("-5", sut.GetValue());
216+
Assert.AreEqual("-7", sut.GetValue());
217+
}
218+
219+
}
220+
221+
public sealed class ClassWithPrivateStuff
222+
{
223+
public int WithPrivateSetter { get; private set; }
224+
public int WithoutSetter { get { return 123; } }
225+
}
226+
227+
public class BaseClass
228+
{
229+
public int NormalNumber { get; set; }
230+
public virtual int OverrideNormalNumber { get; set; }
231+
public virtual int SealedOverrideNormalNumber { get; set; }
232+
}
233+
234+
public class InheritedClass : BaseClass
235+
{
236+
public override int OverrideNormalNumber { get; set; }
237+
public override sealed int SealedOverrideNormalNumber { get; set; }
238+
}
239+
240+
public class WithArrays
241+
{
242+
public int[] Ints { get; set; }
243+
public string[] Strings { get; set; }
244+
public IDisposable[] Interfaces { get; set; }
245+
}
246+
}

ObjectFiller.Test/PersonFillingTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using Microsoft.VisualStudio.TestTools.UnitTesting;
4-
using ObjectFiller.FillerPlugins;
5-
using ObjectFiller.FillerPlugins.String;
64
using ObjectFiller.Test.TestPoco.Person;
5+
using Tynamix.ObjectFiller;
6+
using Tynamix.ObjectFiller.Plugins;
77

88
namespace ObjectFiller.Test
99
{

ObjectFiller/IFluentFillerApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.Linq.Expressions;
3-
using ObjectFiller.FillerPlugins;
3+
using Tynamix.ObjectFiller.Plugins;
44

5-
namespace ObjectFiller
5+
namespace Tynamix.ObjectFiller
66
{
77
/// <summary>
88
/// Interface for the fluent API of the ObjectFiller.NET.

ObjectFiller/IInterfaceMocker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ObjectFiller
1+
namespace Tynamix.ObjectFiller
22
{
33
/// <summary>
44
/// Implement this interface to use a mockingframework for instantiate your interfaces.

ObjectFiller/ObjectFiller.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Linq;
55
using System.Reflection;
66

7-
namespace ObjectFiller
7+
namespace Tynamix.ObjectFiller
88
{
99
/// <summary>
1010
/// The ObjectFiller.NET fills the public properties of your .NET object

0 commit comments

Comments
 (0)