Are list accessors working in 2008? RRS feed

  • Question

  • Hello-


    I just finished running through the TFS intro labs, and decided to try making a new unit test.  The Board class in the TicTacToe example exposes a Cells property that's of type List<Cell>.  Both this property and the Cell type are internal to the app assembly, so I right-clicked in the Board's editor and said "Create Private Accessor" like the demos suggested.


    In my unit test, I then added:

    Board_Accessor board = new Board_Accessor();


    Cool so far, but the next line will throw a type cast exception:

    object cell = board.Cells[3];


    It seems that the generated List<Cell_accessor> and the original List<Cell> types are not compatible.


    Is this expected?  Is there a workaround?



    Tuesday, September 2, 2008 7:10 PM



    Hi Eric,


    There are issues with doing deep copies of generic arrays and lists in the publicize functionality, much of it deriving from the .NET behavior you indicated; when A : B, List<A> is not compatible with List<B>.  As you're using internal members, however, the easiest path for you would be to make your assembly's internal visible to the test assembly, and then public accessors will not be neccessary at all for test code making use of internal members.  You can read more about InternalsVisibleTo at http://msdn.microsoft.com/en-us/library/0tke9fxk.aspx.  At a high level, the implementation will look like:



    Hope this helps,

    Wednesday, September 3, 2008 6:19 PM