Exemplo n.º 1
0
        /// <summary>
        /// 设定配置的值
        /// </summary>
        /// <typeparam name="T">值的类型</typeparam>
        /// <param name="name">配置名</param>
        /// <param name="value">配置的值</param>
        public void Set <T>(string name, T value)
        {
            Guard.NotNull(name, "name");
            if (locators.Count <= 0)
            {
                throw new RuntimeException("No Reg locator. please Reg() locator first.");
            }

            IConfigLocator configLocator = null;
            string         val;

            foreach (var locator in locators)
            {
                if (locator.TryGetValue(name, out val))
                {
                    configLocator = locator;
                }
            }

            if (configLocator == null)
            {
                configLocator = locators.Last();
            }

            ITypeStringConverter converter;

            if (!typeStringConverters.TryGetValue(typeof(T), out converter))
            {
                throw new ConverterException("Can not find [" + typeof(T) + "] coverter impl.");
            }

            configLocator.Set(name, converter.ConvertToString(value));
        }
Exemplo n.º 2
0
        public void FirstLastTest()
        {
            var master = new SortSet <int, int>(0.25, 32);

            for (var i = 0; i < 65536; i++)
            {
                master.Add(i, i);
            }

            Assert.AreEqual(0, master.First());
            Assert.AreEqual(65535, master.Last());

            for (var i = 0; i < 65536; i++)
            {
                Assert.AreEqual(i, master.First());
                Assert.AreEqual(i, master.Shift());
            }

            Assert.AreEqual(0, master.Count);

            master = new SortSet <int, int>(0.25, 32);
            for (var i = 0; i < 65536; i++)
            {
                master.Add(i, i);
            }
            for (var i = 0; i < 65536; i++)
            {
                Assert.AreEqual(65535 - i, master.Last());
                Assert.AreEqual(65535 - i, master.Pop());
            }
        }
Exemplo n.º 3
0
        public void LastEmptySortSet()
        {
            var master = new SortSet <int, int>(0.25, 32);

            ExceptionAssert.Throws <InvalidOperationException>(() =>
            {
                master.Last();
            });
        }
Exemplo n.º 4
0
        public void BoundLastTest()
        {
            var master = new SortSet <int, int>(0.25, 32);

            ExceptionAssert.DoesNotThrow(() =>
            {
                master.Last();
            });
        }