/// <summary> /// Populate the data grid with information sorted by cars' power in ascending order /// </summary> private void PopulateDataGridViewSortCarsByPowerAscending() { dataGridView.Rows.Clear(); HideSpecificInfo(); CarBusiness carBusiness = new CarBusiness(); var carsList = carBusiness.SortCarsByPowerAscending(); DataPopulator(carsList); dataGridView.Columns[5].Visible = true; }
public void SortCarsByPowerAscending() { var data = new List <Car> { new Car { Engine = new Engine { Power = 100 } }, new Car { Engine = new Engine { Power = 120 } }, new Car { Engine = new Engine { Power = 140 } } }.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.SortCarsByPowerAscending(); Assert.AreEqual(100, SortedCars[0].Engine.Power); Assert.AreEqual(120, SortedCars[1].Engine.Power); Assert.AreEqual(140, SortedCars[2].Engine.Power); }