Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="nunit.core">
<HintPath>..\packages\NUnitTestAdapter.1.2\lib\nunit.core.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -101,6 +102,8 @@
<Compile Include="HydratorTests\Hydrator_SimpleAddress_Tests.cs" />
<Compile Include="HydratorTests\Hydrator_SimpleCustomer_Tests.cs" />
<Compile Include="HydratorTests\InjectedGenerator.cs" />
<Compile Include="HydratorTests\GenericHydrator_SimpleCustomer_Tests.cs" />
<Compile Include="HydratorTests\TestUtilities.cs" />
<Compile Include="POCOs\Address.cs" />
<Compile Include="POCOs\ComplexCustomer.cs" />
<Compile Include="POCOs\RestrictedDescriptionCustomer.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Foundation.ObjectHydrator.Tests.POCOs;
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Generic;

namespace Foundation.ObjectHydrator.Tests.HydratorTests {
[TestFixture]
public class GenericHydrator_SimpleCustomer_Tests {

Hydrator hydrator;

[TestFixtureSetUp]
public void Initialize() {
hydrator = new Hydrator(typeof(SimpleCustomer));
}

[Test]
public void Generic_CanGetSingleSimpleCustomer() {
var customer = hydrator.GetSingle() as SimpleCustomer;
Assert.IsTrue(!String.IsNullOrEmpty(customer.Description), "Customer Description should exist.");
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
public void Generic_CanGetSingleRestrictedDescriptionCustomer() {
var customer = hydrator.GetSingle() as SimpleCustomer;

Assert.IsTrue(!String.IsNullOrEmpty(customer.Description), "Customer Description should exist.");
Assert.IsTrue(customer.Description.Length <= 5, "Length not restricted");
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
public void Generic_CanGetList() {
var listCount = 50;
var customers = hydrator.GetList(listCount) as IList;

Assert.IsTrue(customers.Count == listCount, "Customer count is wrong.");

//DumpCustomers(customers);
}

[Test]
public void Generic_CanGetDescription() {
var customer = hydrator.GetSingle() as SimpleCustomer;

Assert.IsTrue(!String.IsNullOrEmpty(customer.Description), "Customer Description should exist.");

TestUtilities.DumpSimpleCustomer(customer);
}



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void CanGetSingleSimpleCustomer()

Assert.IsTrue(!String.IsNullOrEmpty(customer.Description), "Customer Description should exist.");

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -31,7 +31,7 @@ public void CanGetSingleRestrictedDescriptionCustomer()

Assert.IsTrue(!String.IsNullOrEmpty(customer.Description), "Customer Description should exist.");
Assert.IsTrue(customer.Description.Length <= 5,"Length not restricted");
DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}


Expand All @@ -55,7 +55,7 @@ public void CanGetDescription()

Assert.IsTrue(!String.IsNullOrEmpty(customer.Description), "Customer Description should exist.");

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -69,7 +69,7 @@ public void CanConstrainIntegers()
Assert.IsTrue(customer.Locations >= 5 && customer.Locations <= 10,
String.Format("Customer Locations [{0}] is outside expected range.", customer.Locations));

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}


Expand All @@ -85,7 +85,7 @@ public void CanDefaultString()

Assert.IsTrue(defaultValue == customer.Description, String.Format("Default value is not as expected[{0}]", defaultValue));

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -108,7 +108,7 @@ public void CanGetInteger()

Assert.IsTrue(customer.Locations >= 0, String.Format("Customer Locations is expected."));

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -120,7 +120,7 @@ public void CanGetDouble()

Assert.IsTrue(customer.Revenue >= 0, String.Format("Customer Revenue is expected."));

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -135,7 +135,7 @@ public void CanConstrainDoubleDecimalPlaces()
var decimalPart = customer.Revenue - (int) customer.Revenue;
Assert.IsTrue(decimalPart >= 0, String.Format("Customer Revenue decimal part is expected."));

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -149,7 +149,7 @@ public void CanConstrainDoubleRange()

var customer = hydrator.GetSingle();
Assert.That(customer.Revenue, Is.InRange(minimum, maximum));
DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -168,7 +168,7 @@ public void CanConstrainDoubleRangeAndDecimals()
Assert.That(customer.Revenue, Is.InRange(minimum, maximum));
Assert.IsTrue(decimalPart >= 0, String.Format("Customer Revenue decimal part is expected."));

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -183,7 +183,7 @@ public void CanDefaultInteger()

Assert.IsTrue(defaultValue == customer.Locations, String.Format("Default value is not as expected[{0}]", defaultValue));

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -199,7 +199,7 @@ public void CanDefaultDateTime()

Assert.IsTrue(defaultValue == customer.IncorporatedOn, String.Format("Default value is not as expected[{0}]", defaultValue));

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -220,7 +220,7 @@ public void CanChainWithDefaultDescription()
Assert.That(customer.Locations, Is.InRange(minimumValue, maximumValue),
String.Format("Customer Locations [{0}] is outside expected range [{1},{2}].", customer.Locations, minimumValue,
maximumValue));
DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -238,7 +238,7 @@ public void CanConstrainWithDates()
Assert.That(customer.IncorporatedOn, Is.InRange(minimumValue, maximumValue),
String.Format("Customer IncorporatedOn [{0}] is outside expected range [{1}, {2}].", customer.IncorporatedOn,
minimumValue, maximumValue));
DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -256,7 +256,7 @@ public void CanConstrainDates()
Assert.That(customer.IncorporatedOn, Is.InRange(minimumValue, maximumValue),
String.Format("Customer IncorporatedOn [{0}] is outside expected range [{1}, {2}].", customer.IncorporatedOn,
minimumValue, maximumValue));
DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -270,7 +270,7 @@ public void CanGetByteArray()

Assert.IsTrue(customer.Version.Length == length, String.Format("Customer Version Length is expected to be {0}.", length));

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand All @@ -288,7 +288,7 @@ public void CanGetCreditCardNumber()
String.Format("Credit Card Number [{0}] should be {1} long.", customer.CreditCardNumber,
length));

DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

private bool IsWebsiteAddressValid(string webaddy)
Expand Down Expand Up @@ -394,7 +394,7 @@ public void BooleanGenerator()
var customer = hydrator.GetSingle();
Assert.IsNotNull(customer.IsActive);
Assert.IsInstanceOfType(typeof (bool), customer.IsActive);
DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}

