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));
        }
示例#2
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);
        }
        public void TestSetDataNegativeIndex()
        {
            var registry = new SendableRegistry();

            var sendableMock = new Mock <ISendable>();

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

            string data = "42";

            Assert.Throws <ArgumentOutOfRangeException>(() => registry.SetData(sendableMock.Object, -1, data));
        }