private static PropertyDescriptor[] GetListAccessorsForAddresses(BrowsableViewModelList <EmployeeVM> list) { PropertyDescriptorCollection employeeProperties = list.GetItemProperties(null); PropertyDescriptor addressesPropertyDescriptor = employeeProperties["Addresses"]; return(new[] { addressesPropertyDescriptor }); }
private static PropertyDescriptor[] GetListAccessorsForSimpleTypeProperty(BrowsableViewModelList <EmployeeVM> list) { var employeeProperties = list.GetItemProperties(null); var simpleTypePropertyDescriptor = employeeProperties["SimpleTypeProperty"]; return(new[] { simpleTypePropertyDescriptor }); }
public void Constructor_WithEnumerable_PopulatesCollection() { IEnumerable <EmployeeVM> source = new[] { new EmployeeVM(), new EmployeeVM() }; var list = new BrowsableViewModelList <EmployeeVM>(source); CollectionAssert.AreEqual(source.ToArray(), list); }
public void GetItemProperties_WhenListAccessorsIsNull_AlwaysReturnsSameInstance() { var list = new BrowsableViewModelList <EmployeeVM>(); var first = list.GetItemProperties(listAccessors: null); var second = list.GetItemProperties(listAccessors: null); Assert.AreSame(first, second); }
public void GetItemProperties_WhenListAccessorsContainsDescendantPropertyAccessor_AlwaysReturnsSameInstance() { var list = new BrowsableViewModelList <EmployeeVM>(); var first = list.GetItemProperties(GetListAccessorsForManagerAddress(list)); var second = list.GetItemProperties(GetListAccessorsForManagerAddress(list)); Assert.AreSame(first, second); }
public void GetItemProperties_WhenListAccessorsContainsSimpleType_ReturnsPropertyDescriptorsOfThatType() { var list = new BrowsableViewModelList <EmployeeVM>(); var actualProperties = list.GetItemProperties(listAccessors: GetListAccessorsForSimpleTypeProperty(list)); var expectedProperties = TypeDescriptor.GetProperties(typeof(SimpleType)); CollectionAssert.AreEqual(GetExpectations(expectedProperties), GetExpectations(actualProperties)); }
public void GetItemProperties_WhenListAccessorsContainsCollectionPropertyDescriptor_ReturnsPropertyDescriptorsOfItemClassDescriptor() { var list = new BrowsableViewModelList <EmployeeVM>(); var actualProperties = list.GetItemProperties(listAccessors: GetListAccessorsForAddresses(list)); var expectedProperties = AddressVM.ClassDescriptor.Properties; CollectionAssert.AreEqual(GetExpectations(expectedProperties), GetExpectations(actualProperties)); }
public void GetItemProperties_WhenListAccessorsIsNull_ReturnsPropertyDescriptorsOfClassDescriptor() { var list = new BrowsableViewModelList <EmployeeVM>(); var actualProperties = list.GetItemProperties(listAccessors: null); var expectedProperties = EmployeeVM.ClassDescriptor.Properties; CollectionAssert.AreEqual(GetExpectations(expectedProperties), GetExpectations(actualProperties)); }
public void Add_OnEmptyCollection_AddsItem() { var list = new BrowsableViewModelList <EmployeeVM>(); var newItem = new EmployeeVM(); list.Add(newItem); CollectionAssert.AreEqual(new[] { newItem }, list); }
public void Constructor_WithItemArray_PopulatesCollection() { var item1 = new EmployeeVM(); var item2 = new EmployeeVM(); var list = new BrowsableViewModelList <EmployeeVM>(item1, item2); CollectionAssert.AreEqual(new[] { item1, item2 }, list); }
public void Add_OnPopulatedCollection_AddsItem() { var initialItem = new EmployeeVM(); var list = new BrowsableViewModelList <EmployeeVM>(initialItem); var newItem = new EmployeeVM(); list.Add(newItem); CollectionAssert.AreEqual(new[] { initialItem, newItem }, list); }
public void TypeDescriptorGetProperties_ReturnsCorrectProperties() { var list = new BrowsableViewModelList <ParentVM>(new ParentVM()); var selectionPropertyNames = TypeDescriptor .GetProperties(typeof(SingleSelectionVM <SelectionSource>)) .Cast <PropertyDescriptor>() .Select(x => x.Name) .ToArray(); CollectionAssert.Contains(selectionPropertyNames, "SelectedItem"); }
public void BrowsableViewModelList_ReturnsCorrectProperties() { var list = new BrowsableViewModelList <ParentVM>(new ParentVM()); var allProperties = list.GetItemProperties(null); var singleSelectionProperty = allProperties .Cast <PropertyDescriptor>() .Single(x => x.Name == "Selection"); var selectionPropertyNames = list .GetItemProperties(new[] { singleSelectionProperty }) .Cast <PropertyDescriptor>() .Select(x => x.Name) .ToArray(); CollectionAssert.Contains(selectionPropertyNames, "SelectedItem"); }
public void GetItemProperties_ForAViewModelCollectionPropertyOfAnObjectWithoutClassDescriptorAttribute_ReturnsViewModelProperties() { var list = new BrowsableViewModelList <ViewModelWithClassDescriptorVM>(); PropertyDescriptorCollection withDescProperties = list.GetItemProperties(null); PropertyDescriptor withoutAttributePropertyDescriptor = withDescProperties["ViewModelWithoutAttribute"]; PropertyDescriptor withAttributePropertyDescriptor = list .GetItemProperties(new[] { withoutAttributePropertyDescriptor })["ViewModelCollectionWithAttribute"]; PropertyDescriptorCollection withAttributeProperties = list .GetItemProperties(new[] { withoutAttributePropertyDescriptor, withAttributePropertyDescriptor }); var expectedProperties = ViewModelWithClassDescriptorVM.ClassDescriptor.Properties; CollectionAssert.AreEqual(GetExpectations(expectedProperties), GetExpectations(withAttributeProperties)); }