public void CreateFromObject_CopiesPropertiesFromRegularType_IncludesInherited()
        {
            // Arrange
            var obj = new Derived()
            {
                TotallySweetProperty = true, DerivedProperty = false
            };

            // Act
            var dict = new DispatcherValueCollection(obj);

            // Assert
            Assert.IsType <DispatcherValueCollection.PropertyStorage>(dict._storage);
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp =>
            {
                Assert.Equal("DerivedProperty", kvp.Key);
                var value = Assert.IsType <bool>(kvp.Value);
                Assert.False(value);
            },
                kvp =>
            {
                Assert.Equal("TotallySweetProperty", kvp.Key);
                var value = Assert.IsType <bool>(kvp.Value);
                Assert.True(value);
            });
        }
        public void CreateFromObject_CopiesPropertiesFromRegularType()
        {
            // Arrange
            var obj = new RegularType()
            {
                CoolnessFactor = 73
            };

            // Act
            var dict = new DispatcherValueCollection(obj);

            // Assert
            Assert.IsType <DispatcherValueCollection.PropertyStorage>(dict._storage);
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp =>
            {
                Assert.Equal("CoolnessFactor", kvp.Key);
                Assert.Equal(73, kvp.Value);
            },
                kvp =>
            {
                Assert.Equal("IsAwesome", kvp.Key);
                var value = Assert.IsType <bool>(kvp.Value);
                Assert.False(value);
            });
        }
        public void CreateFromIEnumerableStringValuePair_CopiesValues(object values)
        {
            // Arrange & Act
            var dict = new DispatcherValueCollection(values);

            // Assert
            Assert.IsType <DispatcherValueCollection.ListStorage>(dict._storage);
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp => { Assert.Equal("First Name", kvp.Key); Assert.Equal("James", kvp.Value); },
                kvp => { Assert.Equal("Last Name", kvp.Key); Assert.Equal("Henrik", kvp.Value); },
                kvp => { Assert.Equal("Middle Name", kvp.Key); Assert.Equal("Bob", kvp.Value); });
        }
        public void Add_PropertyStorage()
        {
            // Arrange
            var dict = new DispatcherValueCollection(new { age = 30 });

            // Act
            dict.Add("key", "value");

            // Assert
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp => { Assert.Equal("age", kvp.Key); Assert.Equal(30, kvp.Value); },
                kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); });
            Assert.IsType <DispatcherValueCollection.ListStorage>(dict._storage);
        }
        public void CreateFromObject_CopiesPropertiesFromAnonymousType()
        {
            // Arrange
            var obj = new { cool = "beans", awesome = 123 };

            // Act
            var dict = new DispatcherValueCollection(obj);

            // Assert
            Assert.IsType <DispatcherValueCollection.PropertyStorage>(dict._storage);
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp => { Assert.Equal("awesome", kvp.Key); Assert.Equal(123, kvp.Value); },
                kvp => { Assert.Equal("cool", kvp.Key); Assert.Equal("beans", kvp.Value); });
        }
        public void CreateFromObject_CopiesPropertiesFromRegularType_WithHiddenProperty()
        {
            // Arrange
            var obj = new DerivedHiddenProperty()
            {
                DerivedProperty = 5
            };

            // Act
            var dict = new DispatcherValueCollection(obj);

            // Assert
            Assert.IsType <DispatcherValueCollection.PropertyStorage>(dict._storage);
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp => { Assert.Equal("DerivedProperty", kvp.Key); Assert.Equal(5, kvp.Value); });
        }
        public void Add_KeyValuePair()
        {
            // Arrange
            var dict = new DispatcherValueCollection()
            {
                { "age", 30 },
            };

            // Act
            ((ICollection <KeyValuePair <string, object> >)dict).Add(new KeyValuePair <string, object>("key", "value"));

            // Assert
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp => { Assert.Equal("age", kvp.Key); Assert.Equal(30, kvp.Value); },
                kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); });
            Assert.IsType <DispatcherValueCollection.ListStorage>(dict._storage);
        }
        public void IndexSet_ListStorage_NoMatch_AddsValue()
        {
            // Arrange
            var dict = new DispatcherValueCollection()
            {
                { "age", 30 },
            };

            // Act
            dict["key"] = "value";

            // Assert
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp => { Assert.Equal("age", kvp.Key); Assert.Equal(30, kvp.Value); },
                kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); });
            Assert.IsType <DispatcherValueCollection.ListStorage>(dict._storage);
        }
        public void Add_DuplicateKey_CaseInsensitive()
        {
            // Arrange
            var dict = new DispatcherValueCollection()
            {
                { "key", "value" },
            };

            var message = $"An element with the key 'kEy' already exists in the {nameof(DispatcherValueCollection)}";

            // Act & Assert
            ExceptionAssert.ThrowsArgument(() => dict.Add("kEy", "value2"), "key", message);

            // Assert
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); });
            Assert.IsType <DispatcherValueCollection.ListStorage>(dict._storage);
        }
        public void CreateFromIEnumerableKeyValuePair_CopiesValues(object values)
        {
            // Arrange & Act
            var dict = new DispatcherValueCollection(values);

            // Assert
            Assert.IsType <DispatcherValueCollection.ListStorage>(dict._storage);
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp =>
            {
                Assert.Equal("Address", kvp.Key);
                var address = Assert.IsType <Address>(kvp.Value);
                Assert.Equal("Redmond", address.City);
                Assert.Equal("WA", address.State);
            },
                kvp => { Assert.Equal("Age", kvp.Key); Assert.Equal(30, kvp.Value); },
                kvp => { Assert.Equal("Name", kvp.Key); Assert.Equal("James", kvp.Value); });
        }
        public void CreateFromObject_CopiesPropertiesFromRegularType_PublicOnly()
        {
            // Arrange
            var obj = new Visibility()
            {
                IsPublic = true, ItsInternalDealWithIt = 5
            };

            // Act
            var dict = new DispatcherValueCollection(obj);

            // Assert
            Assert.IsType <DispatcherValueCollection.PropertyStorage>(dict._storage);
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp =>
            {
                Assert.Equal("IsPublic", kvp.Key);
                var value = Assert.IsType <bool>(kvp.Value);
                Assert.True(value);
            });
        }