public void SortCarsByTransmissionGearsAscending() { var data = new List <Car> { new Car { Model = "Car1", TransmissionGears = 5 }, new Car { Model = "Car2", TransmissionGears = 6 }, new Car { Model = "Car3", TransmissionGears = 7 }, }.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.SortCarsByTransmissionGearsAscending(); Assert.AreEqual(5, SortedCars[0].TransmissionGears); Assert.AreEqual(6, SortedCars[1].TransmissionGears); Assert.AreEqual(7, SortedCars[2].TransmissionGears); }
/// <summary> /// Populate the data grid with information sorted by cars' number of gears in ascending order /// </summary> private void PopulateDataGridViewSortCarsByTransmissionGearsAscending() { dataGridView.Rows.Clear(); HideSpecificInfo(); CarBusiness carBusiness = new CarBusiness(); var carsList = carBusiness.SortCarsByTransmissionGearsAscending(); DataPopulator(carsList); }