public void SourceRemoveItemWithFilteringAndSorting() { var items = new ObservableCollection <TestModel>() { new TestModel("Beryle Blackbourn", 20), new TestModel("Andrei Epps", 9), new TestModel("Chelsey MacCaig", 47), new TestModel("Dotty Andreopolos", 9), new TestModel("Jemmie Chesshire", 36), }; var cvs = new Rotorsoft.Forms.CollectionViewSource(); cvs.Source = items; cvs.Filter = (item) => (item as TestModel).Score > 15; cvs.SortDescriptions = new ObservableCollection <SortDescription>() { new SortDescription(nameof(TestModel.Score), ListSortDirection.Descending), }; items.RemoveAt(2); Assert.Equal(2, cvs.View.Count()); Assert.Equal("Jemmie Chesshire", cvs.View.GetItemAt <TestModel>(0).Name); Assert.Equal("Beryle Blackbourn", cvs.View.GetItemAt <TestModel>(1).Name); }
public void Constructor() { var cvs = new Rotorsoft.Forms.CollectionViewSource(); Assert.Null(cvs.Source); Assert.Null(cvs.View); Assert.Null(cvs.Filter); Assert.Empty(cvs.SortDescriptions); }
public void SortDescriptionsAddWithEnumerable() { var items = new TestEnumerable(new TestModel[0]); var cvs = new Rotorsoft.Forms.CollectionViewSource(); cvs.Source = items; cvs.SortDescriptions = new ObservableCollection <SortDescription>(); Assert.Throws <InvalidOperationException>(() => cvs.SortDescriptions.Add(new SortDescription(nameof(TestModel.Name), ListSortDirection.Ascending))); }
public void SourceWithNonEmptyList() { var items = new List <object>() { "Lorem Ipsum" }; var cvs = new Rotorsoft.Forms.CollectionViewSource(); cvs.Source = items; Assert.Same(items, cvs.Source); Assert.NotNull(cvs.View); Assert.NotEmpty(cvs.View); }
public void SourceWithNonEmptyEnumerable() { var items = new TestEnumerable(new object[] { "Lorem Ipsum" }); var cvs = new Rotorsoft.Forms.CollectionViewSource(); cvs.Source = items; Assert.Same(items, cvs.Source); Assert.NotNull(cvs.View); Assert.NotEmpty(cvs.View); }
public void SourceWithEmptyList() { var cvs = new Rotorsoft.Forms.CollectionViewSource(); cvs.Source = new List <object>(); Assert.NotNull(cvs.Source); Assert.Empty(cvs.Source); Assert.NotNull(cvs.View); Assert.Empty(cvs.View); Assert.True(cvs.View.CanFilter); Assert.True(cvs.View.CanSort); Assert.False(cvs.View.CanGroup); }
public void SortDescriptionsAddSingleDescending() { var items = new List <TestModel>() { new TestModel("Beryle Blackbourn", 20), new TestModel("Andrei Epps", 9), new TestModel("Chelsey MacCaig", 47), new TestModel("Dotty Andreopolos", 9), new TestModel("Jemmie Chesshire", 36), }; var cvs = new Rotorsoft.Forms.CollectionViewSource(); cvs.Source = items; cvs.SortDescriptions = new ObservableCollection <SortDescription>(); cvs.SortDescriptions.Add(new SortDescription(nameof(TestModel.Score), ListSortDirection.Descending)); Assert.Equal(47, cvs.View.GetItemAt <TestModel>(0).Score); Assert.Equal(9, cvs.View.GetItemAt <TestModel>(4).Score); }
public void FilterWithEnumerable() { var items = new TestEnumerable(new object[] { 10, "Lorem Ipsum", TimeSpan.Zero, }); Predicate <object> filterPredicate = (item) => item is string; var cvs = new Rotorsoft.Forms.CollectionViewSource(); cvs.Source = items; cvs.Filter = filterPredicate; Assert.Same(filterPredicate, cvs.Filter); Assert.NotNull(cvs.View); Assert.NotEmpty(cvs.View); Assert.Equal(1, cvs.View.Count()); }
public void RemoveFilter() { var items = new List <object>() { 10, "Lorem Ipsum", TimeSpan.Zero, }; Predicate <object> filterPredicate = (item) => item is string; var cvs = new Rotorsoft.Forms.CollectionViewSource(); cvs.Source = items; cvs.Filter = filterPredicate; Assert.Equal(1, cvs.View.Count()); cvs.Filter = null; Assert.Equal(3, cvs.View.Count()); }