public IActionResult GetAll()
 {
     try {
         _logger.LogInformation("### Controller Rental : get All rental ...");
         IEnumerable <Rental> rentals = _service.GetAll().ToList();
         return(Ok(rentals));
     }
     catch (Exception ex) {
         _logger.LogError(ex.Message);
         return(BadRequest());
     }
 }
Beispiel #2
0
        public void Get_All_Rentals()
        {
            var rentals = new List <Rental>()
            {
                new Rental
                {
                    Id    = 111,
                    Since = DateTime.Now,
                    Until = DateTime.Now
                },
                new Rental
                {
                    Id    = 222,
                    Since = DateTime.Now,
                    Until = DateTime.Now
                },
                new Rental
                {
                    Id    = 333,
                    Since = DateTime.Now,
                    Until = DateTime.Now
                }
            }.AsQueryable();

            var mockDbSet = new Mock <DbSet <Rental> >();

            mockDbSet.As <IQueryable <Rental> >().Setup(p => p.Provider).Returns(rentals.Provider);
            mockDbSet.As <IQueryable <Rental> >().Setup(p => p.Expression).Returns(rentals.Expression);
            mockDbSet.As <IQueryable <Rental> >().Setup(p => p.ElementType).Returns(rentals.ElementType);
            mockDbSet.As <IQueryable <Rental> >().Setup(p => p.GetEnumerator()).Returns(rentals.GetEnumerator);

            var mockContext = new Mock <RentalContext>();

            mockContext.Setup(r => r.Rentals).Returns(mockDbSet.Object);

            var service = new RentalService(mockContext.Object);
            var rental  = service.GetAll();

            rental.Should().HaveCount(3);
            rental.Should().Contain(r => r.Id == 111);
            rental.Should().Contain(r => r.Id == 222);
            rental.Should().Contain(r => r.Id == 333);
        }
Beispiel #3
0
        public IActionResult GetAll()
        {
            int customerId = (int)ControllerContext.RouteData.Values["CustomerId"];

            return(Ok(_service.GetAll(customerId)));
        }