Skip to content

Commit

Permalink
Fixed Unit Tests to accept new behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
A9G-Data-Droid committed May 15, 2018
1 parent aa3de48 commit 272dd94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
19 changes: 12 additions & 7 deletions PrimS.Telnet.CiTests/ByteStreamHandlerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace PrimS.Telnet.CiTests
using System.ComponentModel;

namespace PrimS.Telnet.CiTests
{
using System;
using System.Diagnostics;
Expand Down Expand Up @@ -205,13 +207,16 @@ public void WhenIacDoSgaByteStreamShouldReturnEmptyAndReplyIacWill()
ByteStreamHandler sut = new ByteStreamHandler(tcpByteStream, new CancellationTokenSource());

#if ASYNC
string response = await sut.ReadAsync(TimeSpan.FromMilliseconds(10));
string response = await sut.ReadAsync(TimeSpan.FromMilliseconds(10));
// A.CallTo(() => networkStream.WriteAsync(A<byte[]>.That.Contains((char)255), 0, 3, new CancellationToken())).MustHaveHappened();
A.CallTo(networkStream).Where(x => x.Method.Name == "WriteAsync").MustHaveHappened();
#else
string response = sut.Read(TimeSpan.FromMilliseconds(10));
A.CallTo(networkStream).Where(x => x.Method.Name == "Write").MustHaveHappened();
// A.CallTo(() => networkStream.Write(A<byte[]>.That.Contains((char)255), 0, 3)).MustHaveHappened();
#endif

response.Should().BeEmpty();
A.CallTo(() => networkStream.WriteByte((byte)Commands.InterpretAsCommand)).MustHaveHappened();
A.CallTo(() => networkStream.WriteByte((byte)Commands.Will)).MustHaveHappened();
}
}

Expand Down Expand Up @@ -244,14 +249,14 @@ public void WhenIacDo1ByteStreamShouldReturnEmptyAndReplyIacWont()
using (ByteStreamHandler sut = new ByteStreamHandler(tcpByteStream, new CancellationTokenSource()))
{
#if ASYNC
string response = await sut.ReadAsync(TimeSpan.FromMilliseconds(10));
string response = await sut.ReadAsync(TimeSpan.FromMilliseconds(10));
A.CallTo(networkStream).Where(x => x.Method.Name == "WriteAsync").MustHaveHappened();
#else
string response = sut.Read(TimeSpan.FromMilliseconds(10));
A.CallTo(networkStream).Where(x => x.Method.Name == "Write").MustHaveHappened();
#endif

response.Should().BeEmpty();
A.CallTo(() => networkStream.WriteByte((byte)Commands.InterpretAsCommand)).MustHaveHappened();
A.CallTo(() => networkStream.WriteByte((byte)Commands.Wont)).MustHaveHappened();
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions PrimS.Telnet.CiTests/TelnetServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,22 @@ private void SpinListen()
private void WaitFor(Socket handler, string awaitedResponse)
{
data = string.Empty;
while (true)
while (!this.IsResponseReceived(data, awaitedResponse))
{
ReceiveResponse(handler);
if (this.IsResponseReceived(data, awaitedResponse))
{
break;
}
}
}

private static void ReceiveResponse(Socket handler)
{
byte[] bytes = new byte[1024];
int bytesRec = handler.Receive(bytes);
data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
data += Encoding.ASCII.GetString(bytes, 0, bytesRec).Trim((char)255);
}

private bool IsResponseReceived(string currentResponse, string responseAwaited)
{
if (currentResponse == responseAwaited)
if (currentResponse.Contains(responseAwaited))
{
System.Diagnostics.Debug.Print("{0} response received", responseAwaited);
Console.WriteLine("{0} response received", responseAwaited);
Expand All @@ -132,4 +128,4 @@ private bool IsResponseReceived(string currentResponse, string responseAwaited)
}
}
}
}
}

0 comments on commit 272dd94

Please sign in to comment.