Hi,
There problem here is that the code is using a public field, TypeMock at this time does not mock fields, so to mock the singleton correctly you would use:
public static class Singleton<T> where T :
{
private static readonly T instance =
typeof(T).InvokeMember(typeof(T).Name,
BindingFlags.CreateInstance |
BindingFlags.Instance |
BindingFlags.NonPublic, null, null, null,
CultureInfo.InvariantCulture) as T;
public static T Instance
{
get { return instance; }
}
}
In any case as a workaround until we implement mocking fields, if you don't want to use a property in the Singleton class, is to call ApplicationSettings.Instance before the recording
e.g.
ApplicationSettings dummy = ApplicationSettings.Instance;
using (RecordExpectations recorder = RecorderManager.StartRecording())
{ recorder.ExpectAndReturn(ApplicationSettings.Instance.AccountImpersonationTicketTimeout, 30);
}