locked
Auto generated Accessor classes and base properties

    Question

  • When creating a unit test project VS created an accessor class to allow the unit tests to get at the private/protected members/methods of the class.

    However, I'm not able to access any members/methods that are part of the base class. Am I missing something? or does it not work this way?

    Wayne

    Friday, April 22, 2011 7:18 PM

Answers

  • Hi Wayne,


    You should be able to access the methods of base class.

    Here is an example:

    Dev Code:

    namespace Private
    {
    class Class1
    {
    private void A()
    {
    }
    protected void B()
    {
    }
    public void C()
    {
    }
    }

    class Class2 : Class1
    {
    private void D()
    {
    }
    }
    }

    Test Code:
    [TestMethod()]
    [DeploymentItem("Private.dll")]
    public void DTest()
    {
    Class2_Accessor target = new Class2_Accessor(); // TODO: Initialize to an appropriate value
    target.D();
    target.C();
    target.B();
    target.A();
    Assert.Inconclusive("A method that does not return a value cannot be verified.");
    }

    Thanks,

    Anuj

    Saturday, April 23, 2011 6:02 AM

All replies

  • Hi Wayne,


    You should be able to access the methods of base class.

    Here is an example:

    Dev Code:

    namespace Private
    {
    class Class1
    {
    private void A()
    {
    }
    protected void B()
    {
    }
    public void C()
    {
    }
    }

    class Class2 : Class1
    {
    private void D()
    {
    }
    }
    }

    Test Code:
    [TestMethod()]
    [DeploymentItem("Private.dll")]
    public void DTest()
    {
    Class2_Accessor target = new Class2_Accessor(); // TODO: Initialize to an appropriate value
    target.D();
    target.C();
    target.B();
    target.A();
    Assert.Inconclusive("A method that does not return a value cannot be verified.");
    }

    Thanks,

    Anuj

    Saturday, April 23, 2011 6:02 AM
  • Hi Wayne,

    What about your issue now? Have you resolved it? And I am marking Anuj's reply as answer. If you found it no help, please feel free to unmark it and let me know.

    Thanks,


    Vicky Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Saturday, April 30, 2011 1:20 AM