Example #1
0
        private void VerifyEmptyPacketFromServerToClient()
        {
            // Init
            RailPacketToClient toClient = new RailPacketToClient();
            Tick startingTick           = TestUtils.CreateTick(4200);
            Tick lastAckTick            = TestUtils.CreateTick(4200 - 5);

            toClient.Initialize(startingTick, lastAckTick, SequenceId.Start, new List <RailEvent>());
            toClient.Populate(
                new List <RailStateDelta>(),
                new List <RailStateDelta>(),
                new List <RailStateDelta>());

            // Verify initialize
            Assert.Equal(startingTick, toClient.SenderTick);
            Assert.Equal(lastAckTick, toClient.LastAckTick);

            // Encode
            Assert.True(bitBuffer.Empty);
            toClient.Encode(stateCreator.Object, eventCreator.Object, bitBuffer);

            // Since the packet was empty, nothing was allocated
            stateCreator.Verify(f => f.CreateState(It.IsAny <int>()), Times.Never);
            stateCreator.Verify(f => f.CreateDelta(), Times.Never);
            stateCreator.Verify(f => f.CreateRecord(), Times.Never);
            stateCreator.Verify(f => f.EntityTypeCompressor, Times.Never);
            eventCreator.Verify(f => f.CreateEvent(It.IsAny <int>()), Times.Never);
            eventCreator.Verify(f => f.EventTypeCompressor, Times.Never);

            // Bitbuffer was written to.
            Assert.True(!bitBuffer.Empty);

            // Decode
            RailPacketFromServer fromServer = new RailPacketFromServer();

            fromServer.Decode(
                commandCreator.Object,
                stateCreator.Object,
                eventCreator.Object,
                bitBuffer);

            // Verify decoded packet
            Assert.True(bitBuffer.IsFinished);
            Assert.Equal(toClient, fromServer, new TestUtils.RailPacketComparer());

            // Since the packet was empty, nothing was allocated
            stateCreator.Verify(f => f.CreateState(It.IsAny <int>()), Times.Never);
            stateCreator.Verify(f => f.CreateDelta(), Times.Never);
            stateCreator.Verify(f => f.CreateRecord(), Times.Never);
            stateCreator.Verify(f => f.EntityTypeCompressor, Times.Never);
            eventCreator.Verify(f => f.CreateEvent(It.IsAny <int>()), Times.Never);
            eventCreator.Verify(f => f.EventTypeCompressor, Times.Never);
        }