Exemplo n.º 1
0
        public void ConnectNoArgs_ZeroPort_ThrowsArgumentOutOfRange()
        {
            var socket = new SymSocket();
            socket.Server = "symitar";

            Assert.Throws<ArgumentOutOfRangeException>(() => socket.Connect());
        }
Exemplo n.º 2
0
        public void ConnectNoArgs_ZeroPort_ThrowsArgumentOutOfRange()
        {
            var socket = new SymSocket();

            socket.Server = "symitar";

            Assert.Throws <ArgumentOutOfRangeException>(() => socket.Connect());
        }
Exemplo n.º 3
0
        public void Connect_AlreadyConnected_ThrowsInvalidOperation()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();
            tcpAdapterMock.Connected.Returns(true);

            var socket = new SymSocket(tcpAdapterMock);
            Assert.Throws<InvalidOperationException>(() => socket.Connect("symitar", 23));
        }
Exemplo n.º 4
0
        public void Connect_SuccessfulConnection_ReturnsTrue()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);

            socket.Connect("symitar", 23).Should().BeTrue();
        }
Exemplo n.º 5
0
        public void ConnectNoArgs_NoServerSet_ThrowsArgumentNull()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);
            socket.Port = 23;

            Assert.Throws<ArgumentNullException>(() => socket.Connect());
        }
Exemplo n.º 6
0
        public void Disconnect_ClosesClient()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);

            socket.Disconnect();
            tcpAdapterMock.Received().Close();
        }
Exemplo n.º 7
0
        public void Connect_CallsUnderlyingClient()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();
            var socket = new SymSocket(tcpAdapterMock);

            socket.Connect("symitar", 23);

            tcpAdapterMock.Received().Connect("symitar", 23);
        }
Exemplo n.º 8
0
        public void Connect_CallsUnderlyingClient()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();
            var socket         = new SymSocket(tcpAdapterMock);

            socket.Connect("symitar", 23);

            tcpAdapterMock.Received().Connect("symitar", 23);
        }
Exemplo n.º 9
0
        public void Connect_SuccessfulConnectionWithIpAddress_CallsHostNameConnectOnAdapter()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);

            socket.Connect("symitar", 23);
            tcpAdapterMock.Received().Connect("symitar", 23);
        }
Exemplo n.º 10
0
        public void Connect_SuccessfulConnectionWithIpAddress_ReturnsTrue()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            var  socket = new SymSocket(tcpAdapterMock);
            bool result = socket.Connect("127.0.0.1", 23);

            result.Should().BeTrue();
        }
Exemplo n.º 11
0
        public void ConnectNoArgs_AfterSettingServerAndPort_ReturnsTrue()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);
            socket.Server = "symitar";
            socket.Port = 23;

            socket.Connect().Should().BeTrue();
        }
Exemplo n.º 12
0
        public void Read_NoData_ReturnsEmptyString()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            tcpAdapterMock.Read().Returns(new byte[0]);

            var socket = new SymSocket(tcpAdapterMock);

            socket.Read().Should().Be("");
        }
Exemplo n.º 13
0
 public void ReadUntilMultiMatch_EmptyMatcherSet_ThrowsArugmentException()
 {
     Assert.Throws <ArgumentException>(
         () =>
     {
         var socket = new SymSocket();
         socket.WaitFor();
     }
         );
 }
Exemplo n.º 14
0
        public void ConnectNoArgs_NoServerSet_ThrowsArgumentNull()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);

            socket.Port = 23;

            Assert.Throws <ArgumentNullException>(() => socket.Connect());
        }
Exemplo n.º 15
0
        public void Connect_AlreadyConnected_ThrowsInvalidOperation()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            tcpAdapterMock.Connected.Returns(true);

            var socket = new SymSocket(tcpAdapterMock);

            Assert.Throws <InvalidOperationException>(() => socket.Connect("symitar", 23));
        }
Exemplo n.º 16
0
        public void Connect_SuccessfulConnection_HasBlankError()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);

            socket.Connect("symitar", 23);

            socket.Error.Should().BeNullOrEmpty();
        }
Exemplo n.º 17
0
        public void ConnectNoArgs_AfterSettingServerAndPort_ReturnsTrue()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);

            socket.Server = "symitar";
            socket.Port   = 23;

            socket.Connect().Should().BeTrue();
        }
Exemplo n.º 18
0
        public void Read_SingleChunk_ReturnsCorrectString()
        {
            var chunk = Encoding.ASCII.GetBytes("data");

            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            tcpAdapterMock.Read().Returns(x => chunk, x => new byte[0]);

            var socket = new SymSocket(tcpAdapterMock);

            socket.Read().Should().Be("data");
        }
Exemplo n.º 19
0
        public void Connect_ClientConnectException_ReturnsFalse()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            tcpAdapterMock
            .When(x => x.Connect("symitar", 23))
            .Do(x => { throw new InvalidOperationException(); });

            var  socket = new SymSocket(tcpAdapterMock);
            bool result = socket.Connect("symitar", 23);

            result.Should().BeFalse();
        }
Exemplo n.º 20
0
        public void Read_MultipleChunks_ConcatenatesCorrectly()
        {
            var chunk1 = Encoding.ASCII.GetBytes("doubl");
            var chunk2 = Encoding.ASCII.GetBytes("e data");

            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            tcpAdapterMock.Read().Returns(x => chunk1, x => chunk2, x => new byte[0]);

            var socket = new SymSocket(tcpAdapterMock);

            socket.Read().Should().Be("double data");
        }
