Exemplo n.º 1
0
        public void TestClientNetwork()
        {
            byte[] toSend = new byte[10];
            string host   = "asd";
            int    port   = 1000;

            Mock <IDataSocket> mockDataSocket = new Mock <IDataSocket>();

            mockDataSocket.Setup(x => x.getMessage()).Returns <byte[]>(null);

            Mock <IClientSocket> mockClientSocket = new Mock <IClientSocket>();

            mockClientSocket.Setup(x => x.connect(It.IsAny <string>(), It.IsAny <Int32>()));
            mockClientSocket.Setup(x => x.handle()).Returns(mockDataSocket.Object);

            Mock <IBuilder <IClientSocket> > mockClientSocketBuilder = new Mock <IBuilder <IClientSocket> >();

            mockClientSocketBuilder.Setup(x => x.Build()).Returns(mockClientSocket.Object);

            ClientNetwork clientNetwork = new ClientNetwork(mockClientSocketBuilder.Object);

            clientNetwork.Connect(host, port);

            for (int i = 0; i < 100; i++)
            {
                clientNetwork.Handle();
            }

            clientNetwork.Send(toSend);



            mockClientSocket.Verify(x => x.connect(host, port));
            mockDataSocket.Verify(m => m.send(toSend));
        }