예제 #1
0
        public void TestGetDataNegativeIndex()
        {
            var registry = new SendableRegistry();

            var sendableMock = new Mock <ISendable>();

            Assert.Throws <ArgumentOutOfRangeException>(() => registry.GetData(sendableMock.Object, -1));
        }
예제 #2
0
        public void TestGetDataNonExistant()
        {
            var registry = new SendableRegistry();

            var sendableMock = new Mock <ISendable>();

            Assert.Null(registry.GetData(sendableMock.Object, 0));
        }
예제 #3
0
        public void TestSetDataTwiceWorks()
        {
            var registry = new SendableRegistry();

            var sendableMock = new Mock <ISendable>();

            registry.Add(sendableMock.Object, "mysendable");

            string data = "42";

            Assert.Null(registry.SetData(sendableMock.Object, 0, data));
            Assert.Equal(data, registry.GetData(sendableMock.Object, 0));

            string data2 = "world";

            Assert.Equal(data, registry.SetData(sendableMock.Object, 0, data2));
            Assert.Equal(data2, registry.GetData(sendableMock.Object, 0));
        }
예제 #4
0
        private static Component GetOrAdd(ISendable sendable)
        {
            Component?data = (Component?)registry.GetData(sendable, dataHandle);

            if (data == null)
            {
                data = new Component();
                registry.SetData(sendable, dataHandle, data);
            }
            return(data);
        }