示例#1
0
        public void DynamicListValue_BasicTest()
        {
            string name       = "John";
            string middleName = "Doc";
            string lastName   = "Smith";
            string randomName = new Random().Next().ToString();

            DynamicListValue lValue = new DynamicListValue();

            Assert.IsNotNull(lValue);

            lValue.Value = name;
            lValue.Add(lastName);
            lValue.Insert(1, middleName);

            Assert.AreEqual(3, lValue.Count);
            Assert.AreEqual(name, lValue.Value);
            Assert.AreEqual(middleName, lValue[1]);
            Assert.AreEqual(lastName, lValue[2]);

            lValue -= middleName;
            lValue -= name;
            lValue += randomName;

            Assert.AreEqual(2, lValue.Count);
            Assert.AreEqual(lastName, lValue.Value);
            Assert.AreEqual(randomName, lValue[1]);

            lValue.Clear();

            Assert.AreEqual(0, lValue.Count);
            Assert.IsFalse(lValue.HasValue);

            var list = new List <TestClass>
            {
                new TestClass(),
                new TestClass(),
                new TestClass()
            };

            lValue.AddRange(list);
            Assert.AreEqual(list.Count, lValue.Count);
            Assert.AreEqual(1, lValue.IndexOf(list[1]));

            bool fResult = lValue.Remove(new TestClass());
            bool tResult = lValue.Remove(list[0]);

            Assert.IsFalse(fResult);
            Assert.IsTrue(tResult);

            fResult = lValue.Contains(list[0]);

            Assert.IsFalse(fResult);
        }
示例#2
0
        public void DynamicListValue_TestDistinct()
        {
            DynamicListValue value = new DynamicListValue();

            string elem1 = "Element 1";
            string elem2 = "Element 2";
            string elem3 = "Element 3";

            value.UseDistinct = true;

            value.Add(elem1);
            value.Add(elem2);
            value.Add(elem2);
            value.Add(elem3);
            value.Add(elem3);
            value.Add(elem1);

            Assert.AreEqual(3, value.Count);
        }
示例#3
0
        public void DynamicListValue_RaiseEventTest()
        {
            int countAddEvent    = 0;
            int countChangeEvent = 0;
            int countOrderEvent  = 0;
            int countRemoveEvent = 0;
            int countClearEvent  = 0;
            int otherEventType   = 0;

            string        mainValue = "Main Test Subject";
            List <string> values    = new List <string> {
                "val1", "val2", "val3"
            };

            DynamicListValue obj = new DynamicListValue();

            obj.OnDynamicListValueChanged += (sender, e) =>
            {
                switch (e.EventType)
                {
                case DynamicDictionaryChangedType.AddedValue:
                    countAddEvent++;
                    break;

                case DynamicDictionaryChangedType.ChangedValue:
                    countChangeEvent++;
                    break;

                case DynamicDictionaryChangedType.OrderValue:
                    countOrderEvent++;
                    break;

                case DynamicDictionaryChangedType.RemovedValue:
                    countRemoveEvent++;
                    break;

                case DynamicDictionaryChangedType.Clear:
                    countClearEvent++;
                    break;

                default:
                    otherEventType++;
                    break;
                }
            };

            obj.Value = mainValue;
            Assert.AreEqual(1, countAddEvent);

            obj.AddRange(values);
            Assert.AreEqual(4, countAddEvent);

            obj.Add(mainValue);
            Assert.AreEqual(5, countAddEvent);

            obj.SetMainValue(1);
            Assert.AreEqual(1, countOrderEvent);

            obj.SetMainValue(obj[2]);
            Assert.AreEqual(2, countOrderEvent);

            obj[0] = mainValue;
            obj[1] = mainValue;
            obj[2] = mainValue;
            Assert.AreEqual(2, countChangeEvent);

            obj.RemoveAt(0);
            Assert.AreEqual(1, countRemoveEvent);

            obj.RemoveRange(values);
            Assert.AreEqual(2, countRemoveEvent);

            obj.Clear();
            Assert.AreEqual(1, countClearEvent);

            Assert.AreEqual(0, otherEventType);
        }