Hi,
You seem to have mixed two of our older APIs, Natural and Reflective mocks. Also, why not try writing this test using our new AAA API? It should be shorter and clearer - see full example below.
Let me know what you think!
Thanks,
Doron
Typemock support
public class ClassUnderTest
{
[PrincipalPermission(SecurityAction.Demand, Role = "EDITOR")]
public void DoSomething() {}
}
[TestClass]
public class SecurityPrincipalTests
{
private IPrincipal backup;
[TestInitialize]
public void SetUp()
{
backup = Thread.CurrentPrincipal;
}
[TestCleanup]
public void TearDown()
{
Thread.CurrentPrincipal = backup;
}
[TestMethod]
[Isolated]
public void WhenHasEditorPermissions_CanCallDoSomethingWithoutException()
{
IPrincipal fakePrincipal = Isolate.Fake.Instance<IPrincipal>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => fakePrincipal.IsInRole("")).WillReturn(true);
Isolate.WhenCalled(() => fakePrincipal.Identity.IsAuthenticated).WillReturn(true);
Thread.CurrentPrincipal = fakePrincipal;
ClassUnderTest target = new ClassUnderTest();
target.DoSomething();
}
}