Instance methods on DateTime RRS feed

  • Question

  • Hi,

    I'm using Pex and Moles to test some code that is dealing with DateTime calculations.  As expected, I can easily detour the static DateTime.Today property call using Moles:

    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas} span.s1 {color: #00a4bf} span.s2 {color: #0000ff}

    MDateTime.TodayGet = () => new DateTime(2011, 1, 1);

    However, I do various calculations that deal with instance members on DateTime such as .Year & .Month.  This is causing Pex to timeout on the constraint solver since the logic within those properties in the System.DateTime implementation is pretty complex.  Since I *know* the value of the DateTime, it would be really helpful if I could detour those properties, for example

    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas; color: #00a4bf} span.s1 {color: #000000} span.s2 {color: #ff0000}

    MDateTime.AllInstances.YearGet = () => 2011;


    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas} span.s1 {color: #00a4bf} span.s2 {color: #0000ff} span.s3 {color: #ff0000}

    MDateTime.TodayGet = () => new DateTime(2011, 1, 1) { YearGet = () => 2011 };

    Doing so would remove a ton of complexity and enable Pex to fully explore the code under test, but it appears as if Moles isn't allowing me to detour properties / methods on value types.  Is this an option somewhere or simply something that isn't implemented yet?  Or is there some deep reason that I'm missing as to why you can't do detours on Value types?





    Monday, January 10, 2011 8:29 PM

All replies

  • This looks like a silly limitation of the current implementation: replacing instance method for all instance on value type should be supported. Added to the backlog.

    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!
    Monday, January 10, 2011 10:42 PM