public void GetProperties_FromArray_ReturnPropertyDescriptorsForEachElementWithNameToOneBasedIndex(int elementCount) { // Setup int[] array = Enumerable.Range(10, elementCount).ToArray(); var converter = new ExpandableArrayConverter(); // Call PropertyDescriptorCollection propertyDescriptors = converter.GetProperties(array); // Assert Assert.IsNotNull(propertyDescriptors); Assert.AreEqual(elementCount, propertyDescriptors.Count); for (var i = 0; i < elementCount; i++) { Assert.AreEqual(array.GetType(), propertyDescriptors[i].ComponentType); Assert.AreEqual($"[{i + 1}]", propertyDescriptors[i].Name); Assert.AreEqual($"[{i + 1}]", propertyDescriptors[i].DisplayName); Assert.AreEqual(typeof(int), propertyDescriptors[i].PropertyType); CollectionAssert.IsEmpty(propertyDescriptors[i].Attributes); var value = propertyDescriptors[i].GetValue(array) as DynamicPropertyBag; Assert.NotNull(value); Assert.AreEqual(array[i], value.WrappedObject); } }
public void GetProperties_FromArray_SettingValuesShouldUpdateArray() { // Setup const int elementCount = 12; int[] array = Enumerable.Repeat(10, elementCount).ToArray(); var converter = new ExpandableArrayConverter(); // Call PropertyDescriptorCollection propertyDescriptors = converter.GetProperties(array); for (var i = 0; i < elementCount; i++) { propertyDescriptors[i].SetValue(array, i); } // Assert CollectionAssert.AreEqual(Enumerable.Range(0, elementCount), array); }