chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hi,
I ran this code:
            var fake_client_auth_context = Isolate.Fake.Instance<AuthorizationContext>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => ServiceSecurityContext.Current.AuthorizationContext).WillReturn(fake_client_auth_context);

            var fake_claim_set_list = new List<ClaimSet>();

            var fake_claim = new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dns", "fake-cf-system", "possess");

            var fake_claim_set = new DefaultClaimSet(new Claim[] {fake_claim});
            fake_claim_set_list.Add(fake_claim_set);

            Isolate.WhenCalled(() => fake_client_auth_context.ClaimSets).WillReturnCollectionValuesOf(fake_claim_set_list);


and got this exception back for the last line:

TypeMock.TypeMockException was unhandled by user code
  Message=
*** Cannot mock unsupported types from mscorlib assembly. See supported types here: https://www.typemock.com/mscorlib-types
  Source=TypeMock
  StackTrace:
       at TypeMock.MockManager.a(Type A_0, String A_1, Boolean A_2)
       at TypeMock.MockManager.a(Type A_0, String A_1)
       at TypeMock.MockManager.g(Type A_0)
       at TypeMock.MockManager.Mock(Type type, Constructor mockConstructors)
       at TypeMock.MockManager.a(Type A_0, Constructor A_1, Object[] A_2, Boolean A_3)
       at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
       at TypeMock.MockManager.MockObject[TMockedType]()
       at TypeMock.ArrangeActAssert.ExpectationEngine`1.a(IEnumerable A_0)
       at ... in ...
  InnerException: 


I'm a little baffled -- this seems like something I should be able to mock. The unit test code is VS2010 and I'm trying to test a VS2005 method. Is that the problem? I'm evaluating this software and if I can't even mock the authentication, I don't see how I can use this software.

According to the website linked in the exception (https://www.typemock.com/mscorlib-types), I can only mock the following types from mscorlib:
The following types are currently supported by Typemock Isolator:
[list]
System -
asked by sorakiu (4.2k points)

3 Answers

0 votes
Hi,

I run the code you posted and reproduced the error.
It looks like a bug in the Isolator since you are not trying to explicitly fake mscorlib type.
We will check it out and get back to you as soon as possible.
answered by ohad (35.4k points)
0 votes
In the meantime here is a workaround that you can use:

var fake_client_auth_context = Isolate.Fake.Instance<AuthorizationContext>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => ServiceSecurityContext.Current.AuthorizationContext).WillReturn(fake_client_auth_context);

var fake_claim_set_list = new List<ClaimSet>();
var fake_claim = new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dns", "fake-cf-system", "possess");

var fake_claim_set = new DefaultClaimSet(new Claim[] { fake_claim });
fake_claim_set_list.Add(fake_claim_set);
Isolate.WhenCalled(() => fake_client_auth_context.ClaimSets).WillReturn(new ReadOnlyCollection<ClaimSet>(fake_claim_set_list));


Please let me know if it helps.
answered by ohad (35.4k points)
0 votes
That worked, I think it is actually more correct than my code. I didn't realize I could do it that way. Thanks.

In the meantime here is a workaround that you can use:

var fake_client_auth_context = Isolate.Fake.Instance<AuthorizationContext>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => ServiceSecurityContext.Current.AuthorizationContext).WillReturn(fake_client_auth_context);

var fake_claim_set_list = new List<ClaimSet>();
var fake_claim = new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dns", "fake-cf-system", "possess");

var fake_claim_set = new DefaultClaimSet(new Claim[] { fake_claim });
fake_claim_set_list.Add(fake_claim_set);
Isolate.WhenCalled(() => fake_client_auth_context.ClaimSets).WillReturn(new ReadOnlyCollection<ClaimSet>(fake_claim_set_list));


Please let me know if it helps.
answered by sorakiu (4.2k points)
...