diff --git a/TestStack.Dossier.Tests/GetSetTests.cs b/TestStack.Dossier.Tests/GetSetTests.cs index 2362f91..18c98e7 100644 --- a/TestStack.Dossier.Tests/GetSetTests.cs +++ b/TestStack.Dossier.Tests/GetSetTests.cs @@ -25,6 +25,27 @@ public void GivenAValueHasBeenSetAgainstAProperty_WhenRetrievingTheValueForThatP retrieved.ShouldBe(SetValue); } + [Fact] + public void GivenAValueHasBeenSetAgainstANestedProperty_WhenRetrievingTheValueForThatProperty_ThenTheSetValueIsReturned() + { + _b.Set(x => x.PostalAddress.Identifier, SetValue); + + var retrieved = _b.Get(x => x.PostalAddress.Identifier); + + retrieved.ShouldBe(SetValue); + } + + [Fact] + public void GivenAValueHasBeenSetAgainstANestedPropertyAndDifferentVaLueHasBeenSetAgainstANonNestedPropertyWithTheSameName_WhenRetrievingTheValueForThatNestedProperty_ThenTheSetValueIsReturned() + { + _b.Set(x => x.PostalAddress.Identifier, SetValue); + _b.Set(x => x.Identifier, (string)null); + + var retrieved = _b.Get(x => x.PostalAddress.Identifier); + + retrieved.ShouldBe(SetValue); + } + [Fact] public void GivenTwoValuesHaveBeenSetAgainstAProperty_WhenRetrievingTheValueForThatProperty_ThenTheLastSetValueIsReturned() { diff --git a/TestStack.Dossier.Tests/TestHelpers/Builders/BasicCustomerBuilder.cs b/TestStack.Dossier.Tests/TestHelpers/Builders/BasicCustomerBuilder.cs index cc3e534..fc9952d 100644 --- a/TestStack.Dossier.Tests/TestHelpers/Builders/BasicCustomerBuilder.cs +++ b/TestStack.Dossier.Tests/TestHelpers/Builders/BasicCustomerBuilder.cs @@ -6,7 +6,7 @@ public class BasicCustomerBuilder : TestDataBuilder x.YearJoined, yearJoined); } + public virtual CustomerBuilder WithPostalAdressIdentifier(string identifier) + { + return Set(x => x.PostalAddress.Identifier, identifier); + } + protected override Customer BuildObject() { return new Customer( @@ -26,6 +31,14 @@ protected override Customer BuildObject() Get(x => x.FirstName), Get(x => x.LastName), Get(x => x.YearJoined), + new Address( + Get(x => x.PostalAddress.Identifier), + Get(x => x.PostalAddress.StreetNo), + Get(x => x.PostalAddress.StreetName), + Get(x => x.PostalAddress.Suburb), + Get(x => x.PostalAddress.City), + Get(x => x.PostalAddress.PostCode) + ), Get(x => x.CustomerClass) ); } diff --git a/TestStack.Dossier.Tests/TestHelpers/Objects/Entities/Address.cs b/TestStack.Dossier.Tests/TestHelpers/Objects/Entities/Address.cs new file mode 100644 index 0000000..01dfc5b --- /dev/null +++ b/TestStack.Dossier.Tests/TestHelpers/Objects/Entities/Address.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TestStack.Dossier.Tests.TestHelpers.Objects.Entities +{ + public class Address + { + protected Address() { } + + public Address(string identifier, int streetNo, string streetName, string suburb, string city, string postCode) + { + Identifier = identifier; + StreetNo = streetNo; + StreetName = streetName; + Suburb = suburb; + City = city; + PostCode = postCode; + } + + public string Identifier { get; private set; } + public virtual int StreetNo { get; private set; } + public string StreetName { get; private set; } + public string Suburb { get; private set; } + public string City { get; private set; } + public string PostCode { get; private set; } + } +} diff --git a/TestStack.Dossier.Tests/TestHelpers/Objects/Entities/Customer.cs b/TestStack.Dossier.Tests/TestHelpers/Objects/Entities/Customer.cs index 3c943ea..5202e8c 100644 --- a/TestStack.Dossier.Tests/TestHelpers/Objects/Entities/Customer.cs +++ b/TestStack.Dossier.Tests/TestHelpers/Objects/Entities/Customer.cs @@ -6,7 +6,7 @@ public class Customer { protected Customer() {} - public Customer(string identifier, string firstName, string lastName, int yearJoined, CustomerClass customerClass) + public Customer(string identifier, string firstName, string lastName, int yearJoined, Address postalAddress, CustomerClass customerClass) { if (string.IsNullOrEmpty(identifier)) throw new ArgumentNullException("identifier"); @@ -19,6 +19,7 @@ public Customer(string identifier, string firstName, string lastName, int yearJo FirstName = firstName; LastName = lastName; YearJoined = yearJoined; + PostalAddress = postalAddress; CustomerClass = customerClass; } @@ -33,6 +34,7 @@ public virtual int CustomerForHowManyYears(DateTime since) public virtual string FirstName { get; private set; } public virtual string LastName { get; private set; } public virtual int YearJoined { get; private set; } + public virtual Address PostalAddress { get; private set; } public virtual CustomerClass CustomerClass { get; private set; } } } diff --git a/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj b/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj index 4391a4f..e8fe2ff 100644 --- a/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj +++ b/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj @@ -66,6 +66,7 @@ + diff --git a/TestStack.Dossier/PathExpressionVisitor.cs b/TestStack.Dossier/PathExpressionVisitor.cs new file mode 100644 index 0000000..5e7ba19 --- /dev/null +++ b/TestStack.Dossier/PathExpressionVisitor.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Linq.Expressions; + +namespace TestStack.Dossier +{ + internal class PathExpressionVisitor : ExpressionVisitor + { + internal readonly List Path = new List(); + + protected override Expression VisitMember(MemberExpression node) + { + Path.Add(node.Member.Name); + return base.VisitMember(node); + } + } + +} diff --git a/TestStack.Dossier/Reflector.cs b/TestStack.Dossier/Reflector.cs index 80c9185..d01c98b 100644 --- a/TestStack.Dossier/Reflector.cs +++ b/TestStack.Dossier/Reflector.cs @@ -11,6 +11,7 @@ internal static class Reflector public static string GetPropertyNameFor(Expression> property) { var memExp = property.Body as MemberExpression; + if (memExp == null) throw new ArgumentException( string.Format( @@ -21,7 +22,10 @@ public static string GetPropertyNameFor(Expression() diff --git a/TestStack.Dossier/TestStack.Dossier.csproj b/TestStack.Dossier/TestStack.Dossier.csproj index 569a193..18981de 100644 --- a/TestStack.Dossier/TestStack.Dossier.csproj +++ b/TestStack.Dossier/TestStack.Dossier.csproj @@ -92,6 +92,7 @@ +