[Test]
Expand Down Expand Up @@ -622,31 +622,10 @@ private void DumpCustomers(IList<SimpleCustomer> customers)
{
foreach (SimpleCustomer customer in customers)
{
DumpSimpleCustomer(customer);
TestUtilities.DumpSimpleCustomer(customer);
}
}

private void DumpSimpleCustomer(Object theObject)
{
Trace.WriteLine("");
foreach (PropertyInfo propertyInfo in theObject.GetType().GetProperties())
{
Trace.WriteLine(String.Format("{0} [{1}]", propertyInfo.Name, propertyInfo.GetValue(theObject, null)));

if (propertyInfo.PropertyType == typeof (byte[]))
{
var theArray = propertyInfo.GetValue(theObject, null) as byte[];
if (theArray != null)
{
Trace.Write(" byte[] ");
for (var i = 0; i < theArray.Length; i++)
{
Trace.Write(String.Format("[{0}]", theArray[i]));
}
Trace.WriteLine(String.Empty);
}
}
}
}

}
}
29 changes: 29 additions & 0 deletions Foundation.ObjectHydrator.Tests/HydratorTests/TestUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Foundation.ObjectHydrator.Tests.HydratorTests {
public static class TestUtilities {
public static void DumpSimpleCustomer(Object theObject) {
Trace.WriteLine("");
foreach (PropertyInfo propertyInfo in theObject.GetType().GetProperties()) {
Trace.WriteLine(String.Format("{0} [{1}]", propertyInfo.Name, propertyInfo.GetValue(theObject, null)));

if (propertyInfo.PropertyType == typeof(byte[])) {
var theArray = propertyInfo.GetValue(theObject, null) as byte[];
if (theArray != null) {
Trace.Write(" byte[] ");
for (var i = 0; i < theArray.Length; i++) {
Trace.Write(String.Format("[{0}]", theArray[i]));
}
Trace.WriteLine(String.Empty);
}
}
}
}

}
}
1 change: 1 addition & 0 deletions Foundation.ObjectHydrator/Foundation.ObjectHydrator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<Compile Include="Generators\UnitedKingdomCountyGenerator.cs" />
<Compile Include="Generators\UnitedKingdomPostcodeGenerator.cs" />
<Compile Include="Generators\WebsiteGenerator.cs" />
<Compile Include="GenericHydrator.cs" />
<Compile Include="Hydrator.cs" />
<Compile Include="Interfaces\IMap.cs" />
<Compile Include="Interfaces\IMapping.cs" />
Expand Down
Loading