Created
October 28, 2017 22:28
-
-
Save HurricanKai/93e1f37764f0ecee0893729e9c968aa4 to your computer and use it in GitHub Desktop.
UnitTest Connection Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using Lib; | |
using System.Threading; | |
namespace Tests | |
{ | |
[TestClass] | |
public class ConnectionTests | |
{ | |
public Server listener; | |
public Client client; | |
private bool received; | |
private int lastreceived; | |
[TestMethod] | |
public void SendInteger() | |
{ | |
listener = new Server(25565); | |
listener.Receive += Listener_Receive; | |
int send = (int)new Random().NextDouble(); | |
client = new Client(25565); | |
client.Send(send); | |
int trys = 0; | |
while (!received) | |
{ | |
if (trys > 10) | |
{ | |
Assert.Fail(); | |
return; | |
} | |
Thread.Sleep(1000); | |
trys++; | |
} | |
Assert.IsTrue(lastreceived == send); | |
} | |
private void Listener_Receive(object sender, IntEventArgs e) | |
{ | |
received = true; | |
lastreceived = e.integer; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment