public ItemFiltererFixture() { var minMaxFilterModeMock = new Mock <IMinMaxFilterModeStrategy <ItemVm> >(); var strictLooseFilterModeMock = new Mock <IStrictLooseFilterModeStrategy <ItemVm> >(); ItemFilterer = new ItemFilterer((type, mode) => string.IsNullOrWhiteSpace(type) ? null : strictLooseFilterModeMock.Object, mode => minMaxFilterModeMock.Object); }
protected virtual void UpdateList() { int selectedIndex = _listBox.SelectedIndex; _listBox.BeginUpdate(); _listBox.Items.Clear(); _listBox.Font = Font; _listBox.ItemHeight = _listBox.Font.Height; int maxWidth = Width; using (Graphics g = (_autoSizePopup) ? CreateGraphics() : null) { // Text.Trim() allows "1 " to trigger updating the list and matching "1 Universe", where // the match involves "1" and "Universe" separately. (Note that "1 " does not match either // "1" or "Universe".) foreach (object item in ItemFilterer.Invoke(Text.Trim(), Items, ItemDisplayStringAdaptor)) { string label = ItemDisplayStringAdaptor.GetDisplayLabel(item); _listBox.Items.Add(new ItemWrapper(item, label)); if (_autoSizePopup) { maxWidth = Math.Max(maxWidth, MeasureItem(g, label).Width); } } } _listBox.EndUpdate(); _listBox.SelectedIndex = selectedIndex; if (_listBox.Items.Count == 0) { HideList(); } else { int visItems = _listBox.Items.Count; if (visItems > 8) { visItems = 8; } _listBox.Height = (visItems * _listBox.ItemHeight) + 4; switch (BorderStyle) { case BorderStyle.FixedSingle: { _listBox.Height += 2; break; } case BorderStyle.Fixed3D: { _listBox.Height += 4; break; } } if (_autoSizePopup) { bool hasScrollBar = visItems < _listBox.Items.Count; _listBox.Width = maxWidth + (hasScrollBar ? 10 : 0); // in theory this shouldn't be needed } _listBox.RightToLeft = RightToLeft; } }
public void TestGetValidItems() { var options = new DbContextOptionsBuilder <DatabaseContext>().UseInMemoryDatabase("TEST_DATABASE", new InMemoryDatabaseRoot()).Options; using (var context = new DatabaseContext(options)) { var items = new List <Item> { new Item { ItemId = 1, ItemTypeId = ItemType.PointsGroup, ItemPermissionTypeId = ItemPermissionType.Public }, new Item { ItemId = 2, ItemTypeId = ItemType.PointsGroup, ItemPermissionTypeId = ItemPermissionType.Private, }, new Item { ItemId = 3, ItemTypeId = ItemType.PointsGroup, ItemPermissionTypeId = ItemPermissionType.Private }, new Item { ItemId = 4, ItemTypeId = ItemType.PointsGroup, ItemPermissionTypeId = ItemPermissionType.Public, DateDeleted = DateTime.Now } }; var userItems = new List <UserItem> { new UserItem { ItemId = 1, UserId = UserId }, new UserItem { ItemId = 3, UserId = SomeOtherUserId }, new UserItem { ItemId = 4, UserId = UserId } }; context.AddRange(items); context.AddRange(userItems); context.SaveChanges(); var expectedValidItems = new List <Item> { new Item { ItemId = 1, ItemTypeId = ItemType.PointsGroup, ItemPermissionTypeId = ItemPermissionType.Public } }; var itemFilterer = new ItemFilterer(context); var actualValidItems = itemFilterer.GetValidItems(UserId, items); Assert.IsTrue(ListComparer.Compare(actualValidItems, expectedValidItems)); } }