Cars.Controllers.CarsController.Sort C# (CSharp) Method

Sort() public method

public Sort ( string parameter ) : IView
parameter string
return IView
        public IView Sort(string parameter)
        {
            ICollection<Car> result = null;

            switch (parameter)
            {
                case "make": 
                    result = this.carsData.SortedByMake(); 
                    break;
                case "year": 
                    result = this.carsData.SortedByYear(); 
                    break;
                default: throw new ArgumentException("Invalid sorting parameter");
            }

            return new View(result);
        }
    }

Usage Example

 public void ExpectCarsRepositoryToSortByYear()
 {
     var mockCarsCollection = new Mock<ICollection<Car>>();
     var mockCarsRepository = new Mock<ICarsRepository>();
     mockCarsRepository.Setup(cr => cr.SortedByYear()).Returns(mockCarsCollection.Object);
     var carsController = new CarsController(mockCarsRepository.Object);
     var result = carsController.Sort("year");
     Assert.IsTrue(result.Model.Equals(mockCarsCollection.Object));
 }
All Usage Examples Of Cars.Controllers.CarsController::Sort