public void TelnetServerShouldTerminateAndReleaseDebuggingContext() { TelnetServer server; using (server = new TelnetServer()) { } server.IsListening.Should().BeFalse(); }
public void ShouldConnect() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); } } }
public void ReceiveTimeoutShouldBeDefaultTo0() { using (TelnetServer server = new TelnetServer()) { using (TcpByteStream sut = new TcpByteStream(server.IPAddress.ToString(), server.Port)) { sut.ReceiveTimeout.Should().Be(0); } } }
public void TcpByteStreamShouldTerminateAndReleaseDebuggingContext() { using (TelnetServer server = new TelnetServer()) { using (TcpByteStream sut = new TcpByteStream(server.IPAddress.ToString(), server.Port)) { sut.Should().NotBeNull(); } } }
public void ShouldConnect() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port)) { Assert.AreEqual(client.IsConnected, true); } } }
public void ShouldTerminateWithAColon() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port)) { Assert.AreEqual(client.IsConnected, true); Assert.IsTrue(client.TerminatedRead(":", TimeSpan.FromMilliseconds(TimeoutMs)).EndsWith(":")); } } }
public void TcpByteStreamShouldConstruct() { using (TelnetServer server = new TelnetServer()) { TcpByteStream sut = null; Action act = () => sut = new TcpByteStream(server.IPAddress.ToString(), server.Port); act.ShouldNotThrow(); sut.Dispose(); } }
public void ShouldTerminateWithAColon() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); client.TerminatedRead(":", TimeSpan.FromMilliseconds(TimeoutMs)).Should().EndWith(":"); } } }
public void ShouldLogin() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); (client.TryLogin("username", "password", TimeoutMs)).Should().Be(true); } } }
public async Task ShouldLogin() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); (await client.TryLoginAsync("username", "password", timeoutMs).ConfigureAwait(false)).Should().Be(true); } } }
public void ShouldLogin() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port)) { Assert.AreEqual(client.IsConnected, true); Assert.AreEqual((client.TryLogin("username", "password", TimeoutMs)), true); } } }
public void ShouldBePromptingForAccount() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port)) { Assert.AreEqual(client.IsConnected, true); string s = client.TerminatedRead("Account:", TimeSpan.FromMilliseconds(TimeoutMs)); Assert.IsTrue(s.Contains("Account:")); } } }
public void ShouldBePromptingForAccount() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); string s = client.TerminatedRead("Account:", TimeSpan.FromMilliseconds(TimeoutMs)); s.Should().Contain("Account:"); } } }
public void ShouldRegexMatchWithAColon() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port)) { Assert.AreEqual(client.IsConnected, true); Regex regex = new Regex(".*:\r?$", RegexOptions.Multiline); Assert.IsTrue(client.TerminatedRead(regex, TimeSpan.FromMilliseconds(TimeoutMs)).EndsWith(":")); } } }
public async Task ShouldBePromptingForAccount() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); string s = await client.TerminatedReadAsync("Account:", TimeSpan.FromMilliseconds(TimeoutMs)); s.Should().Contain("Account:"); } } }
public void WriteByteShouldNotThrow() { byte writtenByte = new byte(); using (TelnetServer server = new TelnetServer()) { using (TcpByteStream sut = new TcpByteStream(server.IPAddress.ToString(), server.Port)) { Action act = () => sut.WriteByte(writtenByte); act.ShouldNotThrow(); } } }
public async Task ShouldBePromptingForAccount() { using (var server = new TelnetServer()) { using (var client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); var s = await client.TerminatedReadAsync("Account:", TimeSpan.FromMilliseconds(timeoutMs)).ConfigureAwait(false); s.Should().Contain("Account:"); } } }
public void ShouldRegexMatchPromptingForAccount() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port)) { Assert.AreEqual(client.IsConnected, true); Regex regex = new Regex(".*Account:\r?$", RegexOptions.Multiline); string s = client.TerminatedRead(regex, TimeSpan.FromMilliseconds(TimeoutMs)); Assert.IsTrue(s.Contains("Account:")); } } }
public async Task ShouldTerminateWithAColon() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); string s = await client.TerminatedReadAsync(":", TimeSpan.FromMilliseconds(timeoutMs)).ConfigureAwait(false); s.Should().EndWith(":"); } } }
public void ShouldBePromptingForPassword() { using (var server = new TelnetServer()) { using (var client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); var s = client.TerminatedRead("Account:", TimeSpan.FromMilliseconds(timeoutMs)); s.Should().Contain("Account:"); client.WriteLine("username"); s = client.TerminatedRead("Password:", TimeSpan.FromMilliseconds(timeoutMs)); } } }
public void ShouldBePromptingForPassword() { using (var server = new TelnetServer()) { using (var client = new Client(server.IPAddress.ToString(), server.Port)) { Assert.AreEqual(client.IsConnected, true); var s = client.TerminatedRead("Account:", TimeSpan.FromMilliseconds(timeoutMs)); Assert.IsTrue(s.Contains("Account:")); client.WriteLine("username"); s = client.TerminatedRead("Password:", TimeSpan.FromMilliseconds(timeoutMs)); } } }
public void ShouldBePromptingForPassword() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); string s = client.TerminatedRead("Account:", TimeSpan.FromMilliseconds(TimeoutMs)); s.Should().Contain("Account:"); client.WriteLine("username"); s = client.TerminatedRead("Password:", TimeSpan.FromMilliseconds(TimeoutMs)); } } }
public void ShouldPromptForInput() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port)) { Assert.AreEqual(client.IsConnected, true); client.TerminatedRead("Account:", TimeSpan.FromMilliseconds(TimeoutMs)); client.WriteLine("username"); client.TerminatedRead("Password:"******"password"); client.TerminatedRead(">", TimeSpan.FromMilliseconds(TimeoutMs)); } } }
public void ShouldRespondWithWan2Info() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); (client.TryLogin("username", "password", TimeoutMs)).Should().Be(true); client.WriteLine("show statistic wan2"); string s = client.TerminatedRead(">", TimeSpan.FromMilliseconds(TimeoutMs)); s.Should().Contain(">"); s.Should().Contain("WAN2"); } } }
public void ShouldPromptForInput() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); string s = client.TerminatedRead("Account:", TimeSpan.FromMilliseconds(TimeoutMs)); client.WriteLine("username"); s = client.TerminatedRead("Password:"******"password"); s = client.TerminatedRead(">", TimeSpan.FromMilliseconds(TimeoutMs)); } } }
public void ShouldRespondWithWan2Info() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port)) { Assert.AreEqual(client.IsConnected, true); Assert.AreEqual(client.TryLogin("username", "password", TimeoutMs), true); client.WriteLine("show statistic wan2"); string s = client.TerminatedRead(">", TimeSpan.FromMilliseconds(TimeoutMs)); Assert.IsTrue(s.Contains(">")); Assert.IsTrue(s.Contains("WAN2")); } } }
public async Task ShouldPromptForInput() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); string s = await client.TerminatedReadAsync("Account:", TimeSpan.FromMilliseconds(TimeoutMs)); client.WriteLine("username"); s = await client.TerminatedReadAsync("Password:"******"password"); s = await client.TerminatedReadAsync(">", TimeSpan.FromMilliseconds(TimeoutMs)); } } }
public async Task ShouldRespondWithWan2InfoRegexTerminated() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); (await client.TryLoginAsync("username", "password", 1500).ConfigureAwait(false)).Should().Be(true); await client.WriteLine("show statistic wan2").ConfigureAwait(false); string s = await client.TerminatedReadAsync(new Regex(".*>$"), TimeSpan.FromMilliseconds(timeoutMs)).ConfigureAwait(false); s.Should().Contain(">"); s.Should().Contain("WAN2"); } } }
public async Task ShouldPromptForInput() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); await client.TerminatedReadAsync("Account:", TimeSpan.FromMilliseconds(timeoutMs)).ConfigureAwait(false); await client.WriteLine("username").ConfigureAwait(false); await client.TerminatedReadAsync("Password:"******"password").ConfigureAwait(false); await client.TerminatedReadAsync(">", TimeSpan.FromMilliseconds(timeoutMs)).ConfigureAwait(false); } } }
public async Task ReadmeExample() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); (await client.TryLoginAsync("username", "password", TimeoutMs)).Should().Be(true); client.WriteLine("show statistic wan2"); string s = await client.TerminatedReadAsync(">", TimeSpan.FromMilliseconds(TimeoutMs)); s.Should().Contain(">"); s.Should().Contain("WAN2"); System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex("(?!WAN2 total TX: )([0-9.]*)(?! GB ,RX: )([0-9.]*)(?= GB)"); regEx.IsMatch(s).Should().Be(true); MatchCollection matches = regEx.Matches(s); decimal tx = decimal.Parse(matches[0].Value); decimal rx = decimal.Parse(matches[1].Value); (tx + rx).Should().BeLessThan(50); } } }
public void ShouldBePromptingForPassword() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port)) { Assert.AreEqual(client.IsConnected, true); string s = client.TerminatedRead("Account:", TimeSpan.FromMilliseconds(TimeoutMs)); Assert.IsTrue(s.Contains("Account:")); client.WriteLine("username"); s = client.TerminatedRead("Password:", TimeSpan.FromMilliseconds(TimeoutMs)); } } }
public async Task ShouldRespondWithWan2Info() { using (TelnetServer server = new TelnetServer()) { using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken())) { client.IsConnected.Should().Be(true); (await client.TryLoginAsync("username", "password", 1500)).Should().Be(true); client.WriteLine("show statistic wan2"); string s = await client.TerminatedReadAsync(">", TimeSpan.FromMilliseconds(TimeoutMs)); s.Should().Contain(">"); s.Should().Contain("WAN2"); } } }