public static List <string> WaitForPackets(FakeNetworkClient client, string lastPacketHeader, int timeout = 5) { DateTime startTime = DateTime.Now; List <string> packets = new List <string>(); while (true) { if (client.SentPackets.Count > 0) { string packet = client.SentPackets.Dequeue(); if (packet != null) { packets.Add(packet); if (packet.StartsWith(lastPacketHeader)) { return(packets); } } } if (startTime.AddSeconds(timeout) <= DateTime.Now) { return(packets); // timing out } } }
public static List <string> WaitForPackets(FakeNetworkClient client, int amount) { DateTime startTime = DateTime.Now; int receivedPackets = 0; List <string> packets = new List <string>(); while (receivedPackets < amount) { if (client.SentPackets.Count > 0) { packets.Add(client.SentPackets.Dequeue()); receivedPackets++; } // exit token if (startTime.AddSeconds(10) < DateTime.Now) { Assert.Fail($"Timed out while waiting for {amount} Packets"); return(new List <string>()); } } return(packets); }
public void GroupTest() { // login, create character, start game FakeNetworkClient clientA = HandlerTestHelper.InitializeTestEnvironment(); FakeNetworkClient clientB = HandlerTestHelper.CreateFakeNetworkClient(); Thread.Sleep(1000); // client A asks client B for group PJoinPacket pjoinPacketRequest = new PJoinPacket() { CharacterId = clientB.Session.Character.CharacterId, RequestType = GroupRequestType.Invited }; clientA.ReceivePacket(pjoinPacketRequest); HandlerTestHelper.WaitForPackets(clientA, 1); // client B accepts group request PJoinPacket pjoinPacketAccept = new PJoinPacket() { CharacterId = clientA.Session.Character.CharacterId, RequestType = GroupRequestType.Accepted }; clientB.ReceivePacket(pjoinPacketAccept); HandlerTestHelper.WaitForPackets(clientA, 1); // check if group has been created successfully Assert.IsNotNull(clientA.Session.Character.Group); Assert.IsNotNull(clientB.Session.Character.Group); Assert.AreEqual(2, clientA.Session.Character.Group.CharacterCount); }
public void SessionManagerTest() { System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US"); //initialize Logger Logger.InitializeLogger(LogManager.GetLogger(typeof(CoreTest))); //initialilize maps ServerManager.Initialize(); //register mappings for items DAOFactory.InventoryDAO.RegisterMapping(typeof(SpecialistInstance)); DAOFactory.InventoryDAO.RegisterMapping(typeof(WearableInstance)); DAOFactory.InventoryDAO.RegisterMapping(typeof(UsableInstance)); DAOFactory.InventoryDAO.InitializeMapper(typeof(ItemInstance)); //initialize PacketSerialization PacketFactory.Initialize <WalkPacket>(); //initialize new manager SessionManager manager = new SessionManager(typeof(CharacterScreenPacketHandler), true); FakeNetworkClient client = new FakeNetworkClient(); manager.AddSession(client); }
// [Test] public void InitializeTestEnvironmentTest() { // login, create character, start game FakeNetworkClient client = HandlerTestHelper.InitializeTestEnvironment(); HandlerTestHelper.ShutdownTestingEnvironment(); Assert.Pass(); }
public static string WaitForPacket(FakeNetworkClient client) { while (true) { if (client.SentPackets.Count > 0) { return(client.SentPackets.Dequeue()); } } }
public static string WaitForPacket(FakeNetworkClient client) { while (true) { if (client.SentPackets.Count > 0) { string packet = client.SentPackets.Dequeue(); Debug.WriteLine($"Dequeued {packet}"); return(packet); } } }
public static string WaitForPacket(FakeNetworkClient client, string packetHeader) { while (true) { if (client.SentPackets.Count > 0) { string packet = client.SentPackets.Dequeue(); if (packet != null && packet.StartsWith(packetHeader)) { return(packet); } } } }
public static FakeNetworkClient CreateFakeNetworkClient() { FakeNetworkClient client = new FakeNetworkClient(); _sessionManager.AddSession(client); long id = ServerManager.RandomNumber(0, 999999); AccountDTO account = new AccountDTO { AccountId = id, Authority = AuthorityType.Admin, LastSession = 12345, Name = "test" + id, Password = "******" }; DAOFactory.AccountDAO.InsertOrUpdate(ref account); // register for account login ServerCommunicationClient.Instance.HubProxy.Invoke("RegisterAccountLogin", account.Name, 12345); // OpenNosEntryPoint -> LoadCharacterList client.ReceivePacket("12345"); client.ReceivePacket(account.Name); client.ReceivePacket("test"); string clistStart = WaitForPacket(client); string clistEnd = WaitForPacket(client); // creation of character client.ReceivePacket($"Char_NEW {account.Name} 2 1 0 9"); List <string> clistAfterCreate = WaitForPackets(client, 3); CListPacket cListPacket = PacketFactory.Deserialize <CListPacket>(clistAfterCreate[1]); // select character client.ReceivePacket($"select {cListPacket.Slot}"); string okPacket = WaitForPacket(client); // start game client.ReceivePacket("game_start"); List <string> gameStartPacketsFirstPart = WaitForPackets(client, "p_clear"); List <string> gameStartPacketsSecondPart = WaitForPackets(client, "p_clear"); // wait 100 milliseconds to be sure initialization has been finished Thread.Sleep(100); return(client); }
public static List <string> WaitForPackets(FakeNetworkClient client, int amount) { int receivedPackets = 0; List <string> packets = new List <string>(); while (receivedPackets < amount) { if (client.SentPackets.Count > 0) { packets.Add(client.SentPackets.Dequeue()); receivedPackets++; } } return(packets); }
public void TestCharacterOption() { // login, create character, start game FakeNetworkClient client = HandlerTestHelper.InitializeTestEnvironment(); CharacterOptionPacket optionPacket = new CharacterOptionPacket { IsActive = false, Option = CharacterOption.FamilyRequestBlocked }; // check family request client.ReceivePacket(optionPacket); string msgPacket = HandlerTestHelper.WaitForPacket(client, "msg"); Assert.IsTrue(client.Session.Character.FamilyRequestBlocked); HandlerTestHelper.ShutdownTestingEnvironment(); Assert.Pass(); }
public static string WaitForPacket(FakeNetworkClient client) { DateTime startTime = DateTime.Now; while (true) { if (client.SentPackets.Count > 0) { string packet = client.SentPackets.Dequeue(); Debug.WriteLine($"Dequeued {packet}"); return(packet); } // exit token if (startTime.AddSeconds(10) < DateTime.Now) { Assert.Fail($"Timed out while waiting for a Packet."); return(string.Empty); } } }
public void TestWalkMove() { // login, create character, start game FakeNetworkClient client = HandlerTestHelper.InitializeTestEnvironment(); WalkPacket walkPacket = new WalkPacket { Speed = 11, XCoordinate = 89, YCoordinate = 126 }; // send walkpacket to client client.ReceivePacket(walkPacket); string mvPacket = HandlerTestHelper.WaitForPacket(client, "mv"); MovePacket movePacket = PacketFactory.Deserialize <MovePacket>(mvPacket); Assert.AreEqual(walkPacket.XCoordinate, movePacket.PositionX); Assert.AreEqual(walkPacket.YCoordinate, movePacket.PositionY); Assert.AreEqual(walkPacket.Speed, movePacket.Speed); HandlerTestHelper.ShutdownTestingEnvironment(); Assert.Pass(); }
public static FakeNetworkClient InitializeTestEnvironment() { System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US"); // initialize Logger Logger.InitializeLogger(LogManager.GetLogger(typeof(BasicPacketHandlerTest))); // create server entities (this values would have been imported) CreateServerItems(); CreateServerMaps(); CreateServerSkills(); // initialize servermanager ServerManager.Initialize(); // initialize WCF ServiceFactory.Instance.Initialize(); // register mappings for items DAOFactory.InventoryDAO.RegisterMapping(typeof(SpecialistInstance)); DAOFactory.InventoryDAO.RegisterMapping(typeof(WearableInstance)); DAOFactory.InventoryDAO.RegisterMapping(typeof(UsableInstance)); DAOFactory.InventoryDAO.InitializeMapper(typeof(ItemInstance)); // initialize PacketSerialization PacketFactory.Initialize <WalkPacket>(); // initialize new manager _sessionManager = new NetworkManager <TestEncryption>("127.0.0.1", 1234, typeof(CharacterScreenPacketHandler), typeof(TestEncryption), true); FakeNetworkClient client = new FakeNetworkClient(); _sessionManager.AddSession(client); AccountDTO account = new AccountDTO() { AccountId = 1, Authority = AuthorityType.Admin, LastSession = 12345, Name = "test", Password = "******" }; DAOFactory.AccountDAO.InsertOrUpdate(ref account); // register for account login ServiceFactory.Instance.CommunicationService.RegisterAccountLogin("test", 12345); // OpenNosEntryPoint -> LoadCharacterList client.ReceivePacket("12345"); client.ReceivePacket("test"); client.ReceivePacket("test"); string clistStart = WaitForPacket(client); string clistEnd = WaitForPacket(client); // creation of character client.ReceivePacket("Char_NEW Test 2 1 0 9"); List <string> clistAfterCreate = WaitForPackets(client, 3); CListPacket cListPacket = PacketFactory.Serialize <CListPacket>(clistAfterCreate[1]); // select character client.ReceivePacket($"select {cListPacket.Slot}"); string okPacket = WaitForPacket(client); // start game client.ReceivePacket("game_start"); List <string> gameStartPacketsFirstPart = WaitForPackets(client, "p_clear"); List <string> gameStartPacketsSecondPart = WaitForPackets(client, "p_clear"); return(client); }