public IActionResult GetBike(int rentPointId, int id) { var bike = bikesRepository.GetOne(id); if (bike is null || bike.RentPointId != rentPointId) { return(NotFound()); } return(Ok(bike)); }
public void GetOneBikeTest() { var bikes = new List <Bike> { new Bike { Id = 1, Description = "Montain", Price = 20, Disponible = true, Image = "123456", RentPointId = 1 }, new Bike { Id = 2, Description = "Street", Price = 25, Disponible = true, Image = "1234", RentPointId = 1 }, }.AsQueryable(); var mockSet = new Mock <DbSet <Bike> >(); mockSet.As <IQueryable <Bike> >().SetupGet(m => m.Provider).Returns(bikes.Provider); mockSet.As <IQueryable <Bike> >().SetupGet(m => m.Expression).Returns(bikes.Expression); mockSet.As <IQueryable <Bike> >().SetupGet(m => m.ElementType).Returns(bikes.ElementType); mockSet.As <IQueryable <Bike> >().Setup(m => m.GetEnumerator()).Returns(bikes.GetEnumerator()); var mockContext = new Mock <CyclepathDbContext>(); mockContext.Setup(c => c.Bikes).Returns(mockSet.Object); var service = new BikeRepository(mockContext.Object); Bike bike = service.GetOne(2); var expected = bikes.ToList()[1]; Assert.AreEqual(expected.Description, bike.Description); }