public void UserApp_StartGameConversation_Test() { //--------------SET UP VARIABLES-------------------// RegistryData registryData = new RegistryData(); RegistryData.GameInfo gameInfo = new RegistryData.GameInfo(); TestAppWorker testAppWorker = new TestAppWorker(registryData); testAppWorker.StartTest(); var gameManager = new UdpCommunicator() { MinPort = 10000, MaxPort = 10999, Timeout = 1000, EnvelopeHandler = ProcessEnvelope1 }; gameManager.Start(); IPEndPoint registryEp = new IPEndPoint(IPAddress.Loopback, testAppWorker.commFacility.udpCommunicator.Port); IPEndPoint gameManagerEp = new IPEndPoint(IPAddress.Loopback, gameManager.Port); gameInfo.RemoteEndPoint = gameManagerEp; gameInfo.GameActive = false; Assert.IsTrue(registryData.AddGame(gameInfo)); StartGameMessage msg1 = new StartGameMessage(1); Envelope env1 = new Envelope(msg1, registryEp); //--------------TEST INITIAL SET UP AND SEND INITIAL MESSAGE-------------------// Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); Assert.IsFalse(gameInfo.GameActive); gameManager.Send(env1); Thread.Sleep(1000); //--------------TEST OUTCOME-------------------// Assert.AreNotSame(msg1, _lastIncomingEnvelope1); // Make sure received message isn't null Assert.IsNotNull(_lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1.message); // Make sure received message is AckMessage Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId); AckMessage msg2 = _lastIncomingEnvelope1.message as AckMessage; Assert.IsNotNull(msg2); Assert.IsTrue(gameInfo.GameActive); Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); //--------------CLOSE EVERYTHING-------------------// testAppWorker.StopTest(); gameManager.Stop(); }
public void UserApp_EndTurnConversation_Test() { TestAppWorker testAppWorker = new TestAppWorker(); testAppWorker.StartTest(); var fakeGameManager = new UdpCommunicator() { MinPort = 10000, MaxPort = 10999, Timeout = 1000, EnvelopeHandler = ProcessEnvelope1 }; fakeGameManager.Start(); IPEndPoint targetEndPoint = new IPEndPoint(IPAddress.Loopback, fakeGameManager.Port); Message msg1 = new EndTurnMessage(1, 6); Envelope env = new Envelope(msg1, targetEndPoint); Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); testAppWorker.commFacility.Process(env); Assert.IsNotNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); Thread.Sleep(100); Assert.AreNotSame(msg1, _lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1.message); Assert.AreEqual(msg1.msgId, _lastIncomingEnvelope1.message.msgId); Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId); }
public void UserApp_JoinGameConversation_Test() { TestAppWorker testAppWorker = new TestAppWorker(); testAppWorker.StartTest(); var fakeRegistry = new UdpCommunicator() { MinPort = 10000, MaxPort = 10999, Timeout = 1000, EnvelopeHandler = ProcessEnvelope1 }; fakeRegistry.Start(); IPEndPoint targetEndPoint = new IPEndPoint(IPAddress.Loopback, fakeRegistry.Port); Message msg1 = new RequestGameMessage(); Envelope env = new Envelope(msg1, targetEndPoint); Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); testAppWorker.commFacility.Process(env); Assert.IsNotNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); Thread.Sleep(100); Assert.AreNotSame(msg1, _lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1.message); Assert.AreEqual(msg1.msgId, _lastIncomingEnvelope1.message.msgId); Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId); RequestGameMessage msg2 = _lastIncomingEnvelope1.message as RequestGameMessage; Assert.IsNotNull(msg2); GameInfoMessage msg3 = new GameInfoMessage(msg1.convId, 1, 1, "GMAddress", "UAAddress"); Assert.AreNotSame((IPEndPoint)fakeRegistry._myUdpClient.Client.LocalEndPoint, _lastIncomingEnvelope1.remoteEndPoint); Envelope env2 = new Envelope(msg3, _lastIncomingEnvelope1.remoteEndPoint); fakeRegistry.Send(env2); Thread.Sleep(100); Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); fakeRegistry.Stop(); testAppWorker.StopTest(); }
public void Registry_JoinGameConversation_Test() { IPEndPoint registryEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 11000); RegistryData registryData = new RegistryData(); TestAppWorker testAppWorker = new TestAppWorker(registryData, registryEndPoint); testAppWorker.StartTest(); var comm1 = new UdpCommunicator() { MinPort = 10000, MaxPort = 10999, Timeout = 1000, EnvelopeHandler = ProcessEnvelope1 }; comm1.Start(); Message msg1 = new RequestGameMessage(); Envelope env = new Envelope(msg1, registryEndPoint); Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); Assert.IsNull(registryData.GetAvailableGameManager()); comm1.Send(env); Thread.Sleep(1000); /* * //The conversation happens to fast. After the sleep, the conv is already gone * Assert.IsNotNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); */ Assert.AreNotSame(msg1, _lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1.message); Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId); GameInfoMessage msg2 = _lastIncomingEnvelope1.message as GameInfoMessage; Assert.IsNotNull(msg2); Assert.IsNotNull(registryData.GetAvailableGameManager()); Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); //-------------STOPPING------------// testAppWorker.StopTest(); comm1.Stop(); }
public void UserApp_StartGameConversation_Test() { //--------------SET UP VARIABLES-------------------// UserInfo userInfo = new UserInfo() { PlayerId = 0, CurrentPlayerId = -1, AcceptUserInput = false }; TestAppWorker testAppWorker = new TestAppWorker(userInfo); testAppWorker.StartTest(); var gameManager = new UdpCommunicator() { MinPort = 10000, MaxPort = 10999, Timeout = 1000, EnvelopeHandler = ProcessEnvelope1 }; gameManager.Start(); IPEndPoint userAppEp = new IPEndPoint(IPAddress.Loopback, testAppWorker.commFacility.udpCommunicator.Port); testAppWorker.UserInfo.GameManagerEP = new IPEndPoint(IPAddress.Loopback, gameManager.Port); StartGameMessage msg1 = new StartGameMessage(1); Envelope env1 = new Envelope(msg1, userAppEp); //--------------TEST INITIAL SET UP AND SEND INITIAL MESSAGE-------------------// Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); gameManager.Send(env1); Thread.Sleep(1000); //--------------TEST OUTCOME-------------------// Assert.IsTrue(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId) is StartGameConversation); Assert.AreNotSame(msg1, _lastIncomingEnvelope1); // Make sure received message isn't null Assert.IsNotNull(_lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1.message); // Make sure received message is AckMessage Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId); AckMessage msg2 = _lastIncomingEnvelope1.message as AckMessage; Assert.IsNotNull(msg2); //--------------SEND START GAME STATE UPDATE MESSAGE-------------------// GameStateUpdateMessage msg3 = new GameStateUpdateMessage(msg1.convId, 1, 0, new short[4], new short[4], new short[84], 0, "TEST APP MOVE"); Envelope env2 = new Envelope(msg3, _lastIncomingEnvelope1.remoteEndPoint); _lastIncomingEnvelope1 = null; // User should not know it is their turn Assert.IsFalse(userInfo.IsTurn); gameManager.Send(env2); Thread.Sleep(1000); //--------------TEST OUTCOME-------------------// // User should know it is their turn Assert.IsTrue(userInfo.IsTurn); Assert.AreNotSame(msg1, _lastIncomingEnvelope1); // Make sure received message isn't null Assert.IsNotNull(_lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1.message); // Make sure received message is AckMessage Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId); AckMessage msg4 = _lastIncomingEnvelope1.message as AckMessage; Assert.IsNotNull(msg4); //--------------SEND FIRST PLAYER GO ACK MESSAGE-------------------// AckMessage msg5 = new AckMessage(msg1.convId, msg1.GameId); Envelope env3 = new Envelope(msg5, _lastIncomingEnvelope1.remoteEndPoint); _lastIncomingEnvelope1 = null; // Check user isn't able to input Assert.IsFalse(userInfo.AcceptUserInput); gameManager.Send(env3); Thread.Sleep(1000); //--------------TEST OUTCOME-------------------// // Check user is able to input Assert.IsTrue(userInfo.AcceptUserInput); // Check conversation ended Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); //--------------CLOSE EVERYTHING-------------------// testAppWorker.StopTest(); gameManager.Stop(); }
public void GameManager_StartGameConversation_Test() { //--------------SET UP VARIABLES-------------------// string[] args = { "Test Arguments" }; GameInfo gameInfo = new GameInfo(); TestAppWorker testAppWorker = new TestAppWorker(args, gameInfo); testAppWorker.StartTest(); var ua1 = new UdpCommunicator() { MinPort = 10000, MaxPort = 10999, Timeout = 1000, EnvelopeHandler = ProcessEnvelope1 }; var ua2 = new UdpCommunicator() { MinPort = 10000, MaxPort = 10999, Timeout = 1000, EnvelopeHandler = ProcessEnvelope2 }; var ua3 = new UdpCommunicator() { MinPort = 10000, MaxPort = 10999, Timeout = 1000, EnvelopeHandler = ProcessEnvelope3 }; var ua4 = new UdpCommunicator() { MinPort = 10000, MaxPort = 10999, Timeout = 1000, EnvelopeHandler = ProcessEnvelope4 }; var registry = new UdpCommunicator() { MinPort = 10000, MaxPort = 10999, Timeout = 1000, EnvelopeHandler = ProcessEnvelope5 }; ua1.Start(); ua2.Start(); ua3.Start(); ua4.Start(); registry.Start(); IPEndPoint ua1Ep = new IPEndPoint(IPAddress.Loopback, ua1.Port); IPEndPoint ua2Ep = new IPEndPoint(IPAddress.Loopback, ua2.Port); IPEndPoint ua3Ep = new IPEndPoint(IPAddress.Loopback, ua3.Port); IPEndPoint ua4Ep = new IPEndPoint(IPAddress.Loopback, ua4.Port); IPEndPoint registryEp = new IPEndPoint(IPAddress.Loopback, registry.Port); Assert.IsTrue(gameInfo.UserEndPoints.TryAdd(0, ua1Ep)); Assert.IsTrue(gameInfo.UserEndPoints.TryAdd(1, ua2Ep)); Assert.IsTrue(gameInfo.UserEndPoints.TryAdd(2, ua3Ep)); Assert.IsTrue(gameInfo.UserEndPoints.TryAdd(3, ua4Ep)); StartGameMessage msg1 = new StartGameMessage(1); Envelope env1 = new Envelope(msg1, registryEp); //--------------TEST INITIAL SET UP AND START CONVERSATION-------------------// Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); testAppWorker.commFacility.Process(env1); Thread.Sleep(1000); //--------------TEST OUTCOME-------------------// Assert.IsTrue(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId) is StartGameConversation); Assert.AreNotSame(msg1, _lastIncomingEnvelope1); Assert.AreNotSame(msg1, _lastIncomingEnvelope2); Assert.AreNotSame(msg1, _lastIncomingEnvelope3); Assert.AreNotSame(msg1, _lastIncomingEnvelope4); Assert.AreNotSame(msg1, _lastIncomingEnvelope5); // Make sure received messages aren't null Assert.IsNotNull(_lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1.message); Assert.IsNotNull(_lastIncomingEnvelope2); Assert.IsNotNull(_lastIncomingEnvelope2.message); Assert.IsNotNull(_lastIncomingEnvelope3); Assert.IsNotNull(_lastIncomingEnvelope3.message); Assert.IsNotNull(_lastIncomingEnvelope4); Assert.IsNotNull(_lastIncomingEnvelope4.message); Assert.IsNotNull(_lastIncomingEnvelope5); Assert.IsNotNull(_lastIncomingEnvelope5.message); // Make sure received messages are StartGameMessages Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId); StartGameMessage msg2 = _lastIncomingEnvelope1.message as StartGameMessage; Assert.IsNotNull(msg2); msg2 = _lastIncomingEnvelope2.message as StartGameMessage; Assert.IsNotNull(msg2); msg2 = _lastIncomingEnvelope3.message as StartGameMessage; Assert.IsNotNull(msg2); msg2 = _lastIncomingEnvelope4.message as StartGameMessage; Assert.IsNotNull(msg2); msg2 = _lastIncomingEnvelope5.message as StartGameMessage; Assert.IsNotNull(msg2); //--------------SEND START ACK MESSAGE-------------------// AckMessage msg3 = new AckMessage(msg1.convId, msg1.GameId); Envelope env2 = new Envelope(msg3, _lastIncomingEnvelope1.remoteEndPoint); _lastIncomingEnvelope1 = null; _lastIncomingEnvelope2 = null; _lastIncomingEnvelope3 = null; _lastIncomingEnvelope4 = null; _lastIncomingEnvelope5 = null; ua1.Send(env2); ua2.Send(env2); ua3.Send(env2); ua4.Send(env2); registry.Send(env2); Thread.Sleep(1000); //--------------TEST OUTCOME-------------------// Assert.AreNotSame(msg1, _lastIncomingEnvelope1); Assert.AreNotSame(msg1, _lastIncomingEnvelope2); Assert.AreNotSame(msg1, _lastIncomingEnvelope3); Assert.AreNotSame(msg1, _lastIncomingEnvelope4); Assert.AreNotSame(msg1, _lastIncomingEnvelope5); // Make sure received messages aren't null, except registry's Assert.IsNotNull(_lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1.message); Assert.IsNotNull(_lastIncomingEnvelope2); Assert.IsNotNull(_lastIncomingEnvelope2.message); Assert.IsNotNull(_lastIncomingEnvelope3); Assert.IsNotNull(_lastIncomingEnvelope3.message); Assert.IsNotNull(_lastIncomingEnvelope4); Assert.IsNotNull(_lastIncomingEnvelope4.message); Assert.IsNull(_lastIncomingEnvelope5); // Make sure received messages are StartGameMessages Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId); GameStateUpdateMessage msg4; msg4 = _lastIncomingEnvelope1.message as GameStateUpdateMessage; Assert.IsNotNull(msg4); msg4 = _lastIncomingEnvelope2.message as GameStateUpdateMessage; Assert.IsNotNull(msg4); msg4 = _lastIncomingEnvelope3.message as GameStateUpdateMessage; Assert.IsNotNull(msg4); msg4 = _lastIncomingEnvelope4.message as GameStateUpdateMessage; Assert.IsNotNull(msg4); //--------------SEND UPDATE ACK MESSAGE-------------------// AckMessage msg5 = new AckMessage(msg1.convId, msg1.GameId); Envelope env3 = new Envelope(msg5, _lastIncomingEnvelope1.remoteEndPoint); _lastIncomingEnvelope1 = null; _lastIncomingEnvelope2 = null; _lastIncomingEnvelope3 = null; _lastIncomingEnvelope4 = null; _lastIncomingEnvelope5 = null; ua1.Send(env3); ua2.Send(env3); ua3.Send(env3); ua4.Send(env3); Thread.Sleep(1000); //--------------TEST OUTCOME-------------------// Assert.AreNotSame(msg1, _lastIncomingEnvelope1); Assert.AreNotSame(msg1, _lastIncomingEnvelope2); Assert.AreNotSame(msg1, _lastIncomingEnvelope3); Assert.AreNotSame(msg1, _lastIncomingEnvelope4); Assert.AreNotSame(msg1, _lastIncomingEnvelope5); // Make sure all received messages are null except ua1's Assert.IsNotNull(_lastIncomingEnvelope1); Assert.IsNotNull(_lastIncomingEnvelope1.message); Assert.IsNull(_lastIncomingEnvelope2); Assert.IsNull(_lastIncomingEnvelope3); Assert.IsNull(_lastIncomingEnvelope4); Assert.IsNull(_lastIncomingEnvelope5); // Check conversation ended Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId)); //--------------CLOSE EVERYTHING-------------------// testAppWorker.StopTest(); ua1.Stop(); ua2.Stop(); ua3.Stop(); ua4.Stop(); registry.Stop(); }