locked
Problems with MSTest private accessor and generics

    Question

  • I'm trying to test a private class in an assembly and so have tried to create a private accessor to the assembly. However when I compile the unit test assembly I get an error "Signature of the body and declaration in a method implementation do not match.  Type: 'Indexer'.  Assembly: 'ClassLibrary_Accessor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.    TestProject".

    The definition of the Indexer type is
        public class Class1
        {
            private class Indexer : IComparable<Indexer>
            {
                #region IComparable<Indexer> Members
    
                int IComparable<Indexer>.CompareTo(Indexer other)
                {
                    return 0;
                }
    
                #endregion
            }
        }

    The problem seems to be due to the explicit implementation of the IComparable interface as if I swap to an implicit implementation the error goes away. Is this a bug in the unit test framework?

    Is there a work around? The class that the error is raised for is not the one I am interested in testing, however there are a reasonable number of similarly implemented class in the assembly. Can I restrict the accessor to only wrap the class that I am interested in?

    Many thanks
    Monday, March 30, 2009 3:04 PM

Answers

  • Hi cambian

    You are hiting a know issue. There's an issue to generate private accessors for an assembly containing generic interface. It was reported at here and will be fixed in VS 2010.

    Currently, you can change the class Indexer to public to work around it.
    Please mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by cambian Wednesday, April 1, 2009 2:23 PM
    Wednesday, April 1, 2009 2:52 AM