public void MyTestInitialize() { _client = new TestablePNet(); _client.TestableHook.StartUpdateThread(); _client.OnRoomChange += s => _client.FinishedRoomChange(); PNetServer.OnPlayerConnected += player => player.ChangeRoom(_testRoom); _testRoom = Room.CreateRoom("test room"); _client.Connect(TestablePNet.GetTestConnectionConfig()); Thread.Sleep(250); _player = PNetServer.AllPlayers().First(f => f != null && f != Player.Server); }
public void TestConnecting() { //setup a default server ServerUtils.SetupDefaultServer(); ServerUtils.StartServerOnNewThread(); var client = new TestablePNet(); client.TestableHook.StartUpdateThread(); client.OnFailedToConnect += s => Assert.Fail("Failed to connect: {0}", s); //the client should connect and disconnect quickly client.Connect(TestablePNet.GetTestConnectionConfig()); Thread.Sleep(200); Assert.AreEqual(client.Status, NetConnectionStatus.Connected, "The client took longer than 200 ms to connect"); client.Disconnect(); Thread.Sleep(200); Assert.AreEqual(client.Status, NetConnectionStatus.Disconnected, "The client took longer than 200 ms to disconnect"); //some cleanup ServerUtils.TeardownServer(); }
public void TestRoomJoining() { _client.OnRoomChange += s => _client.FinishedRoomChange(); PNetServer.OnPlayerConnected += OnPlayerConnected; _client.Connect(TestablePNet.GetTestConnectionConfig()); Thread.Sleep(250); Assert.AreEqual(NetConnectionStatus.Connected, _client.Status, "Client did not connect in 250 ms"); Thread.Sleep(100); var tPlayer = PNetServer.AllPlayers()[1]; Assert.AreSame(_testRoom, tPlayer.CurrentRoom, "Client did not change to the room within 100 ms"); GameState.InvokeIfRequired(() => { tPlayer.ChangeRoom(_testRoom2); }); Thread.Sleep(100); Assert.AreSame(_testRoom2, tPlayer.CurrentRoom, "Client did not switch to room 2 within 100 ms"); GameState.InvokeIfRequired(() => { tPlayer.ChangeRoom(_testRoom); }); Thread.Sleep(100); Assert.AreSame(_testRoom, tPlayer.CurrentRoom, "Client did not change back to room within 100 ms"); }