public void JoinGame_EncodingAndDecoding() { AgentInfo agentInfo = new AgentInfo(1001, AgentInfo.PossibleAgentType.BrilliantStudent) { ANumber = "A0001", FirstName = "Joe", LastName = "Jone" }; JoinGame jg1 = new JoinGame(10, agentInfo); Assert.AreEqual(10, jg1.GameId); Assert.AreSame(agentInfo, jg1.AgentInfo); ByteList bytes = new ByteList(); jg1.Encode(bytes); JoinGame jg2 = JoinGame.Create(bytes); Assert.AreEqual(jg1.GameId, jg2.GameId); bytes.Clear(); jg1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { jg2 = JoinGame.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); jg1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { jg2 = JoinGame.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void CreateEncodingSamples() { StreamWriter writer = new StreamWriter("MessageSamples.txt"); MessageNumber msgNumber = MessageNumber.Create(100, 120); MessageNumber conversationNumber = MessageNumber.Create(200, 240); AgentInfo agentInfo = new AgentInfo(10, AgentInfo.PossibleAgentType.BrilliantStudent, new Common.EndPoint("129.123.5.10:1234")) { AgentStatus = AgentInfo.PossibleAgentStatus.InGame, ANumber = "A00001", FirstName = "Joe", LastName = "Jones", Location = new FieldLocation(10, 20), Points = 100, Strength = 200, Speed = 1.2 }; AckNak ackNak = new AckNak(Reply.PossibleStatus.Success, agentInfo, "Test Message") { MessageNr = msgNumber, ConversationId = conversationNumber, IntResult = 99, Note = "Test Note" }; writer.WriteLine("AckNak"); writer.WriteLine("\tMessageNr={0}", ackNak.MessageNr.ToString()); writer.WriteLine("\tConversationId={0}", ackNak.ConversationId.ToString()); writer.WriteLine("\tReplyType={0}", ackNak.ReplyType); writer.WriteLine("\tAckNak Status={0}", ackNak.Status); writer.WriteLine("\tAgent Info:"); writer.WriteLine("\t\tId={0}", agentInfo.Id); writer.WriteLine("\t\tAgentStatus={0}", agentInfo.AgentStatus); writer.WriteLine("\t\tANumber={0}", agentInfo.ANumber); writer.WriteLine("\t\tFirstName={0}", agentInfo.FirstName); writer.WriteLine("\t\tLastName={0}", agentInfo.LastName); writer.WriteLine("\t\tLocation={0}", agentInfo.Location.ToString()); writer.WriteLine("\t\tPoints={0}", agentInfo.Points); writer.WriteLine("\t\tStrength={0}", agentInfo.Strength); writer.WriteLine("\t\tSpeed={0}", agentInfo.Speed); ByteList byteList = new ByteList(); ackNak.Encode(byteList); writer.WriteLine(""); writer.WriteLine("Encoding:"); writer.WriteLine(byteList.CreateLogString()); writer.WriteLine(""); writer.WriteLine("------------------------------------"); writer.WriteLine(""); JoinGame joinGame = new JoinGame(20, agentInfo) { MessageNr = msgNumber, ConversationId = conversationNumber, }; writer.WriteLine("JoinGame"); writer.WriteLine("\tMessageNr={0}", joinGame.MessageNr.ToString()); writer.WriteLine("\tConversationId={0}", joinGame.ConversationId.ToString()); writer.WriteLine("\tGameId={0}", joinGame.GameId); writer.WriteLine("\tAgent Info:"); writer.WriteLine("\t\tId={0}", agentInfo.Id); writer.WriteLine("\t\tAgentStatus={0}", agentInfo.AgentStatus); writer.WriteLine("\t\tANumber={0}", agentInfo.ANumber); writer.WriteLine("\t\tFirstName={0}", agentInfo.FirstName); writer.WriteLine("\t\tLastName={0}", agentInfo.LastName); writer.WriteLine("\t\tLocation={0}", agentInfo.Location.ToString()); writer.WriteLine("\t\tPoints={0}", agentInfo.Points); writer.WriteLine("\t\tStrength={0}", agentInfo.Strength); writer.WriteLine("\t\tSpeed={0}", agentInfo.Speed); byteList = new ByteList(); joinGame.Encode(byteList); writer.WriteLine(""); writer.WriteLine("Encoding:"); writer.WriteLine(byteList.CreateLogString()); writer.WriteLine(""); writer.WriteLine("------------------------------------"); writer.WriteLine(""); // TODO: All of the other message types }
public void JoinGame_TestConstructorsAndFactories() { JoinGame jg = new JoinGame(); Assert.AreEqual(0, jg.GameId); Assert.IsNull(jg.AgentInfo); AgentInfo agentInfo = new AgentInfo(1001, AgentInfo.PossibleAgentType.BrilliantStudent) { ANumber = "A0001", FirstName = "Joe", LastName = "Jone" }; jg = new JoinGame(10, agentInfo); Assert.AreEqual(10, jg.GameId); Assert.AreSame(agentInfo, jg.AgentInfo); ByteList bytes = new ByteList(); jg.Encode(bytes); Message msg = Message.Create(bytes); Assert.IsNotNull(msg); Assert.IsTrue(msg is JoinGame); JoinGame jg2 = msg as JoinGame; Assert.AreEqual(jg.GameId, jg2.GameId); }