Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,7 @@ UpgradeLog*.htm
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/
FakesAssemblies/
ObjectFillerNET.v2.ncrunchsolution
ObjectFiller/ObjectFiller.v2.ncrunchproject
ObjectFiller.Test/ObjectFiller.Test.v2.ncrunchproject
19 changes: 19 additions & 0 deletions ObjectFiller.Test/CityNamesPluginTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace ObjectFiller.Test
{
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Tynamix.ObjectFiller.Plugins.String;

[TestClass]
public class CityNamesPluginTest
{
[TestMethod]
public void RandomNameIsReturned()
{
var sut = new CityNames();
var value = sut.GetValue();

Assert.IsFalse(string.IsNullOrEmpty(value));
}
}
}
124 changes: 124 additions & 0 deletions ObjectFiller.Test/EmailAddressesPluginTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tynamix.ObjectFiller;

namespace ObjectFiller.Test
{
[TestClass]
public class EmailAddressesPluginTests
{
public string StandardAssertMessage = "Given value does not match e-mail address standard.";

/// <summary>
/// Regex for EMail addresses based on RFC 5322. Unfortunately, it does not find whitespace and yes I am to dumb to fix this issue...
/// </summary>
/// <seealso cref="http://www.regular-expressions.info/email.html"/>
private static Regex RFC5322RegEx = new Regex(
@"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", RegexOptions.IgnoreCase);

[TestMethod]
public void DefaultModeShouldReturnValidEmailAdress()
{
var value = new EmailAddresses().GetValue();

StringAssert.Matches(value, RFC5322RegEx, StandardAssertMessage);
}

[TestMethod]
public void TwoCallsCreateTwoDifferentEMailAddresses()
{
var sut = new EmailAddresses();
var firstValue = sut.GetValue();
var secondValue = sut.GetValue();

Assert.AreNotEqual(firstValue, secondValue);
}

[TestMethod]
public void EMailAddressMustBeValidWithRealNames()
{
var sut = new EmailAddresses();

var value = sut.GetValue();

StringAssert.Matches(value, RFC5322RegEx, StandardAssertMessage);
}

[TestMethod]
public void DomainNamesAreUsedFromRandomData()
{
var referenceValue = "google.com";
var fake = new FakeRandomizerPlugin<string>(referenceValue);

var sut = new EmailAddresses(fake, fake);

var result = sut.GetValue();

StringAssert.EndsWith(result, referenceValue);
StringAssert.Matches(result, RFC5322RegEx, StandardAssertMessage);
}

[TestMethod]
public void PluginMustEnsureValidAddressesEvenAnInvalidDomainNameIsProvided()
{
var referenceValue = "googlecom";
var fake = new FakeRandomizerPlugin<string>(referenceValue);

var sut = new EmailAddresses(fake, fake);

var result = sut.GetValue();

StringAssert.Matches(result, RFC5322RegEx, StandardAssertMessage);
}

[TestMethod]
public void LocalPathMustBeUsedFromRandomData()
{
var referenceValue = "karl";
var fake = new FakeRandomizerPlugin<string>(referenceValue);

var sut = new EmailAddresses(fake);

var result = sut.GetValue();

StringAssert.StartsWith(result, referenceValue);
StringAssert.Matches(result, RFC5322RegEx, StandardAssertMessage);
}

[TestMethod]
public void PluginMustEnsureValidAddressesEvenAnInvalidLocalPartIsProvided()
{
var referenceValue = "ka rl";
var fake = new FakeRandomizerPlugin<string>(referenceValue);

var sut = new EmailAddresses(fake);

var result = sut.GetValue();

StringAssert.Matches(result, RFC5322RegEx, StandardAssertMessage);
}

[TestMethod]
public void GivenDomainRootIsAttachedToGeneratedEmailAddress()
{
var domainRoot = ".de";
var sut = new EmailAddresses(domainRoot);

var result = sut.GetValue();

StringAssert.EndsWith(result, domainRoot);
StringAssert.Matches(result, RFC5322RegEx, StandardAssertMessage);
}

[TestMethod]
public void EmailAddressesWorksInCombinationWithRealNamesPlugin()
{
var realNames = new RealNames(RealNameStyle.FirstNameLastName);

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

StringAssert.Matches(result, RFC5322RegEx, StandardAssertMessage);
}
}
}
18 changes: 18 additions & 0 deletions ObjectFiller.Test/GermanStreetNamesPluginTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tynamix.ObjectFiller.Plugins.String;

