Skip to content

Commit ad391c4

Browse files
committed
Merge pull request #4 from Tynamix/FEATURE_LoremIpsumPlugin
LoremIpsum Plugin implemented
2 parents f11a7a7 + 6d3e3a6 commit ad391c4

File tree

6 files changed

+91
-3
lines changed

6 files changed

+91
-3
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using ObjectFiller.Test.TestPoco.Library;
4+
using Tynamix.ObjectFiller;
5+
using Tynamix.ObjectFiller.Plugins;
6+
7+
namespace ObjectFiller.Test
8+
{
9+
[TestClass]
10+
public class LoremIpsumPluginTest
11+
{
12+
[TestMethod]
13+
public void TestPlugin()
14+
{
15+
int isbnWordCount = 1000;
16+
int nameWordCount = 500;
17+
ObjectFiller<Book> bookFill = new ObjectFiller<Book>();
18+
bookFill.Setup()
19+
.RandomizerForProperty(new LoremIpsumPlugin(isbnWordCount), x => x.ISBN)
20+
.RandomizerForProperty(new LoremIpsumPlugin(nameWordCount), x => x.Name);
21+
22+
Book book = bookFill.Fill();
23+
24+
Assert.IsNotNull(book);
25+
Assert.IsNotNull(book.ISBN);
26+
Assert.IsNotNull(book.Name);
27+
Assert.AreEqual(isbnWordCount, book.ISBN.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length);
28+
Assert.AreEqual(nameWordCount, book.Name.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length);
29+
}
30+
}
31+
}

ObjectFiller.Test/ObjectFiller.Test.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<Compile Include="AddressFillingTest.cs" />
4949
<Compile Include="LibraryFillingTest.cs" />
5050
<Compile Include="ListFillingTest.cs" />
51+
<Compile Include="LoremIpsumPluginTest.cs" />
5152
<Compile Include="PersonFillingTest.cs" />
5253
<Compile Include="Properties\AssemblyInfo.cs" />
5354
<Compile Include="ObjectFillerTest.cs" />
@@ -71,9 +72,6 @@
7172
<Name>ObjectFiller</Name>
7273
</ProjectReference>
7374
</ItemGroup>
74-
<ItemGroup>
75-
<Content Include="Chris_readme.txt" />
76-
</ItemGroup>
7775
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
7876
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7977
Other similar extension points exist, see Microsoft.Common.targets.

ObjectFiller/ObjectFiller.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<Compile Include="Plugins\IRandomizerPlugin.cs" />
4242
<Compile Include="Plugins\PatternGenerator.cs" />
4343
<Compile Include="Plugins\RandomListItem.cs" />
44+
<Compile Include="Plugins\String\LoremIpsumPlugin.cs" />
4445
<Compile Include="Plugins\String\MnemonicStringPlugin.cs" />
4546
<Compile Include="Plugins\String\RealNamePlugin.cs" />
4647
<Compile Include="IFluentFillerApi.cs" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using Tynamix.ObjectFiller.Properties;
3+
4+
namespace Tynamix.ObjectFiller.Plugins
5+
{
6+
public class LoremIpsumPlugin : IRandomizerPlugin<string>
7+
{
8+
private readonly int _wordCount;
9+
private readonly string[] _loremIpsumWords;
10+
11+
public LoremIpsumPlugin(int wordCount)
12+
{
13+
_wordCount = wordCount;
14+
_loremIpsumWords = Resources.loremIpsum.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
15+
}
16+
17+
/// <summary>
18+
/// Gets random data for type <see cref="T"/>
19+
/// </summary>
20+
/// <returns>Random data for type <see cref="T"/></returns>
21+
public string GetValue()
22+
{
23+
string result = string.Empty;
24+
for (int i = 0; i < _wordCount; i++)
25+
{
26+
result += _loremIpsumWords[i % _loremIpsumWords.Length] + " ";
27+
}
28+
29+
return result;
30+
}
31+
}
32+
}

ObjectFiller/Properties/Resources.Designer.cs

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ObjectFiller/Properties/Resources.resx

Lines changed: 15 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)