witdaj on Fri, 31 May 2013 16:12:24

If I'm going to test this method below, would I just need to shim out the two method calls inside my tested method or should my test run these two methods (PreviousQuarterEnd, ResolveDate)and get their values to complete my test?

public override DateTime ResolveDate(ISeries comparisonSeries, DateTime targetDate)
            switch (comparisonSeries.Key)
                case SeriesKey.SomeKey1:
                case SeriesKey.SomeKey2:
                case SeriesKey.SomeKey3:
                case SeriesKey.SomeKey4:
                case SeriesKey.SomeKey5:
                    return DateHelper.PreviousOrCurrentQuarterEnd(targetDate);

            return base.ResolveDate(comparisonSeries, targetDate);




Amanda Zhu on Mon, 03 Jun 2013 02:32:47


Thank you for your post.

As far as I know, a shim modifies the compiled code of your application at run time so that instead of making a specified method call, it runs the shim code that your test provides. Shims can be used to replace calls to assemblies that you cannot modify, such .NET assemblies.

If you want to unit test DateTime ResolveDate method, it is a good choice to shim the method in test method. You can know more information about Microsoft Fakes from:

Isolating Code Under Test with Microsoft Fakes

And this article provides detailed steps and samples for testing with Shims:

Using shims to isolate your application from other assemblies for unit testing

Best regards,