public void SortCarsByManufacturerAndModelDescending() { var data = new List <Car> { new Car { Manufacturer = "ManufacturerA", Model = "CarA" }, new Car { Manufacturer = "ManufacturerB", Model = "CarB" }, new Car { Manufacturer = "ManufacturerB", Model = "CarA", }, }.AsQueryable(); var mockSet = new Mock <DbSet <Car> >(); mockSet.As <IQueryable <Car> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Car> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Car> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Car> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <CarDealershipContext>(); mockContext.Setup(m => m.Cars).Returns(mockSet.Object); var service = new CarBusiness(mockContext.Object); var SortedCars = service.SortCarsByManufacturerAndModelDescending(); Assert.AreEqual("ManufacturerB", SortedCars[0].Manufacturer); Assert.AreEqual("ManufacturerB", SortedCars[1].Manufacturer); Assert.AreEqual("ManufacturerA", SortedCars[2].Manufacturer); Assert.AreEqual("CarB", SortedCars[0].Model); }
/// <summary> /// Populate the data grid with information sorted by cars' manufacturer and model in descending order /// </summary> private void PopulateDataGridViewSortCarsByManufacturerAndModelDescending() { dataGridView.Rows.Clear(); HideSpecificInfo(); CarBusiness carBusiness = new CarBusiness(); var carsList = carBusiness.SortCarsByManufacturerAndModelDescending(); DataPopulator(carsList); }