Customization compilation error

Aug 5, 2013 at 3:15 PM
Hello:

I have the following class that I am trying to test:
public class License
    {
        public virtual DateTime DatePurchased { get; set; }
        public virtual int LicenseDuration { get; set; }
        public virtual EnumDatePeriod PeriodType { get; set; }
        public virtual bool InUse { get; set; }

        public DateTime ExpirationDate()
        {
            ILicenseCalculator calculator = CreateLicenseDurationBuilder(PeriodType);

            return calculator.CalculateLicenseDuration(DatePurchased, LicenseDuration);
        }

        public ILicenseCalculator CreateLicenseDurationBuilder(EnumDatePeriod datePeriod)
        {
            Dictionary<EnumDatePeriod, ILicenseCalculator> calculators = new Dictionary<EnumDatePeriod, ILicenseCalculator>();
            calculators.Add(EnumDatePeriod.Year, new YearLicenseCalculator());
            calculators.Add(EnumDatePeriod.Month, new MonthLicenseCalculator());
            calculators.Add(EnumDatePeriod.Week, new WeekLicenseCalculator());
            calculators.Add(EnumDatePeriod.Day, new DayLicenseCalculator());

            return calculators[datePeriod];
        }
    }
Specifically, I want to see if I have a license that was purchased more than X time periods ago, the expiration date calculates properly. For example, I have a test that is set up to use a 6 month license, with a purchase date from seven months ago. I am trying to force a certain date, so I got into customizing, and set up my test as follows:
[Fact]
        public void CanCalculateExpirationDateOnExpiredMonthlyLicense()
        {
            Fixture fixture = new Fixture();
            fixture.Build<License>()
                .With(x => x.DatePurchased == DateTime.Now.AddMonths(-7))
                .Create();

        }
I realize that this isn't a complete test, but I ran it just to see what feedback I'd get, to make certain I was customizing properly. Looks like I'm not, because I get an error:

Result Message:
System.ArgumentException : The expression's Body is not a MemberExpression. Most likely this is because it does not represent access to a property or field.
Parameter name: propertyPicker

Where have I gone wrong?

Thanks for your help.
Coordinator
Aug 5, 2013 at 6:55 PM
Edited Aug 5, 2013 at 6:55 PM
Try the With overload that takes a value, e.g.
fixture.Build<License>()
    .With(x => x.DatePurchased, DateTime.Now.AddMonths(-7))
    .Create();
HTH