/// <summary> /// Populate the data grid with information about cars with given fuel type /// </summary> private void PopulateDataGridViewGetCarsByFuelType() { dataGridView.Rows.Clear(); HideSpecificInfo(); CarBusiness carBusiness = new CarBusiness(); var carsList = carBusiness.GetCarsByFuelType(FuelBGTtoENG(txtGet.Text)); DataPopulator(carsList); dataGridView.Columns[7].Visible = true; }
public void GetCarsByFuelType() { var data = new List <Car> { new Car { Model = "Car1", Engine = new Engine { FuelType = "Diesel" } }, new Car { Model = "Car2", Engine = new Engine { FuelType = "Gasoline" } }, new Car { Model = "Car3", Engine = new Engine { FuelType = "Electricity" } }, new Car { Model = "Car4", Engine = new Engine { FuelType = "Diesel" } } }.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 CarsFound = service.GetCarsByFuelType("Diesel"); Assert.AreEqual(2, CarsFound.Count()); Assert.AreEqual("Car1", CarsFound[0].Model); Assert.AreEqual("Car4", CarsFound[1].Model); }