public void ValidGetByIdShouldReturnSelectedHotel()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetByIdShouldReturnSelectedHotel))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var hotelService = new ReviewService(context);
                var controller   = new HotelsController(hotelService);

                Hotel hotel2 = new Hotel
                {
                    Id        = 1,
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                Hotel hotel1 = new Hotel
                {
                    Id        = 2,
                    HotelName = "Belvedere Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                hotelService.Create(hotel1);
                hotelService.Create(hotel2);

                context.Entry(hotel1).State = EntityState.Detached;
                context.Entry(hotel2).State = EntityState.Detached;

                var response = controller.GetHotelById(1);

                var contentResult = response as Hotel;

                Assert.IsNotNull(contentResult);
                Assert.AreEqual("Transilvania Hotel", contentResult.HotelName);
            }
        }
        public void ValidGetHotelsShouldListAll()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetHotelsShouldListAll))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var hotelService = new ReviewService(context);
                var controller   = new HotelsController(hotelService);

                Hotel hotel2 = new Hotel
                {
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                Hotel hotel1 = new Hotel
                {
                    HotelName = "Belvedere Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                controller.PostHotel(hotel1);
                controller.PostHotel(hotel2);

                context.Entry(hotel1).State = EntityState.Detached;
                context.Entry(hotel2).State = EntityState.Detached;

                Assert.AreEqual(hotelService.GetHotels().Count(), 2);

                IActionResult actionResult  = controller.GetHotels();
                var           createdResult = actionResult as OkObjectResult;

                Assert.IsNotNull(createdResult);
                Assert.AreEqual(200, createdResult.StatusCode);
            }
        }
        public void ValidGetHotelsShouldListAll()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetHotelsShouldListAll))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var hotelService = new ReviewService(context);

                Hotel hotel2 = new Hotel
                {
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                Hotel hotel1 = new Hotel
                {
                    HotelName = "Belvedere Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                hotelService.Create(hotel1);
                hotelService.Create(hotel2);

                context.Entry(hotel1).State = EntityState.Detached;
                context.Entry(hotel2).State = EntityState.Detached;

                Assert.AreEqual(hotelService.GetHotels().Count(), 2);
            }
        }
        public IActionResult PutReview(long id, [FromBody] Review review)
        {
            if (id != review.Id)
            {
                return(BadRequest());
            }

            _context.Entry(review).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReviewExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public void DeleteById_IdNotFound()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteById_IdNotFound))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var controller = new ReviewsController(context);

                Review review = new Review
                {
                    HotelId = 1,
                    UserId  = 1,
                    Text    = "Cool",
                    Rating  = 8
                };

                controller.PostReview(review);
                context.Entry(review).State = EntityState.Detached;

                var actionResult = controller.DeleteReview(3).Result;
                Assert.IsNotEmpty(context.Reviews);
            }
        }
        public void UpdateShouldUpdateExistingHotel()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpdateShouldUpdateExistingHotel))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var hotelService = new ReviewService(context);
                var addedHotel   = hotelService.Create(new HotelBooking.Hotel
                {
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10
                        }
                    }
                });


                context.Entry(addedHotel).State = EntityState.Detached;
                Assert.AreEqual("Transilvania Hotel", addedHotel.HotelName);
                addedHotel.HotelName = "updated hotel";
                var updatedHotel = hotelService.Update(addedHotel.Id, addedHotel);
                Assert.AreEqual("updated hotel", updatedHotel.HotelName);
            }
        }
        public void ValidGetHotelByIdShouldGetSpecifiedHotel()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetHotelByIdShouldGetSpecifiedHotel))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var   hotelService = new ReviewService(context);
                Hotel hotel        = new Hotel
                {
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                hotel.Id = 1;
                hotelService.Create(hotel);
                context.Entry(hotel).State = EntityState.Detached;

                Assert.AreEqual(hotelService.GetHotelById(1).HotelName, "Transilvania Hotel");
            }
        }
        public void ValidDeleteByIdNotFoundId()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidDeleteShouldDeleteHotel))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var hotelService = new ReviewService(context);
                var controller   = new HotelsController(hotelService);

                Hotel hotel = new Hotel
                {
                    Id        = 100,
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };


                hotelService.Create(hotel);
                context.Entry(hotel).State = EntityState.Detached;

                IActionResult actionResult = controller.DeleteHotel(200);

                //  var createdResult = actionResult as OkObjectResult;

                //  Assert.IsInstanceOf(createdResult.GetType(), typeof(System.Web.Http.Results.NotFoundResult));
                Assert.IsNotEmpty(context.Hotels);
            }
        }