locked
unit testing - private accessor - System.InvalidCastException RRS feed

  • Question

  • i wrote a simple unit testing that used a private accessor

    when i try to get m using the private accessor i get : "System.InvalidCastException"

     

    public class X

    {

            private IDictionary<int, MyClass> m;

    }

     

     

     

    this.target = new X();

    X_Accessor a = new X_Accessor(new PrivateObject(this.target));

    MyClass mmm = a.m[0];

     

     

    why?

    thanks

     

    • Moved by Figo Fei Tuesday, March 23, 2010 2:05 AM (From:Visual Studio Team System - Testing)
    Monday, March 22, 2010 11:11 AM

Answers

All replies

  • Hi yanfog,

    What MyClass's definition looks like? From the error message, it complaint about the type casting problem.

    move to Unit test forum for further response.

    Thanks.


    Figo Fei
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Tuesday, March 23, 2010 2:04 AM
  •  

     

    MyClass

    {

    int i;

    string s;

    }

     

    when i look into the Accessor it's shows

     

    public class Accessor_X

    {

            private IDictionary<int, Accessor_MyClass> m;

    }

     

    and it couldn't cast MyClass to Accessor_MyClass

    Tuesday, March 23, 2010 8:51 AM
  • Hi yanfog,

    The problem is that IDictionary<int, Accessor_MyClass> and IDictionary<int, MyClass> are two different interfaces, they cannot be casted directly.

    Thanks.


    Figo Fei
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Tuesday, March 23, 2010 9:03 AM
  • yes i know, but it generated automatically- by creating a new accessor...

    i have IDictionary<int, MyClass> in my class

    but it generated to me IDictionary<int, Accessor_MyClass>

    Tuesday, March 23, 2010 9:05 AM
  • We're no longer supporting publicize/code generation, please take a look at the following blog:

    http://blogs.msdn.com/vstsqualitytools/archive/2010/01/18/publicize-and-code-generation-for-visual-studio-2010.aspx

    Thanks,
    David Gorena Elizondo
    [MSFT] Visual Studio Team Test

    Tuesday, March 23, 2010 10:41 PM