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 DefaultConstructor_ExpectedValues() { // Call var converter = new ExpandableArrayConverter(); // Assert Assert.IsInstanceOf <ArrayConverter>(converter); }
public void ConvertTo_FromNullToString_ReturnEmptyText() { // Setup var converter = new ExpandableArrayConverter(); // Call object text = converter.ConvertTo(null, typeof(string)); // Assert Assert.AreEqual(string.Empty, text); }
public void ConvertTo_FromArrayToNull_ThrowsArgumentNullException() { // Setup var sourceArray = new int[2]; var converter = new ExpandableArrayConverter(); // Call TestDelegate call = () => converter.ConvertTo(sourceArray, null); // Assert Assert.Throws <ArgumentNullException>(call); }
public void ConvertTo_FromArrayToInt_ThrowsNotSupportedException() { // Setup var sourceArray = new int[1]; var converter = new ExpandableArrayConverter(); // Call TestDelegate call = () => converter.ConvertTo(sourceArray, typeof(int)); // Assert Assert.Throws <NotSupportedException>(call); }
public void ConvertTo_FromArrayToString_ReturnCountText() { // Setup int arrayCount = new Random(21).Next(0, 10); var sourceArray = new int[arrayCount]; var converter = new ExpandableArrayConverter(); // Call object text = converter.ConvertTo(sourceArray, typeof(string)); // Assert Assert.AreEqual($"Aantal ({arrayCount})", text); }
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); }