public void Find_should_return_null_for_non_registered_type() { var customComparers = new CustomComparers(); var comparer = customComparers.Find(typeof(Foo)); Assert.IsNull(comparer); }
public void IsRegisteredFor_should_return_true_for_registered_type() { var customComparers = new CustomComparers(); customComparers.Register <Foo>((x, y) => x.Value.CompareTo(y.Value)); Comparison comparer = customComparers.Find(typeof(Foo)); Assert.IsNotNull(comparer); }
public void Equals_ok(int foo1, int foo2, int expectedSign) { var customComparers = new CustomComparers(); customComparers.Register <Foo>((x, y) => x.Value.CompareTo(y.Value)); Comparison comparer = customComparers.Find(typeof(Foo)); int actualSign = comparer(new Foo(foo1), new Foo(foo2)); Assert.AreEqual(expectedSign, actualSign, (x, y) => Math.Sign(x) == Math.Sign(y)); }
public void Register_and_unregister_ok() { var customComparers = new CustomComparers(); customComparers.Register <Foo>((x, y) => x.Value.CompareTo(y.Value)); customComparers.Unregister <Foo>(); var comparer = customComparers.Find(typeof(Foo)); Assert.IsNull(comparer); }
public void IsRegisteredFor_should_return_true_for_registered_type() { var customComparers = new CustomComparers(); customComparers.Register<Foo>((x, y) => x.Value.CompareTo(y.Value)); Comparison comparer = customComparers.Find(typeof(Foo)); Assert.IsNotNull(comparer); }
public void Find_with_null_type_should_throw_exception() { var customComparers = new CustomComparers(); customComparers.Find(null); }
public void Generic_Registers_with_null_comparer_should_throw_exception() { var customComparers = new CustomComparers(); customComparers.Register <Foo>(null); }
public void Registers_with_null_comparer_should_throw_exception() { var customComparers = new CustomComparers(); customComparers.Register(typeof(Foo), null); }
public void Registers_with_null_type_should_throw_exception() { var customComparers = new CustomComparers(); customComparers.Register(null, (x, y) => 0); }
public void Setup() { var customComparers = new CustomComparers(); customComparers.UnregisterAll(); }
public void Unregister_with_null_type_should_throw_exception() { var customComparers = new CustomComparers(); customComparers.Unregister(null); }
public void Register_and_unregister_ok() { var customComparers = new CustomComparers(); customComparers.Register<Foo>((x, y) => x.Value.CompareTo(y.Value)); customComparers.Unregister<Foo>(); var comparer = customComparers.Find(typeof(Foo)); Assert.IsNull(comparer); }
public void Generic_Registers_with_null_comparer_should_throw_exception() { var customComparers = new CustomComparers(); customComparers.Register<Foo>(null); }
/// <summary> /// Sorts on the specified column (0 based index). /// Specify a sortOrder of None to let the sort direction be chosen automatically /// (toggles the current sort direction if already sorted on tha same column). /// </summary> public void Sort(int colIndex, SortOrder sortOrder = SortOrder.None) { try { IsSorting = true; // If the sort column has changed, force ascending sort. // Otherwise, toggle the sort order. if (_col == colIndex) { // Sorting same column again. Toggle the sort order. _sortAscending = !_sortAscending; } else { // Sorting a different column. Use ascending sort // and switch to the appropriate RowComparer for the column. _sortAscending = true; _col = colIndex; if (!CustomComparers.TryGetValue(_listView.Columns[_col], out _comparer)) { _comparer = _defaultComparer; } } switch (sortOrder) { case SortOrder.None: break; case SortOrder.Ascending: _sortAscending = true; break; case SortOrder.Descending: _sortAscending = false; break; } // The list view tends to sort automatically when // ListView.Sorting or ListView.ListViewItemSorter changes. // It's a little unpredictable, so we use _didSort to keep // track of whether the sort occurs or not to avoid // unnecessary sorting. Comparer sets it to true. _didSort = false; // Always set _listView.Sorting because some users set it // to None between sorts to cause new items to appear // at the bottom. // This sometimes initiates the sort, setting _didSort to true. if (_sortAscending) { _listView.Sorting = SortOrder.Ascending; } else { _listView.Sorting = SortOrder.Descending; } _listView.SetSortIcon(colIndex, _listView.Sorting); // This assignment sometimes initiates the sort, like it or not. _listView.ListViewItemSorter = this; // Avoid re-sorting unnecessarily, but make sure // it happens at least once. if (!_didSort) { // This results in multiple calls to Compare(). _listView.Sort(); } } finally { IsSorting = false; } } // Sort
public void Equals_ok(int foo1, int foo2, int expectedSign) { var customComparers = new CustomComparers(); customComparers.Register<Foo>((x, y) => x.Value.CompareTo(y.Value)); Comparison comparer = customComparers.Find(typeof(Foo)); int actualSign = comparer(new Foo(foo1), new Foo(foo2)); Assert.AreEqual(expectedSign, actualSign, (x, y) => Math.Sign(x) == Math.Sign(y)); }