0

I'm using VS 2010 Professional built-in test cases. I've got a class that has a read-only property that looks something like this:

    Private _server As IServer = Nothing
    Public ReadOnly Property Server()
        Get
            If _server Is Nothing Then
                RemotingSetup.RegisterHttpBinaryChannel()
                _server = RemotingFactory.CreateProxy(Of IServer)(Options.DevLocal)
            End If

            Return _server
        End Get
    End Property

In my test cases I want to make a fake server implementation so I can test some of the class methods without actually hitting the server. I've looked around and have seen the InternalsVisibleTo attribute, but that seems to only allow access to Friend-level members.

Is there any simple way to get access to these members, aside from declaring them Public/Friend?

Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
  • check this question : http://stackoverflow.com/questions/250692/how-do-you-unit-test-private-methods – Matthieu Aug 01 '11 at 20:27

1 Answers1

0

Apart from using a mocking library that will mock private members (such as TypeMock, which is the only one I know of that does this), you are out of luck, at least when it comes to testing this particular class directly.

There are other possibilities - you can subclass from this class and only override this property. This will let you test all other functionality. Of course, this assumes that the class isn't sealed (NotInheritable).

Oded
  • 489,969
  • 99
  • 883
  • 1,009