public void TestGetAllCars() { Mock <IRepository <Cars> > mockedRepo = new Mock <IRepository <Cars> > (MockBehavior.Loose); List <Cars> cars = new List <Cars> { new Cars() { Make = "Audi", Model = "A5" }, new Cars() { Make = "Ford", Model = "Mondeo" }, new Cars() { Make = "Suzuki", Model = "Swift" }, new Cars() { Make = "VW", Model = "Transporter" } }; List <Cars> expectedCars = new List <Cars>() { new Cars() { Make = "Audi", Model = "A5" }, new Cars() { Make = "Ford", Model = "Mondeo" }, new Cars() { Make = "Suzuki", Model = "Swift" }, new Cars() { Make = "VW", Model = "Transporter" } }; mockedRepo.Setup(repo => repo.Print()).Returns(cars.AsQueryable()); CarsLogic logic = new CarsLogic(mockedRepo.Object); //Act var result = logic.PrintCars(); //Assert Assert.That(result.Count, Is.EqualTo(expectedCars.Count)); Assert.That(result, Is.EquivalentTo(expectedCars)); //Verify mockedRepo.Verify(repo => repo.Print(), Times.Once); }
public IQueryable <Cars> PrintCars() { return(cLogic.PrintCars()); }
public IActionResult ListCars() { return(View(carsLogic.PrintCars())); }