Ejemplo n.º 1
0
        public void CreateFromObject_CopiesPropertiesFromRegularType_WithIndexerProperty()
        {
            // Arrange
            var obj = new IndexerProperty();

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

            // Assert
            Assert.Equal(0, dict.Count);
        }
Ejemplo n.º 2
0
        public void CreateFromObject_CopiesPropertiesFromRegularType_WithIndexerProperty()
        {
            // Arrange
            var obj = new IndexerProperty();

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

            // Assert
            Assert.NotNull(dict._propertyStorage);
            Assert.Empty(dict);
        }
        public void CreateFromObject_CopiesPropertiesFromRegularType_WithIndexerProperty()
        {
            // Arrange
            var obj = new IndexerProperty();

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

            // Assert
            Assert.IsType <DispatcherValueCollection.PropertyStorage>(dict._storage);
            Assert.Empty(dict);
        }
Ejemplo n.º 4
0
        public void CreateFromObject_CopiesPropertiesFromRegularType_WithIndexerProperty()
        {
            // Arrange
            var obj = new IndexerProperty();

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

            // Assert
            Assert.Equal(0, dict.Count);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Tests that common aspects of the specified collection are functional.
        /// </summary>
        /// <param name="collection">An object that is the collection to be tested.</param>
        public static void TestCollection(object collection)
        {
            if (collection != null)
            {
                Type MyType;

                MyType = collection.GetType();
                if (MyType.GetInterface("ICollection") != null)
                {
                    Type[] GenericTypes;

                    GenericTypes = MyType.BaseType.GetGenericArguments();
                    if (GenericTypes != null && GenericTypes.Length == 1)
                    {
                        MethodInfo   AddMethod;
                        PropertyInfo CountProperty;
                        PropertyInfo IndexerProperty;
                        MethodInfo   RemoveMethod;

                        AddMethod       = MyType.GetMethod("Add");
                        CountProperty   = MyType.GetProperty("Count");
                        IndexerProperty = MyType.GetProperty("Item", GenericTypes[0], new Type[] { typeof(int) });
                        RemoveMethod    = MyType.GetMethod("Remove");

                        if (AddMethod != null && RemoveMethod != null && CountProperty != null && IndexerProperty != null)
                        {
                            int CurrentCount;

                            CurrentCount = (int)CountProperty.GetValue(collection);
                            if (CurrentCount > 0)
                            {
                                object TestObject;

                                TestObject = IndexerProperty.GetValue(collection, new object[] { 0 });
                                if (TestObject != null)
                                {
                                    Assert.AreEqual(CurrentCount, CountProperty.GetValue(collection));
                                    RemoveMethod.Invoke(collection, new object[] { TestObject });
                                    Assert.AreEqual(CurrentCount - 1, CountProperty.GetValue(collection));
                                    AddMethod.Invoke(collection, new object[] { TestObject });
                                    Assert.AreEqual(CurrentCount, CountProperty.GetValue(collection));
                                }
                                else
                                {
                                    Assert.Fail("Indexer returned a null result");
                                }
                            }
                            else
                            {
                                throw new ArgumentException("The specified collection is empty and cannot be tested", "collection");
                            }
                        }
                        else
                        {
                            throw new ArgumentException("The specified type does not support required operations", "collection");
                        }
                    }
                    else
                    {
                        throw new ArgumentException("The specified type does not implement a generic collection", "collection");
                    }
                }
                else
                {
                    throw new ArgumentException("The specified type does not implement ICollection", "collection");
                }
            }
            else
            {
                throw new ArgumentException("The specified collection is null", "collection");
            }
        }