static void Main(string[] args)
    {
        // Creating a dynamic dictionary.
        dynamic person = new DynamicDictionary();

        // Adding new dynamic properties.
        // The TrySetMember method is called.
        person.FirstName = "Ellen";
        person.LastName  = "Adams";

        // Calling a method defined in the DynmaicDictionary class.
        // The Print method is called.
        person.Print();

        Console.WriteLine(
            "Removing all the elements from the dictionary.");

        // Calling a method that is not defined in the DynamicDictionary class.
        // The TryInvokeMember method is called.
        person.Clear();

        // Calling the Print method again.
        person.Print();

        // The following statement throws an exception at run time.
        // There is no Sample method
        // in the dictionary or in the DynamicDictionary class.
        // person.Sample();
    }
        public void TestClearEmptyList()
        {
            var d = new DynamicDictionary();

            d.Clear();

            Assert.AreEqual(0, d.Count);
        }
        public void DynamicDictionary_EventsTests()
        {
            DynamicDictionary d = new DynamicDictionary();

            int countAdd     = 0;
            int countRemove  = 0;
            int countChanged = 0;
            int countClear   = 0;
            int countOther   = 0;

            d.OnChange += (sender, e) =>
            {
                switch (e.EventType)
                {
                case DynamicDictionaryChangedType.AddedValue:
                    countAdd++;
                    break;

                case DynamicDictionaryChangedType.RemovedValue:
                    countRemove++;
                    break;

                case DynamicDictionaryChangedType.ChangedValue:
                    countChanged++;
                    break;

                case DynamicDictionaryChangedType.Clear:
                    countClear++;
                    break;

                default:
                    countOther++;
                    break;
                }
            };

            d["1"] = "Main";
            Assert.AreEqual(1, countAdd);

            d["1"] = "Main";
            Assert.AreEqual(0, countChanged);

            d["2"] = "New";
            Assert.AreEqual(2, countAdd);

            d["2"] = "Test";
            Assert.AreEqual(1, countChanged);

            d.Add("3", "Name");
            Assert.AreEqual(3, countAdd);

            d.Remove("3");
            Assert.AreEqual(1, countRemove);

            d.Clear();
            Assert.AreEqual(1, countClear);
            Assert.AreEqual(0, countOther);
        }
        public void TestClearNonEmptyList()
        {
            var d = new DynamicDictionary();

            d.Add(new KeyValuePair <string, object>("foo", "bar"));

            d.Clear();

            Assert.AreEqual(0, d.Count);
        }
Exemplo n.º 5
0
        public void Should_remove_all_values_when_clear_is_invoked()
        {
            // Given
            var input = new DynamicDictionary();

            input["test1"] = 10;
            input["test2"] = "test2";

            // When
            input.Clear();

            // Then
            input.Count.ShouldEqual(0);
        }
Exemplo n.º 6
0
        internal static void Test()
        {
            // Динамический словарь.
            dynamic person = new DynamicDictionary();

            // Динамические свойства
            person.FirstName = "Ellen";
            person.LastName  = "Adams";

            person.ToString();

            // TryInvokeMember делает доступными методы словаря
            person.Remove("firstname");
            person.ToString();

            person.Clear();   // TryInvokeMember
        }
        public void Should_remove_all_values_when_clear_is_invoked()
        {
            // Given
            var input = new DynamicDictionary();
            input["test1"] = 10;
            input["test2"] = "test2";

            // When
            input.Clear();

            // Then
            input.Count.ShouldEqual(0);
        }
        public void TestClearEmptyList()
        {
            var d = new DynamicDictionary();

            d.Clear();
            
            Assert.AreEqual(0, d.Count);
        }
        public void TestClearNonEmptyList()
        {
            var d = new DynamicDictionary();

            d.Add(new KeyValuePair<string, object>("foo", "bar"));

            d.Clear();

            Assert.AreEqual(0, d.Count);
        }