public void TestSorting(bool isAscending, SortingMode sortingColumn, bool expected) { var dateTime = DateTime.UtcNow; var firstFileViewModel = _autoMocker.CreateInstance <FileViewModel>(); firstFileViewModel.Name = "Program"; firstFileViewModel.Extension = "cs"; firstFileViewModel.Size = 1024; firstFileViewModel.LastModifiedDateTime = dateTime; var secondFileViewModel = _autoMocker.CreateInstance <FileViewModel>(); secondFileViewModel.Name = "module"; secondFileViewModel.Extension = "js"; secondFileViewModel.Size = 2048; secondFileViewModel.LastModifiedDateTime = dateTime.AddDays(1); var comparer = new FileViewModelsComparer(isAscending, sortingColumn); var result = comparer.Compare(firstFileViewModel, secondFileViewModel); Assert.Equal(expected, result > 0); result = comparer.Compare(secondFileViewModel, firstFileViewModel); Assert.Equal(expected, result < 0); }
public void TestThrows() { var comparer = new FileViewModelsComparer(false, (SortingMode)42); var firstFileViewModel = _autoMocker.CreateInstance <FileViewModel>(); var secondFileViewModel = _autoMocker.CreateInstance <FileViewModel>(); void Compare() => comparer.Compare(firstFileViewModel, secondFileViewModel); Assert.Throws <ArgumentOutOfRangeException>(Compare); }
public int Compare(IFileSystemNodeViewModel x, IFileSystemNodeViewModel y) => (x, y) switch { (FileViewModel a, FileViewModel b) => _filesComparer.Compare(a, b), (DirectoryViewModel a, DirectoryViewModel b) => _directoriesComparer.Compare(a, b), (FileViewModel _, DirectoryViewModel _) => 1, (DirectoryViewModel _, FileViewModel _) => - 1, _ => throw new InvalidOperationException() }; }