namespace ObjectFiller.Test
{
[TestClass]
public class GermanStreetNamesPluginTest
{
[TestMethod]
public void RandomNameIsReturned()
{
var sut = new GermanStreetNames();
var value = sut.GetValue();

Assert.IsFalse(string.IsNullOrEmpty(value));
}
}
}
4 changes: 4 additions & 0 deletions ObjectFiller.Test/ObjectFiller.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AddressFillingTest.cs" />
<Compile Include="CityNamesPluginTest.cs" />
<Compile Include="CreateInstanceTest.cs" />
<Compile Include="DefaultDatatypeMappingsTest.cs" />
<Compile Include="EnumTest.cs" />
<Compile Include="GermanStreetNamesPluginTest.cs" />
<Compile Include="HashStackTests.cs" />
<Compile Include="LibraryFillingTest.cs" />
<Compile Include="ListFillingTest.cs" />
Expand All @@ -57,6 +59,7 @@
<Compile Include="PersonFillingTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ObjectFillerTest.cs" />
<Compile Include="RandomizerPluginFake.cs" />
<Compile Include="RangePluginTest.cs" />
<Compile Include="RealNamePluginTest.cs" />
<Compile Include="TestPoco\Library\Book.cs" />
Expand All @@ -76,6 +79,7 @@
<Compile Include="TestPoco\Person\OrderedPersonProperties.cs" />
<Compile Include="TestPoco\SimpleList.cs" />
<Compile Include="SaveFillerSetupTest.cs" />
<Compile Include="EmailAddressesPluginTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ObjectFiller\ObjectFiller.csproj">
Expand Down
31 changes: 31 additions & 0 deletions ObjectFiller.Test/RandomizerPluginFake.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using Tynamix.ObjectFiller;

namespace ObjectFiller.Test
{
public class FakeRandomizerPlugin<T> : IRandomizerPlugin<T>
{
public Func<T> OnGetValue;

public T ReturnValue { get; set; }

public FakeRandomizerPlugin()
{
}

public FakeRandomizerPlugin(T returnValue)
{
ReturnValue = returnValue;
}

public T GetValue()
{
if (OnGetValue != null)
{
return OnGetValue();
}

return ReturnValue;
}
}
}
3 changes: 3 additions & 0 deletions ObjectFiller/ObjectFiller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Plugins\String\CityNames.cs" />
<Compile Include="Plugins\String\EmailAddresses.cs" />
<Compile Include="Plugins\String\GermanStreetNames.cs" />
<Compile Include="Plugins\String\Lipsum.cs" />
<Compile Include="HashStack.cs" />
<Compile Include="Setup\FillerSetup.cs" />
Expand Down
1 change: 0 additions & 1 deletion ObjectFiller/Plugins/RandomListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public RandomListItem(IEnumerable<T> allAvailableValues)

}


public T GetValue()
{
int rndmListIndex = Random.Next(0, _allAvailableValues.Length);
Expand Down
23 changes: 23 additions & 0 deletions ObjectFiller/Plugins/String/CityNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Tynamix.ObjectFiller.Plugins.String
{
using System.Collections.Generic;

public class CityNames : IRandomizerPlugin<string>
{
protected readonly List<string> _names = new List<string>
{
"Lodon",
"Paris",
"Dresden",
"Berlin",
"Rom",
"New York"
};

public string GetValue()
{
var index = Random.Next(_names.Count - 1);
return _names[index];
}
}
}
67 changes: 67 additions & 0 deletions ObjectFiller/Plugins/String/EmailAddresses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

namespace Tynamix.ObjectFiller
{
public class EmailAddresses : IRandomizerPlugin<string>
{
private readonly IRandomizerPlugin<string> domainNameSource;

private readonly IRandomizerPlugin<string> localPartSource;

private string domainRoot;

public EmailAddresses()
: this(new MnemonicString(1), new MnemonicString(1), ".com")
{
}

public EmailAddresses(IRandomizerPlugin<string> localPartSource)
: this(localPartSource, new MnemonicString(1), ".com")
{
}

public EmailAddresses(
IRandomizerPlugin<string> localPartSource,
IRandomizerPlugin<string> domainSource,
string domainRoot)
{
this.domainRoot = domainRoot;
this.localPartSource = localPartSource;
this.domainNameSource = domainSource;
}

public EmailAddresses(string domainRoot)
: this(new MnemonicString(1), new MnemonicString(1), domainRoot)
{
}

public EmailAddresses(IRandomizerPlugin<string> localPartSource, IRandomizerPlugin<string> domainSource) : this(localPartSource, domainSource, ".com")
{
}

public string GetValue()
{
var localPart = this.GetLocalPart();
var domain = this.GetDomainName();

return string.Format("{0}@{1}", localPart, domain).ToLower();
}

private string GetDomainName()
{
var domainName = this.domainNameSource.GetValue();

if (domainName.Contains("."))
{
return domainName;
}

return string.Format("{0}{1}", domainName, this.domainRoot);
}

private string GetLocalPart()
{
var originalSample = this.localPartSource.GetValue();
return originalSample.Replace(" ", ".");
}
}
}
Loading