Esempio n. 1
0
        public void GetRentpointTest()
        {
            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
                },
                new Bike
                {
                    Id          = 2,
                    Description = "Garden",
                    Price       = 30,
                    Disponible  = true,
                    Image       = "25649",
                    RentPointId = 2
                },
            }.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);

            var rentPoints = service.GetRentPointBikes(1).ToList();

            Assert.AreEqual(2, rentPoints.Count);
            Assert.AreEqual("Montain", rentPoints[0].Description);
            Assert.AreEqual("Street", rentPoints[1].Description);
        }
Esempio n. 2
0
 public IEnumerable <Bike> GetBikesFromRentPoint(int rentPointId)
 {
     return(bikesRepository.GetRentPointBikes(rentPointId));
 }