public void Test_Contains() { Assert.IsFalse(_view.Contains(-1)); foreach (int item in LIST) { Assert.IsTrue(_view.Contains(item)); } }
public void Contains() { object[] list = { 1, 2, 3, 4, 5, 6 }; var cv = new CollectionView(list); cv.Filter = item => (int)item % 2 == 0; Assert.IsTrue(cv.Contains(4), "A1"); Assert.IsFalse(cv.Contains(3), "A2"); Assert.IsFalse(cv.Contains(98), "A3"); Assert.IsFalse(cv.Contains(99), "A4"); }
public void ContainsTest() { TestClass item = CollectionView[0] as TestClass; // show that items in the Collection will return true. Assert.IsTrue(CollectionView.Contains(item)); // show that items not added to the Collection will return false item = new TestClass(); Assert.IsFalse(CollectionView.Contains(item)); // show that once we add it in, it will return true. MethodInfo mi = SourceCollection.GetType().GetMethod("Insert"); mi.Invoke(SourceCollection, new object[] { 25, item }); Assert.IsTrue(CollectionView.Contains(item)); // now test that with paging, if the item is not on the current page, // it will return false CollectionView.PageSize = 5; Assert.IsFalse(CollectionView.Contains(item)); // now move to the last page where the item is, and verify // that it will now return true CollectionView.MoveToLastPage(); Assert.IsTrue(CollectionView.Contains(item)); }
public void AddItemWithFilterTest() { CollectionView.Filter = this.FilterNegativeNumbers; Assert.AreEqual(25, CollectionView.Count); // verify that because of the filter, after adding the item, // the count will not change and the item won't be in the view. MethodInfo mi = SourceCollection.GetType().GetMethod("Insert"); TestClass newItem = new TestClass() { IntProperty = -1 }; mi.Invoke(SourceCollection, new object[] { 0, newItem }); Assert.AreEqual(25, CollectionView.Count); Assert.IsFalse(CollectionView.Contains(newItem)); // verify that when we have a pagesize set, we will have the same result // since the items should not be inserted into the collection CollectionView.PageSize = 30; newItem = new TestClass() { IntProperty = -1 }; mi.Invoke(SourceCollection, new object[] { 0, newItem }); Assert.AreEqual(25, CollectionView.Count); Assert.IsFalse(CollectionView.Contains(newItem)); }
public void EditItemNotInViewTest() { // if we don't implement IList, we cannot run the rest of // the test as we cannot add/remove items if (this.ImplementsIList) { // test that we can edit an item not in the collection // and that it will get added to the collection upon // calling CommitEdit TestClass item = new TestClass(); Assert.IsFalse(CollectionView.Contains(item)); CollectionView.EditItem(item); CollectionView.CommitEdit(); Assert.IsTrue(CollectionView.Contains(item)); // also, show that when we have paging and call edit item // on an item for a different page, we will still be able // to edit it and move it to the correct location CollectionView.SortDescriptions.Add(new SortDescription("IntProperty", ListSortDirection.Ascending)); item = CollectionView[0] as TestClass; CollectionView.PageSize = 5; CollectionView.MoveToLastPage(); Assert.IsFalse(CollectionView.Contains(item)); CollectionView.EditItem(item); // because of sorting, this item should be moved to the last page // upon commit item.IntProperty = 100; CollectionView.CommitEdit(); Assert.IsTrue(CollectionView.Contains(item)); } }
public void RemoveTest() { // verify the the count gets updated when we remove items TestClass removeItem = CollectionView[0] as TestClass; Assert.AreEqual(25, CollectionView.Count); Assert.IsTrue(CollectionView.Contains(removeItem)); CollectionView.Remove(removeItem); Assert.AreEqual(24, CollectionView.Count); Assert.IsFalse(CollectionView.Contains(removeItem)); // verify that we cannot call Remove/RemoveAt during an Edit CollectionView.EditItem(CollectionView[0]); AssertExpectedException( new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PagedCollectionViewResources.OperationNotAllowedDuringAddOrEdit, "RemoveAt")), delegate { CollectionView.RemoveAt(0); }); // verify that we also cannot call Remove/RemoveAt during an Add CollectionView.AddNew(); AssertExpectedException( new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PagedCollectionViewResources.OperationNotAllowedDuringAddOrEdit, "RemoveAt")), delegate { CollectionView.RemoveAt(0); }); }
public ChatWindowViewModel(ChatWindowViewModelSettings settings, List <TranslationEngine> translationEngines, List <ChatMsgType> allChatCodes, HotKeyManager hotKeyManager) { this._AsyncPropertyChanged = new AsyncEvent <AsyncPropertyChangedEventArgs>(this.EventErrorHandler, "ChatWindowViewModel \n AsyncPropertyChanged"); this._RequestChatClear = new AsyncEvent <TatruEventArgs>(this.EventErrorHandler, "ChatWindowViewModel \n RequsetChatClear"); ShowChatWindowCommand = new TataruUICommand(ShowChatWindow); RestChatWindowPositionCommand = new TataruUICommand(ResetChatWindowPosition); _IsWindowVisible = true; Name = settings.Name; _WinId = settings.WinId; ChatFontSize = settings.ChatFontSize; LineBreakHeight = settings.LineBreakHeight; SpacingCount = settings.SpacingCount; IsAlwaysOnTop = settings.IsAlwaysOnTop; IsClickThrough = settings.IsClickThrough; IsAutoHide = settings.IsAutoHide; AutoHideTimeout = settings.AutoHideTimeout; IsHiddenByUser = false; BackGroundColor = settings.BackGroundColor; TranslationEngines = new CollectionView(translationEngines); var tmpEngine = translationEngines.FirstOrDefault(x => x.EngineName == settings.TranslationEngineName); TranslationEngines.MoveCurrentToFirst(); if (tmpEngine != null) { if (TranslationEngines.Contains(tmpEngine)) { TranslationEngines.MoveCurrentTo(tmpEngine); } else { TranslationEngines.MoveCurrentToFirst(); } } OnTranslationEngineChange(this, null); TrySetLangugue(_TranslateFromLanguagues, settings.FromLanguague); TrySetLangugue(_TranslateToLanguagues, settings.ToLanguague); ChatWindowRectangle = settings.ChatWindowRectangle; ChatCodes = LoadChatCodes(settings.ChatCodes, allChatCodes); _HotKeyManager = hotKeyManager; ShowHideChatKeys = new HotKeyCombination(settings.ShowHideChatKeys); ClickThoughtChatKeys = new HotKeyCombination(settings.ClickThoughtChatKeys); ClearChatKeys = new HotKeyCombination(settings.ClearChatKeys); _HotKeyManager.GlobalHotKeyPressed += OnGlobalHotKeyPressed; }
public void InsertAndRemoveGroupsTest() { // if we don't implement IList, we cannot run the rest of // the test as we cannot add/remove items if (this.ImplementsIList) { // set group description and verify that the items get grouped in this order CollectionView.GroupDescriptions.Add(new PropertyGroupDescription("StringProperty")); // currently there should be groups "A" and "B" Assert.AreEqual(2, CollectionView.Groups.Count); // insert a new item and verify that a new group is created TestClass newItem = CollectionView.AddNew() as TestClass; newItem.StringProperty = "C"; CollectionView.CommitNew(); // verify that we now have an additional group and that it appears at the end Assert.AreEqual(3, CollectionView.Groups.Count); Assert.AreEqual(25, CollectionView.IndexOf(newItem)); // now remove that item (since it is the only one in its group) and verify that // the group is removed CollectionView.Remove(newItem); Assert.AreEqual(2, CollectionView.Groups.Count); Assert.IsFalse(CollectionView.Contains(newItem)); } }
private void TrySetLangugue(CollectionView collection, TranslatorLanguague languague) { if (languague == null) { collection.MoveCurrentToFirst(); } else { if (collection.Contains(languague)) { collection.MoveCurrentTo(languague); } else { collection.MoveCurrentToFirst(); } } }
public void CurrencyWithChangedPageSize() { // add a pagesize and set currency CollectionView.PageSize = 5; CollectionView.MoveCurrentToLast(); Assert.IsTrue(CollectionView.Contains(CollectionView.CurrentItem)); Assert.AreEqual(4, CollectionView.CurrentPosition); TestClass item = CollectionView.CurrentItem as TestClass; // change the pagesize and verify that currency has changed to the // first item since the item that had currency is no longer in the view CollectionView.PageSize = 4; Assert.IsTrue(CollectionView.Contains(CollectionView.CurrentItem)); Assert.AreEqual(0, CollectionView.CurrentPosition); Assert.IsFalse(CollectionView.Contains(item)); // now move currency to the last item again and set the pagesize to // a larger value CollectionView.MoveCurrentToLast(); Assert.AreEqual(3, CollectionView.CurrentPosition); item = CollectionView.CurrentItem as TestClass; CollectionView.PageSize = 10; // verify that the currency stayed on that item, since it was still // in the view Assert.AreEqual(3, CollectionView.CurrentPosition); Assert.IsTrue(CollectionView.Contains(item)); // set currency to after last and change page size to verify that it // will stay after last CollectionView.MoveCurrentToPosition(CollectionView.Count); Assert.IsTrue(CollectionView.IsCurrentAfterLast); Assert.AreEqual(10, CollectionView.CurrentPosition); CollectionView.PageSize = 5; // verify that it is still after last Assert.IsTrue(CollectionView.IsCurrentAfterLast); Assert.AreEqual(5, CollectionView.CurrentPosition); }
/// <summary> /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"/> contains a specific value. /// </summary> /// <returns> /// true if <paramref name="item"/> is found in the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false. /// </returns> /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param> public bool Contains(T item) { return(CollectionView.Contains(item)); }
public void AddItemWithPagingTest() { // verify that when we do not have sorting or grouping, when an item // is inserted, we will respect the index specified by the event. CollectionView.PageSize = 5; Assert.AreEqual(5, CollectionView.Count); MethodInfo mi = SourceCollection.GetType().GetMethod("Insert"); TestClass newItem = new TestClass() { IntProperty = 6 }; mi.Invoke(SourceCollection, new object[] { 1, newItem }); Assert.AreEqual(1, CollectionView.IndexOf(newItem)); Assert.AreEqual(5, CollectionView.Count); // however, if that index is beyond what the current page is showing, // it will not be present in the view newItem = new TestClass() { IntProperty = 6 }; mi.Invoke(SourceCollection, new object[] { 10, newItem }); Assert.IsFalse(CollectionView.Contains(newItem)); // now add sorting CollectionView.SortDescriptions.Add(new SortDescription("IntProperty", ListSortDirection.Ascending)); // verify that if we insert into the current page, the last item will be // pushed off TestClass lastItem = CollectionView[4] as TestClass; Assert.IsTrue(CollectionView.Contains(lastItem)); newItem = new TestClass() { IntProperty = 0 }; mi.Invoke(SourceCollection, new object[] { 0, newItem }); Assert.AreEqual(0, CollectionView.IndexOf(newItem)); Assert.IsFalse(CollectionView.Contains(lastItem)); // also in this case, if the sorting pushes the item to a different // page, it will not be displayed newItem = new TestClass() { IntProperty = 2 }; mi.Invoke(SourceCollection, new object[] { 20, newItem }); Assert.IsFalse(CollectionView.Contains(newItem)); // now add grouping - because of paging, only two of the groups will // be currently displayed (0 and 1). CollectionView.GroupDescriptions.Add(new PropertyGroupDescription("IntProperty")); Assert.AreEqual(2, CollectionView.Groups.Count); // add an item in the first group and verify that the last item in the // second group gets pushed off newItem = new TestClass() { IntProperty = 0 }; Assert.AreEqual(1, (CollectionView.Groups[0] as CollectionViewGroup).Items.Count); Assert.AreEqual(4, (CollectionView.Groups[1] as CollectionViewGroup).Items.Count); mi.Invoke(SourceCollection, new object[] { 0, newItem }); Assert.AreEqual(2, (CollectionView.Groups[0] as CollectionViewGroup).Items.Count); Assert.AreEqual(3, (CollectionView.Groups[1] as CollectionViewGroup).Items.Count); // again add an item into another page beyond the current one and verify that // the items remain unchanged newItem = new TestClass() { IntProperty = 6 }; Assert.AreEqual(2, (CollectionView.Groups[0] as CollectionViewGroup).Items.Count); Assert.AreEqual(3, (CollectionView.Groups[1] as CollectionViewGroup).Items.Count); mi.Invoke(SourceCollection, new object[] { 0, newItem }); Assert.AreEqual(2, (CollectionView.Groups[0] as CollectionViewGroup).Items.Count); Assert.AreEqual(3, (CollectionView.Groups[1] as CollectionViewGroup).Items.Count); // move to the last page and add an item in an earlier group to // verify that an item gets pushed up into this page CollectionView.MoveToLastPage(); Assert.AreEqual(1, (CollectionView.Groups[0] as CollectionViewGroup).Items.Count); newItem = new TestClass() { IntProperty = 2 }; mi.Invoke(SourceCollection, new object[] { 0, newItem }); Assert.AreEqual(2, (CollectionView.Groups[0] as CollectionViewGroup).Items.Count); }
public void FilteredEditItemTest() { // apply a filter to the CollectionView CollectionView.Filter = FilterNegativeNumbers; Assert.AreEqual(25, CollectionView.Count); // edit the item and set the IntProperty to a negative // number. before we commit, it should stay in the view TestClass editItem = CollectionView[0] as TestClass; CollectionView.MoveCurrentTo(editItem); CollectionView.EditItem(editItem); editItem.IntProperty = -1; Assert.AreEqual(25, CollectionView.Count); Assert.IsTrue(CollectionView.Contains(editItem)); // now commit to verify that it gets filtered out of the view // also verify that the correct events get fired _expectedEventQueue.Clear(); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanging" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CollectionChanged", Parameter = "Remove" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanged" }); CollectionView.CommitEdit(); Assert.AreEqual(0, _expectedEventQueue.Count); Assert.AreEqual(24, CollectionView.Count); Assert.IsFalse(CollectionView.Contains(editItem)); // verify that the currency has moved to a different item Assert.AreEqual(0, CollectionView.CurrentPosition); Assert.AreNotEqual(editItem, CollectionView.CurrentItem); // try adding paging and run through the same test // the only differnce should be that we add in a new item // to replace the one that got filtered out of the current page CollectionView.PageSize = 5; editItem = CollectionView[0] as TestClass; CollectionView.MoveCurrentTo(editItem); CollectionView.EditItem(editItem); editItem.IntProperty = -1; Assert.AreEqual(5, CollectionView.Count); Assert.IsTrue(CollectionView.Contains(editItem)); // now commit to verify that it gets filtered out of the view // also verify that the correct events get fired _expectedEventQueue.Clear(); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanging" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CollectionChanged", Parameter = "Remove" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CollectionChanged", Parameter = "Add" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanged" }); CollectionView.CommitEdit(); Assert.AreEqual(0, _expectedEventQueue.Count); Assert.AreEqual(5, CollectionView.Count); Assert.IsFalse(CollectionView.Contains(editItem)); // also, try this on the last page to verify that a new item is not brought in CollectionView.MoveToLastPage(); editItem = CollectionView[0] as TestClass; CollectionView.MoveCurrentTo(editItem); CollectionView.EditItem(editItem); editItem.IntProperty = -1; Assert.AreEqual(3, CollectionView.Count); Assert.IsTrue(CollectionView.Contains(editItem)); // now commit to verify that it gets filtered out of the view // also verify that the correct events get fired _expectedEventQueue.Clear(); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanging" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CollectionChanged", Parameter = "Remove" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanged" }); CollectionView.CommitEdit(); Assert.AreEqual(0, _expectedEventQueue.Count); Assert.AreEqual(2, CollectionView.Count); Assert.IsFalse(CollectionView.Contains(editItem)); // now add grouping, move to the first page, and run // through the scenario again CollectionView.GroupDescriptions.Add(new PropertyGroupDescription("IntProperty")); CollectionView.MoveToFirstPage(); editItem = CollectionView[0] as TestClass; CollectionView.MoveCurrentTo(editItem); CollectionView.EditItem(editItem); editItem.IntProperty = -1; Assert.AreEqual(5, CollectionView.Count); Assert.IsTrue(CollectionView.Contains(editItem)); // now commit to verify that it gets filtered out of the view // also verify that the correct events get fired _expectedEventQueue.Clear(); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanging" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CollectionChanged", Parameter = "Remove" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CollectionChanged", Parameter = "Add" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanged" }); CollectionView.CommitEdit(); Assert.AreEqual(0, _expectedEventQueue.Count); Assert.AreEqual(5, CollectionView.Count); Assert.IsFalse(CollectionView.Contains(editItem)); // now try the same thing on the last page. since it // only has one item, once it gets filtered out, we // should move to the previous page CollectionView.MoveToLastPage(); Assert.AreEqual(4, CollectionView.PageIndex); editItem = CollectionView[0] as TestClass; CollectionView.MoveCurrentTo(editItem); CollectionView.EditItem(editItem); editItem.IntProperty = -1; Assert.AreEqual(1, CollectionView.Count); Assert.IsTrue(CollectionView.Contains(editItem)); // now commit to verify that it gets filtered out of the view // also verify that the correct events get fired _expectedEventQueue.Clear(); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanging" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CollectionChanged", Parameter = "Remove" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanging" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CollectionChanged", Parameter = "Reset" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanged" }); CollectionView.CommitEdit(); Assert.AreEqual(0, _expectedEventQueue.Count); Assert.AreEqual(5, CollectionView.Count); Assert.IsFalse(CollectionView.Contains(editItem)); // now try the same thing on the last page. we should get // a remove event, but not an add editItem = CollectionView[0] as TestClass; CollectionView.MoveCurrentTo(editItem); CollectionView.EditItem(editItem); editItem.IntProperty = -1; Assert.AreEqual(5, CollectionView.Count); Assert.IsTrue(CollectionView.Contains(editItem)); // now commit to verify that it gets filtered out of the view // also verify that the correct events get fired _expectedEventQueue.Clear(); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanging" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CollectionChanged", Parameter = "Remove" }); _expectedEventQueue.Add(new EventNotification() { EventType = "CurrentChanged" }); CollectionView.CommitEdit(); Assert.AreEqual(0, _expectedEventQueue.Count); Assert.AreEqual(4, CollectionView.Count); Assert.IsFalse(CollectionView.Contains(editItem)); // now verify that even if the item is filtered out, we can // still edit it, and that if we change the value so that // we pass the filter, we would display it again CollectionView.SortDescriptions.Add(new SortDescription("IntProperty", ListSortDirection.Ascending)); CollectionView.MoveToLastPage(); Assert.IsFalse(CollectionView.Contains(editItem)); CollectionView.EditItem(editItem); editItem.IntProperty = 10; CollectionView.CommitEdit(); Assert.IsTrue(CollectionView.Contains(editItem)); }
public void ContainsFilter () { CollectionView c = new CollectionView (new object [] { -1, 1 }); c.Filter = ContainsFilterFilter; Assert.IsFalse (c.Contains (null), "1"); Assert.IsTrue (c.Contains (1), "2"); Assert.IsFalse (c.Contains (2), "3"); Assert.IsFalse (c.Contains (-1), "4"); }
public void ContainsFilterNull () { CollectionView c = new CollectionView (new object [] { 1 }); Assert.IsFalse (c.Contains (null), "1"); Assert.IsTrue (c.Contains (1), "2"); Assert.IsFalse (c.Contains (2), "3"); }