Exemplo n.º 21
0
        public void Connect_ClientConnectException_HasErrorMessage()
        {
            var tcpAdapterMock = Substitute.For <ITcpAdapter>();

            tcpAdapterMock
            .When(x => x.Connect("symitar", 23))
            .Do(x => { throw new InvalidOperationException(); });

            var socket = new SymSocket(tcpAdapterMock);

            socket.Connect("symitar", 23);
            socket.Error.Should().Contain("Unable to Connect to Server");
        }
Exemplo n.º 22
0
        private void startButton_Click(object sender, EventArgs e)
        {
            Thread.CurrentThread.Name = "Main Thread";
            if (_session != null)
            {
                _socket.Disconnect();
                _socket = null;
            }

            var adapter = new SocketAdapter();

            _socket  = new SymSocket(adapter, "symitar", 23);
            _session = new SymSession(_socket, 670);
            Login();
        }
Exemplo n.º 23
0
        public void Connect_SuccessfulConnectionWithIpAddress_ReturnsTrue()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);
            bool result = socket.Connect("127.0.0.1", 23);
            result.Should().BeTrue();
        }
Exemplo n.º 24
0
 public void Connect_NullServer_ThrowsArgumentNull()
 {
     var socket = new SymSocket();
     Assert.Throws<ArgumentNullException>(() => socket.Connect(null, 1));
 }
Exemplo n.º 25
0
        public void Connect_NullServer_ThrowsArgumentNull()
        {
            var socket = new SymSocket();

            Assert.Throws <ArgumentNullException>(() => socket.Connect(null, 1));
        }
Exemplo n.º 26
0
        public void Connect_SuccessfulConnection_HasBlankError()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);
            socket.Connect("symitar", 23);

            socket.Error.Should().BeNullOrEmpty();
        }
Exemplo n.º 27
0
        public void Connect_SuccessfulConnection_ReturnsTrue()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);

            socket.Connect("symitar", 23).Should().BeTrue();
        }
Exemplo n.º 28
0
        public void Connect_NegativePort_ThrowsArgumentOutOfRange()
        {
            var socket = new SymSocket();

            Assert.Throws <ArgumentOutOfRangeException>(() => socket.Connect("symitar", -1));
        }
Exemplo n.º 29
0
        public void Disconnect_ClosesClient()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);
            socket.Disconnect();
            tcpAdapterMock.Received().Close();
        }
Exemplo n.º 30
0
 public void Connect_ZeroPort_ThrowsArgumentOutOfRange()
 {
     var socket = new SymSocket();
     Assert.Throws<ArgumentOutOfRangeException>(() => socket.Connect("symitar", 0));
 }
Exemplo n.º 31
0
        public void Read_MultipleChunks_ConcatenatesCorrectly()
        {
            var chunk1 = Encoding.ASCII.GetBytes("doubl");
            var chunk2 = Encoding.ASCII.GetBytes("e data");

            var tcpAdapterMock = Substitute.For<ITcpAdapter>();
            tcpAdapterMock.Read().Returns(x => chunk1, x => chunk2, x => new byte[0]);

            var socket = new SymSocket(tcpAdapterMock);

            socket.Read().Should().Be("double data");
        }
Exemplo n.º 32
0
 public void ReadUntilMultiMatch_EmptyMatcherSet_ThrowsArugmentException()
 {
     Assert.Throws<ArgumentException>(
         () =>
             {
                 var socket = new SymSocket();
                 socket.WaitFor();
             }
         );
 }
Exemplo n.º 33
0
        public void Read_NoData_ReturnsEmptyString()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();
            tcpAdapterMock.Read().Returns(new byte[0]);

            var socket = new SymSocket(tcpAdapterMock);

            socket.Read().Should().Be("");
        }
Exemplo n.º 34
0
        public void Read_SingleChunk_ReturnsCorrectString()
        {
            var chunk = Encoding.ASCII.GetBytes("data");

            var tcpAdapterMock = Substitute.For<ITcpAdapter>();
            tcpAdapterMock.Read().Returns(x => chunk, x => new byte[0]);

            var socket = new SymSocket(tcpAdapterMock);

            socket.Read().Should().Be("data");
        }
Exemplo n.º 35
0
        public void Connect_ClientConnectException_HasErrorMessage()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();
            tcpAdapterMock
                .When(x => x.Connect("symitar", 23))
                .Do(x => { throw new InvalidOperationException(); });

            var socket = new SymSocket(tcpAdapterMock);
            socket.Connect("symitar", 23);
            socket.Error.Should().Contain("Unable to Connect to Server");
        }
Exemplo n.º 36
0
        public void Connect_ClientConnectException_ReturnsFalse()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();
            tcpAdapterMock
                .When(x => x.Connect("symitar", 23))
                .Do(x => { throw new InvalidOperationException(); });

            var socket = new SymSocket(tcpAdapterMock);
            bool result = socket.Connect("symitar", 23);
            result.Should().BeFalse();
        }
Exemplo n.º 37
0
        public void Connect_SuccessfulConnectionWithIpAddress_CallsHostNameConnectOnAdapter()
        {
            var tcpAdapterMock = Substitute.For<ITcpAdapter>();

            var socket = new SymSocket(tcpAdapterMock);
            socket.Connect("symitar", 23);
            tcpAdapterMock.Received().Connect("symitar", 23);
        }