//Get logic// //Sort logic// /// <summary> /// Populate the data grid with information sorted by cars' dealership name in ascending order /// </summary> private void PopulateDataGridViewSortCarsByDealershipNameAscending() { dataGridView.Rows.Clear(); HideSpecificInfo(); CarBusiness carBusiness = new CarBusiness(); var carsList = carBusiness.SortCarsByDealershipNameAscending(); DataPopulator(carsList); }
public void SortCarsByDealershipNameAscending() { var data = new List <Car> { new Car { Model = "Car1", CarDealership = new CarDealership { Name = "NameA" } }, new Car { Model = "Car2", CarDealership = new CarDealership { Name = "NameB" } }, new Car { Model = "Car3", CarDealership = new CarDealership { Name = "NameC" } }, }.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.SortCarsByDealershipNameAscending(); Assert.AreEqual("NameA", SortedCars[0].CarDealership.Name); Assert.AreEqual("NameB", SortedCars[1].CarDealership.Name); Assert.AreEqual("NameC", SortedCars[2].CarDealership.Name); }