So the set up is this, I have a class and methods
Class DoThings
getCurrentThing returns Thing
string userName = WindowsIdentity.GetCurrent().Name;
call lookupThing(userName)
lookupThing(username)
Class UseDoThings
lastThingDone() returns the string we want to check
call DoThings.getCurrentThing
So we have created the following test code
Isolate.WhenCalled(() => new DoThings()).ReturnRecursiveFake(); //not sure it is required
DoThings fakeDoThings = new DoThings();
Isolate.WhenCalled(() => new DoThings()).WillReturn(fakeDoThings);
var fakeThing = new Thing ("Ogedei", "Sechen", "", "Ogedei.Sechen@Mongols.horde");
Isolate.WhenCalled(() => fakeADHelper.GetCurrent()).WillReturn(fakeThing);
Isolate.NonPublic.WhenCalled(fakeADHelper, "lookupUser").WillReturn(fakeUser);
These lines do not cause the target call to return the fakeUser only the current user
Isolate.WhenCalled(() => WindowsIdentity.GetCurrent().Name).WillReturn("UserName");
this tosses an error
Error Message
Test method ServicesTests.UtilityServiceTest.LastLoginInfoTest threw exception:
TypeMock.TypeMockException:
*** No method calls found in recording block. Please check:
* Are you trying to fake a field instead of a property?
* Are you are trying to fake an unsupported mscorlib type? See supported types here:
https://www.typemock.com/mscorlib-types
Error Stack Trace
gg.a(cx A_0, Boolean A_1)
bh.a(Boolean A_0)
dl.b(Boolean A_0)
ij.b(Boolean A_0)
ij.a(Object A_0, Boolean A_1, Func`1 A_2, Action A_3, Action A_4, Action A_5, Boolean A_6)
ij.e(Object A_0)
TypeMock.ArrangeActAssert.ExpectationEngine`1.a(TResult A_0)
UtilityService target = new UtilityService(); // TODO: Initialize to an appropriate value
UtilityService_Accessor targetAcc = new UtilityService_Accessor(); // TODO: Initialize to an appropriate value
string actual = target.LastLoginInfo();
string targetValue = String.Format("User <i>{0}</i> last logged on {1} at {2}", "Brian.Jones@EMG.Local", "", "") +
String.Format("<br>Bad Password Time: {0}<br>Last Successful Interactive Logon: {1} " +
"<br>Last failed logon time", "", "", "") +
String.Format("<br>Number of unsuccessful logon attempts: {0}<br>Failed Interactive Logon Count At Last Successful Logon: {1} "
, "", "");
target = new UseDoThings
actual = target.LastThingDone()
this always returns the current user and not the mocked value.
I am not sure what I am missing in the faking that is not overriding the call and what is wrong with the Windows Identity call as well
Thanks in advance for your assistance