Beispiel #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);
        }
Beispiel #2
0
        public void Shutdown_SocketIsConnected_ExecuteSocketShutdown()
        {
            // Setup the mock helper
            var mockHelper = new Mock <IP2PNodeHelper>();

            // Setup the expected method returns
            mockHelper.Setup(d => d.CloseSocket(It.IsAny <Socket>()));

            mockHelper.Setup(d => d.ShutdownSocket(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.Shutdown();

            mockHelper.VerifyAll();
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public void Shutdown_SocketNotConnected_SkipSocketShutdown()
        {
            // Setup the mock helper
            var mockHelper = new Mock <IP2PNodeHelper>();

            // Setup the expected method returns
            mockHelper.Setup(d => d.CloseSocket(It.IsAny <Socket>())).Verifiable();

            mockHelper.Setup(d => d.ShutdownSocket(It.IsAny <Socket>()))
            .Throws(new AssertFailedException("Shutdown socket was executed, it should of been skipped."));

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

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

            var classInTest = new P2PClientNodeHarness(mockHelper.Object);

            classInTest.Shutdown();

            mockHelper.Verify();
        }