I've done quite a bit of testing around sockets in an application I wrote...so I will try to be of assistance. Before we do that let's back up a moment and let me ask what you're trying to do? What is the scenario you want to test? You don't actually want your test to go out and connect to a bunch of ports do you?
(Also on another topic, I see you're using Socket and Tcp as the protocol, have you looked int TcpClient class which sits on top of Socket?) On Fri, Aug 21, 2009 at 2:13 PM, Seth Corduan < [email protected]> wrote: > Hello All, > > > > I’m just picking this up, so this may not be the brightest of questions, > but it has me relatively stumped. I’m experimenting with mocking a socket, > and have the following (sample) code implemented: > > > > [TestMethod] > > public void AbuseArrayList_UsingCreateMockGenerics() > > { > > MockRepository mocks = new MockRepository(); > > ArrayList list = mocks.StrictMock<ArrayList>(new Object[] > {15}); > > > > Socket sock = mocks.StrictMock<Socket>(new Object[] { > AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp }); > > > > Expect.Call(delegate { sock.Bind(new IPEndPoint(IPAddress.Any, > 12112)); }); > > // Setup the expectation of a call on the mock > > Expect.Call(delegate { list.GetRange(1, 1); }).Return(null); > > Expect.Call(list.Capacity).Return(999); > > > > > > mocks.ReplayAll(); > > > > // Evaluate the values from the mock > > Assert.AreEqual(999, list.Capacity); > > Assert.AreEqual(null, list.GetRange(1, 1)); > > > > mocks.VerifyAll(); ; > > } > > The odd part is that the call: > > > > Expect.Call(delegate { sock.Bind(new IPEndPoint( > IPAddress.Any, 12112)); }); > > > > > > Throws the exception: > > > > Test method TestSamples.UnitTest1.AbuseArrayList_UsingCreateMockGenerics > threw exception: System.InvalidOperationException: Invalid call, the last > call has been used or no call has been made (make sure that you are calling > a virtual (C#) / Overridable (VB) method).. > > > > > > Unless it is moved to after the other expects: > > > > > > Expect.Call(delegate { list.GetRange(1, 1); }).Return(null); > > Expect.Call(list.Capacity).Return(999); > > Expect.Call(delegate { sock.Bind(new IPEndPoint(IPAddress.Any, > 12112)); }); > > > > At that point, it doesn’t seem to have any effect at all. Any suggestions > as to what I should know, but don’t, would be appreciated. > > > > Seth Corduan > > Software Engineer > > *Attention: This message and all attachments are private and may contain > information that is confidential and privileged. If you receive this message > in error, please notify the sender by reply email and delete the message > immediately.* > > > > -- Tim Barcz ASPInsider http://timbarcz.devlicio.us http://www.twitter.com/timbarcz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en -~----------~----~----~----~------~----~------~--~---
