Esempio n. 1
0
        public void Send_ByteArray_DataAddedToQueue()
        {
            // Setup the mock helper
            var mockHelper = new Mock <IP2PNodeHelper>();

            // Setup the expected method returns
            //mockHelper.Setup(d => d.BeginConnect(It.IsAny<IPEndPoint>(), It.IsAny<AsyncCallback>(), It.IsAny<Socket>()));

            Byte[] someData = new Byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

            var classInTest = new P2PClientNodeHarness(mockHelper.Object);

            classInTest.HasNetworkCycleStarted = true;
            classInTest.Send(someData);

            mockHelper.VerifyAll();

            // size = 4 bytes plus 10 bytes of data
            Assert.AreEqual(14, classInTest.SendQueue.Count);
        }
Esempio n. 2
0
        public void Send_ByteArrayCycleNotStarted_DataSent()
        {
            // Setup the mock helper
            var mockHelper = new Mock <IP2PNodeHelper>();

            // Setup the expected method returns
            mockHelper.Setup(d => d.BeginSend(It.IsAny <Byte[]>(), It.IsAny <AsyncCallback>(), It.IsAny <Socket>()));

            mockHelper.Setup(d => d.IsConnected(It.IsAny <Socket>()))
            .Returns(true);

            Byte[] someData = new Byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

            var classInTest = new P2PClientNodeHarness(mockHelper.Object);

            classInTest.HasNetworkCycleStarted = false;
            classInTest.Send(someData);

            mockHelper.VerifyAll();

            // queue should be clear after the data is sent
            Assert.AreEqual(0, classInTest.SendQueue.Count);
        }