public void CopyToTests()
        {
            var testContext = _propertyTestData.GetContext();
            var x           = new ConfigurationDictionary <IChildElement>(null, testContext.ChildConfigurationDictionaryPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            var a = testContext.GetChildElement("a");
            var b = testContext.GetChildElement("b");
            var c = testContext.GetChildElement("c");

            x.AddCopy("a", a);
            x.AddCopy("b", b);
            x.AddCopy("c", c);

            var array = new KeyValuePair <string, IChildElement> [3];

            x.CopyTo(array, 0);

            Assert.Equal(a, array[0].Value, ConfigurationObjectComparer.Instance);
            Assert.Equal(b, array[1].Value, ConfigurationObjectComparer.Instance);
            Assert.Equal(c, array[2].Value, ConfigurationObjectComparer.Instance);

            Assert.Throws <ArgumentException>(() => x.CopyTo(array, 1));

            Assert.Throws <ArgumentOutOfRangeException>(() => x.CopyTo(array, -1));

            array = new KeyValuePair <string, IChildElement> [2];

            Assert.Throws <ArgumentException>(() => x.CopyTo(array, 0));

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x.CopyTo(array, 0));
        }
        public void ContainsTests()
        {
            var testContext = _propertyTestData.GetContext();
            var x           = new ConfigurationDictionary <IChildElement>(null, testContext.ChildConfigurationDictionaryPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            var a = testContext.GetChildElement("a");
            var b = testContext.GetChildElement("b");
            var c = testContext.GetChildElement("c");
            var d = testContext.GetChildElement("d");

            x.AddCopy("a", a);
            x.AddCopy("b", b);

            Assert.True(x.Contains(a));
            Assert.True(x.Contains(b));
            Assert.False(x.Contains(c));
            Assert.False(x.Contains(null));
            Assert.True(((ICollection <KeyValuePair <string, IChildElement> >)x).Contains(new KeyValuePair <string, IChildElement>("a", a)));
            Assert.False(((ICollection <KeyValuePair <string, IChildElement> >)x).Contains(new KeyValuePair <string, IChildElement>("d", d)));

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x.Contains(a));
            Assert.Throws <ObjectDisposedException>(() =>
                                                    ((ICollection <KeyValuePair <string, IChildElement> >)x).Contains(new KeyValuePair <string, IChildElement>("a", a)));
        }
        public void ClearTests()
        {
            var testContext = _propertyTestData.GetContext();
            var a           = testContext.GetChildElement("a");
            var b           = testContext.GetChildElement("b");
            var c           = testContext.GetChildElement("c");
            var d           = testContext.GetChildElement("d");
            var x           = new ConfigurationDictionary <IChildElement>(null, testContext.ChildConfigurationDictionaryPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings(), Get("a", a), Get("b", b), Get("c", c), Get("d", d));

            Assert.Equal(4, x.Count);

            var change = (NotifyCollectionChangedAction)(-1);

            x.CollectionChanged += (sender, args) => { change = args.Action; };

            x.Clear();

            Assert.Equal(0, x.Count);
            Assert.Equal(NotifyCollectionChangedAction.Reset, change);

            foreach (var item in x)
            {
                Assert.True(false);
            }

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x.Clear());
        }
        public void DisposeTests()
        {
            var testContext = _propertyTestData.GetContext();
            var x           = new ConfigurationDictionary <IChildElement>(null, testContext.ChildConfigurationDictionaryPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x.ContainsKey("A"));
        }
        public void RemoveTests()
        {
            var testContext = _propertyTestData.GetContext();
            var x           = new ConfigurationDictionary <IChildElement>(null, testContext.ChildConfigurationDictionaryPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            var a = testContext.GetChildElement("a");
            var b = testContext.GetChildElement("b");
            var c = testContext.GetChildElement("c");
            var d = testContext.GetChildElement("d");

            x.AddCopy("a", a);
            x.AddCopy("b", b);
            x.AddCopy("c", c);

            var change = (NotifyCollectionChangedAction)(-1);

            x.CollectionChanged += (sender, args) => { change = args.Action; };

            Assert.True(x.Remove(b));
            Assert.Equal(NotifyCollectionChangedAction.Remove, change);

            change = (NotifyCollectionChangedAction)(-1);
            Assert.False(x.Remove(b));
            Assert.Equal((NotifyCollectionChangedAction)(-1), change);

            Assert.Equal(2, x.Count);

            var n = 0;

            foreach (var item in x)
            {
                switch (n++)
                {
                case 0:
                    Assert.Equal(a, item.Value, ConfigurationObjectComparer.Instance);
                    break;

                case 1:
                    Assert.Equal(c, item.Value, ConfigurationObjectComparer.Instance);
                    break;

                default:
                    Assert.True(false);
                    break;
                }
            }

            x.AddCopy("b", b);
            Assert.True(x.Remove(new KeyValuePair <string, IChildElement>("b", b)));
            Assert.False(x.Remove(new KeyValuePair <string, IChildElement>("b", b)));

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x.Remove(a));
        }
        public void UntypedEnumeratorTests()
        {
            var testContext = _propertyTestData.GetContext();
            var a           = testContext.GetChildElement("a");
            var b           = testContext.GetChildElement("b");
            var c           = testContext.GetChildElement("c");

            var x = new ConfigurationDictionary <IChildElement>(null, testContext.ChildConfigurationDictionaryPropertyDef,
                                                                testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            foreach (var item in (IEnumerable)x)
            {
                Assert.True(false);
            }

            x = new ConfigurationDictionary <IChildElement>(null, testContext.ChildConfigurationDictionaryPropertyDef,
                                                            testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings(), Get("a", a), Get("b", b), Get("c", c));

            var n = 0;

            foreach (KeyValuePair <string, IChildElement> item in (IEnumerable)x)
            {
                switch (n++)
                {
                case 0:
                    Assert.Equal(a, item.Value, ConfigurationObjectComparer.Instance);
                    break;

                case 1:
                    Assert.Equal(b, item.Value, ConfigurationObjectComparer.Instance);
                    break;

                case 2:
                    Assert.Equal(c, item.Value, ConfigurationObjectComparer.Instance);
                    break;

                default:
                    Assert.True(false);
                    break;
                }
            }

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() =>
            {
                foreach (var y in (IEnumerable)x)
                {
                }

                ;
            });
        }
        public void ValuesTests()
        {
            var testContext = _propertyTestData.GetContext();
            var a           = testContext.GetChildElement("a");
            var b           = testContext.GetChildElement("b");
            var c           = testContext.GetChildElement("c");

            var x = new ConfigurationDictionary <IChildElement>(null, testContext.ChildConfigurationDictionaryPropertyDef,
                                                                testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings(), Get("a", a), Get("b", b), Get("c", c));

            var values = x.Values;

            Assert.NotNull(values);
            Assert.Equal(3, values.Count);

            var n = 0;

            foreach (var value in values)
            {
                switch (n++)
                {
                case 0:
                    Assert.Equal(a, value, ConfigurationObjectComparer.Instance);
                    break;

                case 1:
                    Assert.Equal(b, value, ConfigurationObjectComparer.Instance);
                    break;

                case 2:
                    Assert.Equal(c, value, ConfigurationObjectComparer.Instance);
                    break;

                default:
                    Assert.True(false);
                    break;
                }
            }

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x.Values);
        }
        public void KeysTests()
        {
            var testContext = _propertyTestData.GetContext();
            var a           = testContext.GetChildElement("a");
            var b           = testContext.GetChildElement("b");
            var c           = testContext.GetChildElement("c");

            var x = new ConfigurationDictionary <IChildElement>(null, testContext.ChildConfigurationDictionaryPropertyDef,
                                                                testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings(), Get("a", a), Get("b", b), Get("c", c));

            var keys = x.Keys;

            Assert.NotNull(keys);
            Assert.Equal(3, keys.Count);

            var n = 0;

            foreach (var key in keys)
            {
                switch (n++)
                {
                case 0:
                    Assert.Equal(a.PropertyDef().PropertyName, key);
                    break;

                case 1:
                    Assert.Equal(b.PropertyDef().PropertyName, key);
                    break;

                case 2:
                    Assert.Equal(c.PropertyDef().PropertyName, key);
                    break;

                default:
                    Assert.True(false);
                    break;
                }
            }

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x.Keys);
        }
        public void IndexerTests()
        {
            var testContext = _propertyTestData.GetContext();
            var x           = new ConfigurationDictionary <IChildElement>(null, testContext.ChildConfigurationDictionaryPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            var a = testContext.GetChildElement("a");
            var b = testContext.GetChildElement("b");
            var c = testContext.GetChildElement("c");
            var d = testContext.GetChildElement("d");

            x.AddCopy("a", a);
            x.AddCopy("b", b);
            x.AddCopy("c", c);

            Assert.Equal(a, x["a"].Value, ConfigurationObjectComparer.Instance);
            Assert.Equal(b, x["b"].Value, ConfigurationObjectComparer.Instance);
            Assert.Equal(c, x["c"].Value, ConfigurationObjectComparer.Instance);
            Assert.Throws <ArgumentOutOfRangeException>(() => x["d"]);

            x["a"].Value = a;

            var z = (IDictionary <string, IChildElement>)x;

            Assert.Equal(a, z["a"], ConfigurationObjectComparer.Instance);
            Assert.Equal(b, z["b"], ConfigurationObjectComparer.Instance);
            Assert.Equal(c, z["c"], ConfigurationObjectComparer.Instance);
            Assert.Throws <ArgumentOutOfRangeException>(() => z["d"]);
            z["a"] = a;

            var change = (NotifyCollectionChangedAction)(-1);

            x.CollectionChanged += (sender, args) => { change = args.Action; };

            x["c"].Value = d;

            Assert.Equal(NotifyCollectionChangedAction.Replace, change);

            var n = 0;

            foreach (var item in x)
            {
                switch (n++)
                {
                case 0:
                    Assert.Equal(a, item.Value, ConfigurationObjectComparer.Instance);
                    break;

                case 1:
                    Assert.Equal(b, item.Value, ConfigurationObjectComparer.Instance);
                    break;

                case 2:
                    Assert.Equal(d, item.Value, ConfigurationObjectComparer.Instance);
                    break;

                default:
                    Assert.True(false);
                    break;
                }
            }

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x["a"]);
        }