private void CanEncode(int iNumberOfEntries) { // Add entries to pending RailPackedListOutgoing <Foo> list = new RailPackedListOutgoing <Foo>(); for (int i = 0; i < iNumberOfEntries; ++i) { list.AddPending(poolMock.Object.Allocate()); } Assert.Equal(iNumberOfEntries, elementsCreated); poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries)); poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Never); // Encode RailBitBuffer buffer = new RailBitBuffer(); list.Encode( buffer, RailConfig.PACKCAP_COMMANDS, RailConfig.MAXSIZE_COMMANDUPDATE, (foo, buf) => foo.WriteData(buf)); Assert.False(buffer.Empty); poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries)); poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Never); Assert.Equal(iNumberOfEntries, list.Sent.Count()); // Clear the list. This should deallocate all sent objects. list.Clear(); poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries)); poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Exactly(iNumberOfEntries)); }
private void CanDecode(int iNumberOfEntries) { // Add entries to pending RailPackedListOutgoing <Foo> list = new RailPackedListOutgoing <Foo>(); for (int i = 0; i < iNumberOfEntries; ++i) { list.AddPending(poolMock.Object.Allocate()); } Assert.Equal(iNumberOfEntries, elementsCreated); poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries)); poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Never); // Encode RailBitBuffer buffer = new RailBitBuffer(); list.Encode( buffer, RailConfig.PACKCAP_COMMANDS, RailConfig.MAXSIZE_COMMANDUPDATE, (foo, buf) => foo.WriteData(buf)); Assert.False(buffer.Empty); poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries)); poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Never); Assert.Equal(iNumberOfEntries, list.Sent.Count()); RailPackedListIncoming <Foo> incoming = new RailPackedListIncoming <Foo>(); incoming.Decode( buffer, b => { Foo foo = poolMock.Object.Allocate(); foo.ReadData(b); return(foo); }); Assert.Equal(iNumberOfEntries, incoming.Received.Count()); }
public RailPacketToClient() { deltas = new RailPackedListOutgoing <RailStateDelta>(); }
public RailPacketToServer() { view = new RailView(); commandUpdates = new RailPackedListOutgoing <RailCommandUpdate>(); }