the_drow
the_drow

Reputation: 19191

Mocking a silverlight socket

I am using the Moq library to mock the socket's behaviour.
My first problem was that socket had no interface but I exctracted an interface and I intend to use an adapter which implements the same interface.
I am trying to simulate a situation where the socket is connected, however the Connected property has no public set (and it shouldn't have one).
How would you go around it? Should I just create my own mock socket manually?
Is there another option?

Upvotes: 0

Views: 101

Answers (2)

the_drow
the_drow

Reputation: 19191

Fond the right syntax. It should be:

    var mock = new Mock<ISocket>();
    mock.SetupGet(socket => socket.Connected)
        .Returns(true);

Upvotes: 1

Phil Sandler
Phil Sandler

Reputation: 28046

I can't think of any time when I have found a need to to mock a setter. If you want the socket to appear connected, mock its connected property to return "true" (assuming it's boolean).

Maybe post a little more about what you are trying to accomplish with the mock?

Upvotes: 0

Related Questions