• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
Team System Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Download
 
 
Support
 
 
Forums
 
 
 
Team System Developer Center > Visual Studio Team System Forums > Visual Studio Team System - Testing > Are list accessors working in 2008?
Ask a questionAsk a question
Search Forums:
  • Search Visual Studio Team System - Testing Forum Search Visual Studio Team System - Testing Forum
  • Search All Visual Studio Team System Forums Search All Visual Studio Team System Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerAre list accessors working in 2008?

  • Tuesday, September 02, 2008 7:10 PMEricAll Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    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?

    Thanks,

    Eric

    • ReplyReply
    • QuoteQuote
     

Answers

  • Wednesday, September 03, 2008 6:19 PMJoe Allan Muharsky - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0

     

    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:

     

    [assembly:InternalsVisibleTo("MyTestAssembly")]

    Hope this helps,

    • ReplyReply
    • QuoteQuote
     

All Replies

    Need Help with Forums? (FAQ)
     
    © 2009 Microsoft Corporation. All rights reserved.
    Terms of Use
    |
    Trademarks
    |
    Privacy Statement