Exemple #1
0
        private void PoolReusesInstances()
        {
            factoryMock.Setup(f => f.Create()).Returns(new A());
            RailMemoryPool <A> pool = new RailMemoryPool <A>(factoryMock.Object);
            A firstObject           = pool.Allocate();

            factoryMock.Verify(f => f.Create(), Times.Once);

            pool.Deallocate(firstObject);
            A secondObject = pool.Allocate();

            factoryMock.Verify(f => f.Create(), Times.Once);
            Assert.Same(firstObject, secondObject);
        }
Exemple #2
0
        private void AllocateCallsFactory()
        {
            A instance = new A();

            factoryMock.Setup(f => f.Create()).Returns(instance);

            RailMemoryPool <A> pool = new RailMemoryPool <A>(factoryMock.Object);
            A allocatedObject       = pool.Allocate();

            factoryMock.Verify(f => f.Create(), Times.Once);
            Assert.Same(instance, allocatedObject);
        }
Exemple #3
0
        private void DecodeReadsTickAndCommandData(int iData)
        {
            RailMemoryPool <RailCommand> pool =
                new RailMemoryPool <RailCommand>(new RailFactory <TestUtils.Command>());
            Mock <IRailCommandConstruction> mockCreator = new Mock <IRailCommandConstruction>();

            mockCreator.Setup(m => m.CreateCommand()).Returns(pool.Allocate());

            RailBitBuffer bitBuffer   = new RailBitBuffer(2);
            Tick          writtenTick = Tick.START.GetNext();

            bitBuffer.WriteTick(writtenTick);
            bitBuffer.WriteInt(iData);

            RailCommand decodedGenericCommand = RailCommand.Decode(mockCreator.Object, bitBuffer);

            Assert.IsType <TestUtils.Command>(decodedGenericCommand);
            TestUtils.Command decodedCommand = decodedGenericCommand as TestUtils.Command;
            Assert.NotNull(decodedCommand);
            Assert.Equal(writtenTick, decodedCommand.ClientTick);
            Assert.Equal(iData, decodedCommand.Data);
        }