Perhaps this can help - try to Mock the Constructor of BlackBoxClaimPermission using
var mock = MockManager.Mock(typeof(BlackBoxClaimPermission));
mock.ExpectUnmockedConstructor().Args(new Assign(...));
This way you can pass any argument you need during the test to the property
Well, I don't think this will help me very much. The problem is that inside the BlackBoxPermission attribute, there's a check (AOP) that the current thread's principal has a set of claims (specified in the attribute itself). When testing, the thread doesn't have a claimset at all, and I will get an exception.
So, basically I would like to write something like:
BlackBoxClaimPermissionAttribute attribute = Isolate.Fake.Instance<BlackBoxClaimPermissionAttribute>();
Isolate.Swap.NextInstance<BlackBoxClaimPermissionAttribute>().With(attribute);
Isolate.WhenCalled(() => attribute.Validate()).IgnoreCall();
But, either I'm doing something wrong, or this doesn't work. Remember I'm using dependency injection to make sure the security test (BlackBoxPermission) is running before the method logic.
By the way, there's a huge point here. This attribute is made because of security reasons. First of all, if I'm able to ignore it, wouldn't that be a great security issue? Second, if I refactor I have to make the refactored method public in order to test it. Yet again a great security issue (even though it wouldn't be available in the service itself, it would be available to anyone getting their hands in the dll).