public void HandlePacketTest() { var TestPacketHelperInstance = new TestPacketHelper( Packet.PacketType.RemoveAllElements, new RemoveAllElementsHandler() ); var Index = TestPacketHelperInstance.DescendingIndex; Index.UpdateUserScore(1000, 10000, 300); Index.UpdateUserScore(1001, 10000, 250); Index.UpdateUserScore(1002, 10000, 200); TestPacketHelperInstance.Handle((Stream) => { Stream.WriteStruct(new RemoveAllElementsHandler.RequestStruct() { RankingIndexId = Index.IndexId, }); }); Assert.AreEqual( "", Index.GetRange(0, 10000).ToStringArray("\r\n") ); }
public void HandlePacketTest() { var TestPacketHelperInstance = new TestPacketHelper( Packet.PacketType.GetElementOffset, new GetElementOffsetHandler() ); var DescendingIndex = TestPacketHelperInstance.DescendingIndex; DescendingIndex.UpdateUserScore(UserId: 1001, ScoreTimeStamp: 10000, ScoreValue: 200); DescendingIndex.UpdateUserScore(UserId: 1002, ScoreTimeStamp: 10000, ScoreValue: 300); DescendingIndex.UpdateUserScore(UserId: 1000, ScoreTimeStamp: 10000, ScoreValue: 100); DescendingIndex.UpdateUserScore(UserId: 1003, ScoreTimeStamp: 10000, ScoreValue: 50); TestPacketHelperInstance.Handle((Stream) => { var BinaryWriter = new BinaryWriter(Stream); BinaryWriter.Write((int)DescendingIndex.IndexId); BinaryWriter.Write((uint)1000); }); Assert.AreEqual( "Packet(Type=GetElementOffset, Data=02000000)", TestPacketHelperInstance.PacketToSend.ToString() ); }
public void HandlePacketTest() { var TestPacketHelperInstance = new TestPacketHelper( Packet.PacketType.ListElements, new ListElementsHandler() ); var Ranking = TestPacketHelperInstance.DescendingIndex; Ranking.UpdateUserScore(1000, 10000, 250); Ranking.UpdateUserScore(1001, 10000, 200); Ranking.UpdateUserScore(1002, 10000, 150); Ranking.UpdateUserScore(1003, 10000, 100); Ranking.UpdateUserScore(1004, 10000, 50); TestPacketHelperInstance.Handle((Stream) => { Stream.WriteStruct(new ListElementsHandler.RequestStruct() { RankingIndexId = TestPacketHelperInstance.DescendingIndex.IndexId, Offset = 2, Count = 2, }); }); Assert.AreEqual( "ResponseEntryStruct(Position=2,UserId=1002,ScoreValue=150,ScoreTimeStamp=10000)" + "ResponseEntryStruct(Position=3,UserId=1003,ScoreValue=100,ScoreTimeStamp=10000)" + "", TestPacketHelperInstance.PacketToSend.Stream.ReadStructVectorUntilTheEndOfStream<ListElementsHandler.ResponseEntryStruct>().ToStringArray("") ); }
public void HandlePacketTest() { var TestPacketHelperInstance = new TestPacketHelper( Packet.PacketType.GetVersion, new GetVersionHandler() ); TestPacketHelperInstance.Handle((Stream) => { }); Assert.AreEqual( new ServerManager().Version.ToString(), TestPacketHelperInstance.PacketToSend.Stream.ReadStruct<ServerManager.VersionStruct>().ToString() ); }
public void HandlePacketTest() { var TestPacketHelperInstance = new TestPacketHelper( Packet.PacketType.Ping, new PingHandler() ); TestPacketHelperInstance.Handle((Stream) => { }); Assert.AreEqual( "Packet(Type=Ping, Data=)", TestPacketHelperInstance.PacketToSend.ToString() ); }
public void HandlePacketTest() { var TestPacketHelperInstance = new TestPacketHelper( Packet.PacketType.GetRankingInfo, new GetRankingInfoHandler() ); var DescendingIndex = TestPacketHelperInstance.DescendingIndex; DescendingIndex.UpdateUserScore(1, 1000, 9999); TestPacketHelperInstance.Handle((Stream) => { new BinaryWriter(Stream).Write((int)DescendingIndex.IndexId); }); Assert.AreEqual( "ResponseStruct(Result=0,Length=1,Direction=Descending,TopScore=9999,BottomScore=9999,MaxElements=-1,TreeHeight=-1)", TestPacketHelperInstance.PacketToSend.Stream.ReadStruct<GetRankingInfoHandler.ResponseStruct>().ToStringDefault() ); }
public void HandlePacketTest() { var TestPacketHelperInstance = new TestPacketHelper( Packet.PacketType.RemoveElements, new RemoveElementsHandler() ); var Index = TestPacketHelperInstance.DescendingIndex; Index.UpdateUserScore(1000, 10000, 300); Index.UpdateUserScore(1001, 10000, 250); Index.UpdateUserScore(1002, 10000, 200); Index.UpdateUserScore(1003, 10000, 150); Index.UpdateUserScore(1004, 10000, 100); TestPacketHelperInstance.Handle((Stream) => { Stream.WriteStruct(new RemoveElementsHandler.RequestHeaderStruct() { RankingIndexId = Index.IndexId, }); Stream.WriteStruct(new RemoveElementsHandler.RequestEntryStruct() { UserId = 1001, }); Stream.WriteStruct(new RemoveElementsHandler.RequestEntryStruct() { UserId = 1003, }); }); Assert.AreEqual( "User(UserId:1000, ScoreTimeStamp:10000, ScoreValue:300)\r\n" + "User(UserId:1002, ScoreTimeStamp:10000, ScoreValue:200)\r\n" + "User(UserId:1004, ScoreTimeStamp:10000, ScoreValue:100)" + "", Index.GetRange(0, 10000).ToStringArray("\r\n") ); }
public void HandlePacketTest() { var TestPacketHelperInstance = new TestPacketHelper( Packet.PacketType.SetElements, new SetElementsHandler() ); var TestIndex = TestPacketHelperInstance.DescendingIndex; TestPacketHelperInstance.Handle((Stream) => { Stream.WriteStruct(new SetElementsHandler.RequestHeaderStruct() { RankingId = TestIndex.IndexId, }); Stream.WriteStruct(new SetElementsHandler.RequestEntryStruct() { UserId = 0, ScoreValue = 100, ScoreTimeStamp = 1000, }); Stream.WriteStruct(new SetElementsHandler.RequestEntryStruct() { UserId = 1, ScoreValue = 150, ScoreTimeStamp = 1001, }); }); Assert.AreEqual( "User(UserId:1, ScoreTimeStamp:1001, ScoreValue:150)" + "User(UserId:0, ScoreTimeStamp:1000, ScoreValue:100)" + "", TestIndex.GetRange(0, 100).ToStringArray("") ); }