Implicit/Explicit coversion with respect to the "as" keyword
I'm trying to do some unit testing on a project that unfortunately has high level of unit interdepence.   Currently, a lot of our classes look to a custom **UserIdentity** object to determine authentication, but that object has a lot of internal hoop-jumping that I would just as soon avoid when trying to test invidual unit functionality.

To work around some of this, I'm trying to create a "mock" verson of this UserIdentity that can be plugged in with a more  tightly-controlled variable environment.

Long story short, we have a UserIdentity class with several public read-only properties and a static CurrentIdentity (**IIdentity**) placeholder.  I'm able work around just about everything with a "mock" **IIdentity** implementation, but I'm running into a wall when I reach a point where the CurrentIdentity is cast as a **UserIdentity**.

It's a pretty straight-forward method:

    internal static UserIdentity GetCurrentIdentity()
    {
        UserIdentity currentIdentity = ApplicationContext.User.Identity as UserIdentity;
        return currentIdentity;
    }

I've set up my mock object to create a member of the **UserIdentity** type, and then do something like this:

        public static implicit operator UserIdentity(MockUserIdentity src)
        {
            return src.UserIdentity;
        }

or this

        public static explicit operator UserIdentity(MockUserIdentity src)
        {
            return src.UserIdentity;
        }

The problem is that as far as I can tell, that 'as' doesn't seem to invoke either an implicit or explicit conversion operation on my mock object.  My question(s) is(are?), am I missing something simple here or will this not work because (I'm guessing) the 'as' operation looks directly to class inheritence (which my object does not do...)? 

Also, a bit off topic maybe, but why can there not be simultaneous explict and implicit operators of the same resultant type within a class?   Unless I'm missing something silly, the compiler balks if I try to have both conversion operators at once.  I have to pick one or the other.
Implicit/Explicit coversion with respect to the "as" keyword
===

I'm trying to do some unit testing on a project that unfortunately has high level of unit interdepence.   Currently, a lot of our classes look to a custom **UserIdentity** object to determine authentication, but that object has a lot of internal hoop-jumping that I would just as soon avoid when trying to test invidual unit functionality.

To work around some of this, I'm trying to create a "mock" verson of this UserIdentity that can be plugged in with a more  tightly-controlled variable environment.

Long story short, we have a UserIdentity class with several public read-only properties and a static CurrentIdentity (**IIdentity**) placeholder.  I'm able work around just about everything with a "mock" **IIdentity** implementation, but I'm running into a wall when I reach a point where the CurrentIdentity is cast as a **UserIdentity**.

It's a pretty straight-forward method:

    internal static UserIdentity GetCurrentIdentity()
    {
        UserIdentity currentIdentity = ApplicationContext.User.Identity as UserIdentity;
        return currentIdentity;
    }

I've set up my mock object to create a member of the **UserIdentity** type, and then do something like this:

        public static implicit operator UserIdentity(MockUserIdentity src)
        {
            return src.UserIdentity;
        }

or this

        public static explicit operator UserIdentity(MockUserIdentity src)
        {
            return src.UserIdentity;
        }

The problem is that as far as I can tell, that 'as' doesn't seem to invoke either an implicit or explicit conversion operation on my mock object.  My question(s) is(are?), am I missing something simple here or will this not work because (I'm guessing) the 'as' operation looks directly to class inheritence (which my object does not do...)? 

Also, a bit off topic maybe, but why can there not be simultaneous explict and implicit operators of the same resultant type within a class?   Unless I'm missing something silly, the compiler balks if I try to have both conversion operators at once.  I have to pick one or the other.