MSDN > フォーラム ホーム > Visual Studio Team System - Testing > Are list accessors working in 2008?
質問する質問する
 

回答済みAre list accessors working in 2008?

  • 2008年9月2日 19:10EricAll ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     

    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

回答

  • 2008年9月3日 18:19Joe Allan Muharsky - MSFT ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み

     

    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,

すべての返信

  • 2008年9月3日 18:19Joe Allan Muharsky - MSFT ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み

     

    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,